A matrix to rotate an object

Top  Previous  Next

When you insert a part in an assembly you can specify the initial position and rotation. You do this by providing a matrix to the AddiPartMember call. Here is an example of how to create a matrix which will rotate the part around the Z axis by 180 degrees:

 

   CComPtr<TransientGeometry> pTransGeom = GetTransGeomPtr () ;   

   CComPtr<Matrix> pPosMatrix;

   pTransGeom->CreateMatrix(&pPosMatrix); // Defaults to origin

 

   CComPtr<Vector> pZAxis = nullptr ;

   pTransGeom->CreateVector (0,0,1,&pZAxis);

 

   CComPtr<Point> pOrigin = nullptr ;

   pTransGeom->CreatePoint (0,0,0,&pOrigin);

 

   pPosMatrix->SetToRotation (TwoPi,pZAxis,pOrigin) ;

 

...and when you call AddiPartMember you use the matrix like this:

 

   pOccurrencesList->AddiPartMember (bstrFileName,pPosMatrix,_variant_t(bstrMemberName),&pOccurrence) ;

 

Note that SetToRotation requires radians, not degrees.

 

These two diagrams show the result of using a X-Axis rotation matrix when calling AddiPartMember:

 

Inventor-Programming-No-Rotate-iPart-Member

 

Inventor-Programming-Rotate-iPart-Member-X-Axis

 

Here is a code fragment which creates the matrix which does that:

 

       CComPtr<Matrix> pRotXMatrix;

       pTransGeom->CreateMatrix(&pRotXMatrix);

       CComPtr<Vector> pXAxis = nullptr ;

       pTransGeom->CreateVector (0,1,0,&pXAxis);

       pRotXMatrix->SetToRotation (gkPi,pXAxis,pOrigin) ;

 

If you are using two planes in a constraint you can also sometimes use FlipNormal to rotate the inserted object 180°

 

 

 

 

Text, images and diagrams © 2021 Owen F. Ransen. All rights reserved. (But copy the source code as much as you want!)