Combining Multiple Rotations

Combining Multiple Rotations

GeorgK
Advisor Advisor
2,094 Views
10 Replies
Message 1 of 11

Combining Multiple Rotations

GeorgK
Advisor
Advisor

Hello together,

 

A series of rotations can be concatenated into a single rotation matrix by multiplying their rotation matrices together. Which is the order in Inventor?

 

Public Sub DumpMatrix(oMatrix As Matrix)
    Dim i As Integer
    For i = 1 To 4
        Debug.Print Format(oMatrix.Cell(i, 1), "0.000000") & ", " & _
                    Format(oMatrix.Cell(i, 2), "0.000000") & ", " & _
                    Format(oMatrix.Cell(i, 3), "0.000000") & ", " & _
                    Format(oMatrix.Cell(i, 4), "0.000000")
    Next
End Sub

Does there exist a sample for the multiplication?

 

Thank you

 

Georg

0 Likes
Accepted solutions (2)
2,095 Views
10 Replies
Replies (10)
Message 2 of 11

MechMachineMan
Advisor
Advisor

A good start is the help file's overview.

 

http://help.autodesk.com/view/INVNTOR/2018/ENU/?guid=GUID-9E3378FE-9F06-4e8a-A818-D4C81AB44B83


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 3 of 11

GeorgK
Advisor
Advisor

I could rotate the matrix around one axis. For example the x-axis:

 

x1.Text = 1
y1.Text = 0
z1.Text = 0
'w1.Text = 0

x2.Text = 0
y2.Text = Math.Cos(txtbox_Winkel_a.Text * Math.PI / 180)
z2.Text = -Math.Sin(txtbox_Winkel_a.Text * Math.PI / 180)
'w2.Text = 0

x3.Text = 0
y3.Text = Math.Sin(txtbox_Winkel_a.Text * Math.PI / 180)
z3.Text = Math.Cos(txtbox_Winkel_a.Text * Math.PI / 180)
'w3.Text = 0

x4.Text = 0
y4.Text = 0
z4.Text = 0
'w4.Text = 1

But I would like to combine it.

 

https://en.wikipedia.org/wiki/Euler_angles

 

Georg

0 Likes
Message 4 of 11

GeorgK
Advisor
Advisor
0 Likes
Message 5 of 11

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi @GeorgK,

 

Can you please provide some more details about Matrices (List of matrix for roatation)? also provide screenshots of actual position before rotation and after rotation expected?

 

 

List of functionalities available for matrix.

 

GetCoordinateSystem Invert PostMultiplyBy
PutMatrixData SetToAlignCoordinateSystems SetToRotateTo
SetTranslation GetMatrixData IsEqualTo
PreMultiplyBy SetCoordinateSystem SetToIdentity
SetToRotation TransformBy

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 6 of 11

GeorgK
Advisor
Advisor

Hello @chandra.shekar.g,

 

I could solve the problem by calculating the rotation about X,Y, Z axis and then multiplying the matrices. Is there a better  way to do this?

 

rotation.png

 

Thank you

 

Georg

0 Likes
Message 7 of 11

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi @GeorgK,

 

 

Can you please explain in more details about requirement with screenshots?

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 8 of 11

GeorgK
Advisor
Advisor

Hello @chandra.shekar.g,

 

the order of Euler angles of multiple axis rotations (degrees) in Inventor is ZYX. What I calculate is the rotation about X, Y, Z. For example a part should rotate X= 94,91° ; Y= -66,4834° ; Z= 138,0235°. I calculate the rotations about X,Y,Z like described on page 3 https://www.geometrictools.com/Documentation/EulerAngles.pdf

 

To combine the 3 angles I use the formula from https://www.geometrictools.com/Documentation/EulerAngles.pdf

 

https://www.euclideanspace.com/maths/geometry/affine/matrix4x4/index.htm

 

http://danceswithcode.net/engineeringnotes/rotations_in_3d/rotations_in_3d_part1.html

 

Onlinecalculator:

http://www.andre-gaschler.com/rotationconverter/

 

Is there a better way to do this or should I use Quaterninion? Which is the fastest way in Inventor?

 

Georg

 

0 Likes
Message 9 of 11

GeorgK
Advisor
Advisor

Quaternion Calculator.png

0 Likes
Message 10 of 11

chandra.shekar.g
Autodesk Support
Autodesk Support
Accepted solution

Hi @GeorgK,

 

Try the following sample VBA code to combine matrix.

 

Sub Main()

    Dim oDoc As AssemblyDocument
    Set oDoc = ThisApplication.ActiveDocument
    
    Dim oDef As AssemblyComponentDefinition
    Set oDef = oDoc.ComponentDefinition
    
    Dim occ As ComponentOccurrence
    Set occ = oDef.Occurrences.Item(1)
    
    Dim oTG As TransientGeometry
    Set oTG = ThisApplication.TransientGeometry

    ' Create an identity matrix
    Dim xMatrix As Matrix
    Set xMatrix = oTG.CreateMatrix

    ' Rotate about X-Axis by 45 degrees
    Call xMatrix.SetToRotation(3.14159 / 4, oTG.CreateVector(1, 0, 0), oTG.CreatePoint(0, 0, 0))
    
    ' Create an identity matrix
    Dim yMatrix As Matrix
    Set yMatrix = oTG.CreateMatrix

    ' Rotate about Y-Axis by 45 degrees
    Call yMatrix.SetToRotation(3.14159 / 4, oTG.CreateVector(0, 1, 0), oTG.CreatePoint(0, 0, 0))
    
    ' Create an identity matrix
    Dim zMatrix As Matrix
    Set zMatrix = oTG.CreateMatrix

    ' Rotate about Z-Axis by 45 degrees
    Call zMatrix.SetToRotation(3.14159 / 4, oTG.CreateVector(0, 0, 1), oTG.CreatePoint(0, 0, 0))
    
    Dim oMatrix As Matrix
    Set oMatrix = oTG.CreateMatrix
    
    Call oMatrix.PreMultiplyBy(xMatrix)

Call oMatrix.PreMultiplyBy(yMatrix) Call oMatrix.PreMultiplyBy(zMatrix) occ.Transformation = oMatrix Call oDoc.Update End Sub

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 11 of 11

GeorgK
Advisor
Advisor
Accepted solution

Hello @chandra.shekar.g,

 

your code works with the changed order:

 

Call oMatrix.PreMultiplyBy(zMatrix)   
Call oMatrix.PreMultiplyBy(yMatrix)   
Call oMatrix.PreMultiplyBy(xMatrix)

 

I use the matrices. This is more flexible.

 

Thank you very much

 

Georg

0 Likes