Angle from Transform Matrix returns wrong value for assemblies

Angle from Transform Matrix returns wrong value for assemblies

Anonymous
Not applicable
677 Views
3 Replies
Message 1 of 4

Angle from Transform Matrix returns wrong value for assemblies

Anonymous
Not applicable

Hi,

 

I am using a matrix calculation ( angle = acos ((basisX.x + basisY.Y + basisZ.Z -1)/2) ) to return the rotation angle of assemblies. I have been using this for a couple of months without any problems. However a few assemblies seem to return a wrong value in my last project. 

 

Using the post 'Get Angle from Transform.BasisX, BasisY and BasisZ' (https://forums.autodesk.com/t5/revit-api-forum/get-angle-from-transform-basisx-basisy-and-basisz/td-...) I have also calculated the angle.

 

In my example assembly 'WA045' returns the same values for both calculations (this assembly has a correct rotation). However assembly 'WA014' returns two different values of which '204 degrees (or 24; anything at a 90 deg angle from 114 deg)' seems to be correct, but the value of '156 deg' from the matrix calculation is wrong.

 

Is my approach faulty or am I missing something?

 

regards,

Raymond

 

 

0 Likes
678 Views
3 Replies
Replies (3)
Message 2 of 4

JimJia
Alumni
Alumni

Dear Raymond,

 

The value that acos returns will be [0,pi], so the matrix calculation return '156 deg' is correct.

acos method can not return value greater than '180 deg'.

 

please notice that '204 deg' + '156 deg' = '360 deg'

 

Actually the angle between two vectors is correct.

 

If you want to get the value '204 deg', you need to consider the direction of the vector.

 

I think you can use XYZ.AngleOnPlaneTo Method, it will return a value between 0 and 2*pi.

 


Jim Jia
Autodesk Forge Evangelist
https://forge.autodesk.com
Developer Technical Services
Autodesk Developer Network
Email: Jim.Jia@autodesk.com
0 Likes
Message 3 of 4

BenoitE&A
Collaborator
Collaborator

Or you need to complete your angle calculation by another, checking whether your angle is between 0 and Pi or between Pi and 2*Pi.

I do this using the sign of the dotproduct of my vector and the local y axis. If the product is >0 then my angle is between 0 and Pi, in the other case it is between Pi and 2*Pi

 

Be careful if you do this that the searched angle is 2*Pi - calculatedAngle when it is between Pi and 2*Pi (and not Pi+calculatedAngle).


Benoit FAVRE
CEO of etudes & automates
www.etudesetautomates.com/
0 Likes
Message 4 of 4

Anonymous
Not applicable

Thanks for the suggestions. I will go and have a look 🙂

0 Likes