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!
Thanks
Graham Cook
Solved! Go to Solution.
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!
Thanks
Graham Cook
Solved! Go to Solution.
You could get funky with the matrix maths
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
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.
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
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
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
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
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.