Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

What is different between PostMultiplyBy and PreMultiplyBy in Inventor API?

liminma8458
Collaborator

What is different between PostMultiplyBy and PreMultiplyBy in Inventor API?

liminma8458
Collaborator
Collaborator

Hi, Exports,

Recently, I looked into below 2 threads on PreMultiplyBy and PostMultiplyBy. Both of these Inventor API functions can apply to Matrix and do multiple rotations, what is different between these two functions? what is different between the results after their operations?

https://forums.autodesk.com/t5/inventor-programming-ilogic/combining-multiple-rotations/m-p/7553161

https://forums.autodesk.com/t5/inventor-programming-ilogic/rotate-block-in-part-sketch/td-p/13026176

Thanks
Limin
Inventor pro 2023 64 bit update 2.1; Windows 10 pro 64 bit version 21H2; Office 2013 32 bit
0 Likes
Reply
Accepted solutions (1)
314 Views
2 Replies
Replies (2)

Michael.Navara
Advisor
Advisor
Accepted solution

This question is related to matrix multiplication. I'm not mathematician and I don't want to explain why it works and how the matrix multiplication is realized. For mathematical background see another resource (for example wikipedia is good source)

 

But few facts from theory is required.

1) Multiplication of matrices is not commutative

  • If you have two real numbers a and b then a*b = b*a. -> Is commutative
  • This is not true for matrices. If you have two matrices A and B then A*B =/= B*A. -> Is NOT commutative

2) You can change multiplication order (A*B)*C = A*(B*C).

 

Few facts of transformation matrices

1) Multiplication of matrices may not be always defined. But for transformation matrices is defined every time.

2) Transformation matrices describes individual moves (rotation and translation) and can combine them to single complex move.

3) Each simple move is always defined in object's coordinate system.

 

What API Methods does:

Following API method multiplies two matrices in defined order

PostMutiplyByA.PostMutiplyBy(B) => A*B

PreMultiplyBy: A.PreMultiplyBy(B) => B*A

 

Practical impacts

Let you have two transformation matrices Tx which describes translation in X direction and Tr which describes rotation about object's origin of PI/4 rad (45 deg counter clockwise) and block which can be transformed by matrix T.

 

Situation 1

In this situation we apply translation first and then apply rotation T = Tx * Tr. The result will look like this

MichaelNavara_0-1726815367518.png

 

Situation 2

In this situation we apply rotation first and then apply translation T = Tr * Tx. The result will look like this

MichaelNavara_1-1726815487813.png

 

Code sample for testing

'Initialization
Dim part As PartDocument = ThisDoc.Document
Dim sketch As PlanarSketch = part.ComponentDefinition.Sketches(1)
Dim block As SketchBlock = sketch.SketchBlocks(1)

'Setup matrices
Dim translationMtx As Matrix2d = ThisApplication.TransientGeometry.CreateMatrix2d()
Dim translationVector As Vector2d = ThisApplication.TransientGeometry.CreateVector2d(3, 0)
translationMtx.SetTranslation(translationVector)

Dim rotationMtx As Matrix2d = ThisApplication.TransientGeometry.CreateMatrix2d()
Dim center As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(0, 0)
rotationMtx.SetToRotation(Math.PI / 4, center)

Dim invertedRotationMtx = rotationMtx.Copy()
invertedRotationMtx.Invert()

Dim blockTransformation As Matrix2d = ThisApplication.TransientGeometry.CreateMatrix2d()

'Uncomment following situations for testing

'Situation 1
'  with PostMultiplyBy
blockTransformation.PostMultiplyBy(translationMtx) 	'Tx
blockTransformation.PostMultiplyBy(rotationMtx)		'Tr

''Situation 2
''  with PostMultiplyBy
'blockTransformation.PostMultiplyBy(rotationMtx)	'Tr
'blockTransformation.PostMultiplyBy(translationMtx)	'Tx


''Situation 2
''  with PreMultiplyBy
'blockTransformation.PostMultiplyBy(translationMtx)	'Tx
'blockTransformation.PreMultiplyBy(rotationMtx)		'Tr


block.Transformation = blockTransformation

ThisApplication.ActiveView.Update

 

 

 

liminma8458
Collaborator
Collaborator

Hi, Michael,

Thank you so much for the test sample! I will research on that.

Great with the definition. That is something I want confirmation for a long time.

PostMutiplyByA.PostMutiplyBy(B) => A*B

PreMultiplyBy: A.PreMultiplyBy(B) => B*A

 

Thumb up!

 

Thanks
Limin
Inventor pro 2023 64 bit update 2.1; Windows 10 pro 64 bit version 21H2; Office 2013 32 bit
0 Likes