Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Get Angle from Transform.BasisX, BasisY and BasisZ

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
grahamcook
4819 Views, 4 Replies

Get Angle from Transform.BasisX, BasisY and BasisZ

grahamcook
Advocate
Advocate

Hi

 

I have imported a DWG and iterated through looking for all Block references to get their names and Origins.  This part has been successful for which i based my code on Joe Ye's answer in the following post - http://forums.autodesk.com/t5/revit-api/selecting-cad-lines/td-p/3894252

 

My problem is getting the angle or rotation of the block.  I know that the Transform.BasisX, BasisY and BasisZ will give me the angle but i don't know how to extract it.  For example i know the following Transform represents 45 deg but despite looking through the forums i haven't figured how it works.  Any pointers much appreciated!

 

Capture.PNG

 

 

Thanks

 

Graham Cook

0 Likes

Get Angle from Transform.BasisX, BasisY and BasisZ

Hi

 

I have imported a DWG and iterated through looking for all Block references to get their names and Origins.  This part has been successful for which i based my code on Joe Ye's answer in the following post - http://forums.autodesk.com/t5/revit-api/selecting-cad-lines/td-p/3894252

 

My problem is getting the angle or rotation of the block.  I know that the Transform.BasisX, BasisY and BasisZ will give me the angle but i don't know how to extract it.  For example i know the following Transform represents 45 deg but despite looking through the forums i haven't figured how it works.  Any pointers much appreciated!

 

Capture.PNG

 

 

Thanks

 

Graham Cook

4 REPLIES 4
Message 2 of 5
Anonymous
in reply to: grahamcook

Anonymous
Not applicable
Accepted solution

You could get funky with the matrix maths Smiley Wink

 

Or you could do something like trans.OfVector(XYZ.BasisX) then usethe result with XYZ.AngleOnPlaneTo to check against XYZ.BasisX get the angle. You would need to do some pre-qualifications to determine the correct plane to check the angles on (or even which test vector to use, spinning a vector on it's axis is not likely to tell you much). There could be a pure API method for this but I can't think of it.

 

Really though, I'd suggest brushing up on your matrix maths. Transforms are essentially a matrix (there's some differences that I can't remember off the top of my head exactly what they are) and the information is all there to be gathered for yourself. I'm a bit rusty myself since I haven't worked on opengl code in a while, but if you get a few library functions together you'll be golden.

 

I'll see if I can dig through some of my old code when I get home and post a few snippets.

You could get funky with the matrix maths Smiley Wink

 

Or you could do something like trans.OfVector(XYZ.BasisX) then usethe result with XYZ.AngleOnPlaneTo to check against XYZ.BasisX get the angle. You would need to do some pre-qualifications to determine the correct plane to check the angles on (or even which test vector to use, spinning a vector on it's axis is not likely to tell you much). There could be a pure API method for this but I can't think of it.

 

Really though, I'd suggest brushing up on your matrix maths. Transforms are essentially a matrix (there's some differences that I can't remember off the top of my head exactly what they are) and the information is all there to be gathered for yourself. I'm a bit rusty myself since I haven't worked on opengl code in a while, but if you get a few library functions together you'll be golden.

 

I'll see if I can dig through some of my old code when I get home and post a few snippets.

Message 3 of 5
Anonymous
in reply to: grahamcook

Anonymous
Not applicable

Ok, I couldn't find anything close enough in my old code but here's a few resources that should steer you clear.

 

This one has some java code and a few explanations on how to extract the angle and axis of rotation:

http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/

 

This from the API developers guide explains the specifics of the underlying matrix of the Transform class:

http://help.autodesk.com/view/RVT/2014/ENU/?guid=GUID-78445211-E211-4E27-B080-BE9FA3C50631

0 Likes

Ok, I couldn't find anything close enough in my old code but here's a few resources that should steer you clear.

 

This one has some java code and a few explanations on how to extract the angle and axis of rotation:

http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/

 

This from the API developers guide explains the specifics of the underlying matrix of the Transform class:

http://help.autodesk.com/view/RVT/2014/ENU/?guid=GUID-78445211-E211-4E27-B080-BE9FA3C50631

Message 4 of 5
grahamcook
in reply to: Anonymous

grahamcook
Advocate
Advocate

Thanks Scott.  Your first reply gave me the solution.  These are always going to be 2D angles so I found that the following always returned the right angle.

 

XYZ vectorTran = transform.OfVector(transform.BasisX);

double d1 = transform.BasisX.AngleOnPlaneTo(vectorTran, transform.BasisZ); // radians

d1 = d1 * (180 / Math.PI); // degrees

 

 

I struggle to understand it though so I will be reading up using those links you provided!

 

Regards

 

Graham Cook

 

Thanks Scott.  Your first reply gave me the solution.  These are always going to be 2D angles so I found that the following always returned the right angle.

 

XYZ vectorTran = transform.OfVector(transform.BasisX);

double d1 = transform.BasisX.AngleOnPlaneTo(vectorTran, transform.BasisZ); // radians

d1 = d1 * (180 / Math.PI); // degrees

 

 

I struggle to understand it though so I will be reading up using those links you provided!

 

Regards

 

Graham Cook

 

Message 5 of 5
c_hanschen
in reply to: grahamcook

c_hanschen
Advocate
Advocate

I think this is the most simple way to get the rotation angle:

 

MyTransform.BasisX.AngleTo(New XYZ(1, 0, 0))

 

Chris Hanschen

LKSVDD architecten

The Netherlands

0 Likes

I think this is the most simple way to get the rotation angle:

 

MyTransform.BasisX.AngleTo(New XYZ(1, 0, 0))

 

Chris Hanschen

LKSVDD architecten

The Netherlands

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report