Rotate a User Coordinate System

Rotate a User Coordinate System

johnPGNFG
Enthusiast Enthusiast
1,067 Views
3 Replies
Message 1 of 4

Rotate a User Coordinate System

johnPGNFG
Enthusiast
Enthusiast

I'm trying to rotate a user coordinate system about it's Z axis.  This seems like a simple task but apparently I'm missing some steps.  I first create my transform and user coordinate system.  These are in the correct location. Then later in the code I need to rotate the user coordinate system around it's z axis.  I'm trying to use "SetToRotation" but this keeps using the default origin and coordinate system. 

 

TransientGeometry transGeom = invApp.TransientGeometry;
Inventor.Matrix text_Transform = invApp.TransientGeometry.CreateMatrix();
text_Transform.SetCoordinateSystem(textOrigin3d, Xvec, Yvec, Zvec);
UserCoordinateSystemDefinition textUCSdef = oCompDef.UserCoordinateSystems.CreateDefinition();
textUCSdef.Transformation = text_Transform;
UserCoordinateSystem textUCS = oCompDef.UserCoordinateSystems.Add(textUCSdef);

 

Everything above works correctly.  Then let's say I want to rotate the ucs 30 degrees about it's z axis:


text_Transform.SetToRotation(30 * Math.PI / 180, Zvec, transGeom.CreatePoint(0, 0, 0));

textUCS.Transformation = text_Transform;

 

This moves the ucs to the documents origin and uses the default coordinate system, rotated 30 degrees about the Zvec.  So, it's using the right vector to rotate about, but it's using the wrong coordinate system.  What am I missing?  

 

0 Likes
Accepted solutions (1)
1,068 Views
3 Replies
Replies (3)
Message 2 of 4

WCrihfield
Mentor
Mentor

Hi @johnPGNFG.  At first glance, I would say that you should use the 'textOrigin3d' variable instead of creating a new transient point at (0,0,0) for the 'center' of your rotation, because you are using the 'Zvec' variable from that earlier reference too.  Those two were used in specifying the coordinate system of your matrix, so I would assume you would want to use the same data to define your axis & center for rotating it.  Just makes sense to me.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 4

johnPGNFG
Enthusiast
Enthusiast

I have tried using textOrigin3d as the point, the image below shows what happens.   The input point is the point of rotation, which you are right, textOrigin3d is the point I want to rotate around.  

 

text_Transform.SetToRotation(30 * Math.PI / 180, Zvec, textOrigin3d);

 

The problem comes on the next line:

 textUCS.Transformation = text_Transform;

 

It shifts textUCS to the origin of the part document, realigns it to the default coordinate system, then rotates it 30 degrees around textOrigin3d. 

 

I want textUCS to stay in place, rotated 30 degrees around the z axis. (I'm using 30 as an example, this is a variable)

 

johnPGNFG_1-1679335702664.png

 

 

0 Likes
Message 4 of 4

johnPGNFG
Enthusiast
Enthusiast
Accepted solution

I figured it out.  I need to create a separate matrix to define the rotation.  Then transform my original matrix by the rotation matrix.  So it would look something like this...

 

TransientGeometry transGeom = m_invApp.TransientGeometry;
Inventor.Matrix text_Transform = m_invApp.TransientGeometry.CreateMatrix();
text_Transform.SetCoordinateSystem(textOrigin3d, Xvec, Yvec, Zvec);
UserCoordinateSystemDefinition textUCSdef = oCompDef.UserCoordinateSystems.CreateDefinition();
textUCSdef.Transformation = text_Transform;
UserCoordinateSystem textUCS = oCompDef.UserCoordinateSystems.Add(textUCSdef);


Inventor.Matrix rotationMatrix = m_invApp.TransientGeometry.CreateMatrix();
 rotationMatrix.SetToRotation(30*Math.PI/180, Zvec, textOrigin3d);

text_Transform.TransformBy(rotationMatrix);

textUCS.Transformation = text_Transform;

 

 

johnPGNFG_1-1679348626723.png

 

 

 

 

0 Likes