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

Discrepancy between Matrix.SetToRotation and Matrix3D.RotateAt

dhaverstick
Advocate

Discrepancy between Matrix.SetToRotation and Matrix3D.RotateAt

dhaverstick
Advocate
Advocate

I'm trying to port some code from the Inventor API to a more generic .Net API and I found a discrepancy between two functions that are supposed to do the same thing.

 

In Inventor, I created an Inventor.Matrix and then rotated it about the Y Axis by AnglePhi (PI/8). Here's the code snippet.

Dim RotationMatrixYAxis As Inventor.Matrix = InventorApp.TransientGeometry.CreateMatrix
RotationMatrixYAxis.SetToRotation(AnglePhi, InventorApp.TransientGeometry.CreateVector(0, 1, 0), InventorApp.TransientGeometry.CreatePoint(0, 0, 0))

The resultant cell values from this operation are: 1,1 = 0.9238, 1,2 = 0, 1,3 = 0.3826, 2,1 = 0, 2,2 = 1, 2,3 = 0, 3,1 = -0.3826, 3,2 = 0, 3,3 = 0.9238

Now I do the same thing using the System.Numerics and System.Windows.Media.Media3D libraries.

Dim QuaternionObj As System.Numerics.Quaternion
Dim YAxisVector As New System.Numerics.Vector3(0, 1, 0)
QuaternionObj = System.Numerics.Quaternion.CreateFromAxisAngle(YAxisVector, AnglePhi)
Dim MyQuaternion As System.Windows.Media.Media3D.Quaternion
MyQuaternion = New Quaternion(QuaternionObj.X, QuaternionObj.Y, QuaternionObj.Z, QuaternionObj.W)
Dim RotationMatrixYAxis As New System.Windows.Media.Media3D.Matrix3D
RotationMatrixYAxis.RotateAt(MyQuaternion, New Point3D(0, 0, 0))

The resultant cell values from this operation are: 1,1 = 0.9238, 1,2 = 0, 1,3 = -0.3826, 2,1 = 0, 2,2 = 1, 2,3 = 0, 3,1 = 0.3826, 3,2 = 0, 3,3 = 0.9238

 

Notice that the signs are switched for the elements 1,3 and 3,1 between the two methods of rotation.

 

Can anyone explain to me why this is taking place? My code porting project is stopped dead in its tracks until I get this little mystery solved.

 

Thanks in advance!

 

Darren Haverstick

Paul Mueller Company

 

 

0 Likes
Reply
810 Views
7 Replies
Replies (7)

chandra.shekar.g
Autodesk Support
Autodesk Support

@dhaverstick,

 

Can you please provide non confidential VB.net project which includes System.Windows.Media.Media3D.Quaternion?

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes

dhaverstick
Advocate
Advocate

Attached is a zip file containing the project you asked for.

 

Notice that the Media3D rotation matrix is always the inverse of the corresponding Inventor matrix.

 

Darren Haverstick

Paul Mueller Company

0 Likes

chandra.shekar.g
Autodesk Support
Autodesk Support

@dhaverstick,

 

In the attached mathgeometry.pdf(refer page number 16 - 23), rotation of occurrence in assembly is clearly explained. Please go through the same. The working of Matrix3D.RotateAt should be checked with Microsoft team.(https://docs.microsoft.com/en-us/dotnet/api/system.windows.media.media3d.matrix3d.rotateat?view=netc...)

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes

dhaverstick
Advocate
Advocate

I'm not sure what you are trying to tell me with your last reply. I have used Inventor rotation matrices many times. What I am asking for is some insight on why two commands, one Inventor and one .Net, that appear to do the same thing, produce different results.

 

This might better be illustrated with the attached Inventor addin project. This project has the user enter a rotation angle value and choose what axis to rotate about. The results of the rotation matrices are then displayed for both the Inventor Matrix object and the Media3D Matrix3D object. From the results, you can easily see that one matrix is the inverse of the other.

 

This project is compiled on the Inventor 2019 platform. There is an executable that you can install and run along with all the source code.

 

If it helps any, I have done the same comparison with the AutoCAD Geometry.Matrix3d object and the Media3D.Matrix3D object. The results are the same as the Inventor comparison. One matrix is the inverse of the other.

 

Darren Haverstick

Paul Mueller Company

0 Likes

YuhanZhang
Autodesk
Autodesk

Hi Darren,

 

Have you encountered any problem with the rotation of Matrix in Inventor(except the values against Matrix3D in .net)? Do you want to rotate some Inventor objects(like ComponentOccurrence, SurfaceBody) but has wrong result with the Matrix.SetToRotation?



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes

dhaverstick
Advocate
Advocate

No, I have not had any issues with using matrices in Inventor. I'm just wanting someone to explain to me why two methods, that appear to do the same thing, produce different results.

 

Darren

0 Likes

YuhanZhang
Autodesk
Autodesk

I am not sure why Microsoft chose that style, but you can refer to some articles like below one to understand what Inventor does for the Matrix's rotation:

 

https://www.continuummechanics.org/rotationmatrix.html 

 

Specially for the section "3-D Reduction to 2-D".

 

If you have any problem with using the Matrix in Inventor please let me know.

 

 



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes