After many failed attempts I have to ask the question.... what is the correct sequence of events that needs to occur to place a cell (or any object) at a specific 3D rotation. I have computed all of the rotations (shown below). When I apply the rotation to the cell I can get it to rotate based on either the X,Y, or Z rotation, but once I combine the rotations the cell is not correctly rotated. Needless to say I have done a lot of reading on the 3dmatrix, 3dtransforms, vectors, etc. trying to figure this out, I get close, but close does not count! My rotations are based on using existing geometry in the file, specifically a 3D linestring. I have included below how I go about computing the rotation angles, as well as how I am apply the rotation to the cell. I think my logic with respect to computing the angles is correct, but not 100% sure. This works if I am rotating in ONE of the X, Y, or Z rotations, but not when any combination of rotations are applied.
Thanks in advance for any advice,timbelow is the code snippet that I am using...
dim v3d1 As Vector3ddim StrVertices() As Point3ddim StrVindex As Longdim myAngle as doubledim TV_matrix As Matrix3dim TV_trans As Transform3dDim myCell As CellElementDim X_angle As DoubleDIM Y_angle As DoubleDIM Z_angle As Doubledim myPoints as point3d
With Telement.AsVertexList StrVertices = .GetVertices 'get the start vertex Id of segment StrVindex = .GetClosestSegment(TempPoint) 'get the vector of the segment v3d1 = Vector3dFromXY(StrVertices(StrVindex + 1).x - StrVertices(StrVindex).x, StrVertices(StrVindex + 1).y - StrVertices(StrVindex).y) end with 'now get the "TOP view angle" Z_angle= Vector3dPolarAngle(v3d1) 'this computes the "profile" angle using delta Z difference of the points, and the XY distance of the points 'the profile angle is the "normal" angle that uses Z values and the distance between the points to compute the "profile" angle Y_angle = Atn((StrVertices(StrVindex).z - StrVertices(StrVindex + 1).z) / Point3dDistanceXY(StrVertices(StrVindex), StrVertices(StrVindex + 1))) 'this computes the "cross section rotation", using a user key-in to define the angle X_angle = radians(myAngle) Set myCell = CreateCellElement2(myCellname,myPoints, cellscale, True, Matrix3dIdentity)
'rotate about X cellscale.x = 1 cellscale.y = 0 cellscale.z = 0 TV_matrix = Matrix3dFromVectorAndRotationAngle(cellscale, X_angle) TV_trans = Transform3dFromMatrix3dAndFixedPoint3d(TV_matrix, myPoints) myCell.Transform TV_trans
'rotate about y cellscale.x = 0 cellscale.y = 1 cellscale.z = 0 TV_matrix = Matrix3dFromVectorAndRotationAngle(cellscale, Y_angle) TV_trans = Transform3dFromMatrix3dAndFixedPoint3d(TV_matrix, myPoints) myCell.Transform TV_trans
'rotate about z cellscale.x = 0 cellscale.y = 0 cellscale.z = 1 TV_matrix = Matrix3dFromVectorAndRotationAngle(cellscale, Z_angle) TV_trans = Transform3dFromMatrix3dAndFixedPoint3d(TV_matrix, myPoints) myCell.Transform TV_trans ActiveModelReference.AddElement myCell myCell.Redraw msdDrawingModeNormal