Hello, I am in need of some assistance in understanding and manipulating this call.
Here is the code I have from this thread.
Dim pt As Point3d
Dim RotMat As Matrix3x3
someComponent.GetPosition(pt, RotMat)
Dim c1, c2, s1 As Double
RX1 = Math.Atan2(RotMat.Yz, RotMat.Zz)
c2 = Math.Sqrt(RotMat.Xx ^ 2 + RotMat.Xy ^ 2)
RY1 = Math.Atan2(-RotMat.Xz, c2)
s1 = Math.Sin(RX1)
c1 = Math.Cos(RX1)
RZ1 = Math.Atan2(s1 * RotMat.Zx - c1 * RotMat.Yx, c1 * RotMat.Yy - s1 * RotMat.Zy)
'convert angles from radians to degrees
RX1 *= (180 / Math.PI)
RY1 *= (180 / Math.PI)
RZ1 *= (180 / Math.PI)
In all honesty I don't fully understand the explanation provided in the source code. However I understand Euler's Angles pretty well from this wiki article. My question is, how are these orientation matrixes computed? The NX 8.5 reference has no comments about this method besides it's parameters and the description "Gets the position of a component". So what's the problem? I have components that appear to have the exact same orientation but are not returning the same RX1, RY1, and RZ1.
End Goal: Be able to accurately compute the angle of a component with respect to the ABS. You can imagine my component lives on a part that is a box and I want to know which side(or face) of the box he lives on.
re: GetPosition
The rotation matrix wiki article does a pretty good job explaining what is represented by the matrix returned from the .GetPosition method.
If your file has a component added to an assembly twice with the same orientation, but my code returns different angles, perhaps you have found a bug in my code. Can you email me an example file where this behavior is demonstrated? (info@nxjournaling.com)
For the example given, I'm not sure you need the orientation of the component to determine "which side of the box" it lives on. It seems you could take a measurement from the component to the "box" and the result would indicate on which side the component resides. For instance, if I have a datum plane on the YZ plane, and the measurement from the component to the plane indicates a +X value, I know the component is on the -X side of the plane (and vice-versa).
Thanks for the wiki article,
Thanks for the wiki article, it helped the understanding a bit. I do not believe the bug is in your code because the orientation matrices returned from these two components are different.
The orientation matrices being different would normally push me to believe that simply the two components do not have the same orientation! However I have reason to believe otherwise. The two components look like they are both on a -25 degree angle from being perpendicular to a face. The orientation matrices and the posted code of these two components indicate that one is perfectly perpendicular and that one is -25 degrees from perpendicular.
As for the example given as my end goal, I forgot to include that I need to know at which angle the component is on each side. So, for example, I could differentiate between a component that is perpendicular to side 6 and a component that is x amount of degrees from being perpendicular to side 6.
NX 8.5
NX 9.0
Same comment but cleaned up a bit
Thanks for the wiki article, it helped the understanding a bit. I do not believe the bug is in your code because the orientation matrices returned from these two components are different. The orientation matrices being different would normally push me to believe that simply the two components do not have the same orientation! However I have reason to believe otherwise. The two components look like they are both on a -25 degree angle from being perpendicular to a face. The orientation matrices and the posted code of these two components indicate that one is perfectly perpendicular and that one is -25 degrees from perpendicular. As for the example given as my end goal, I forgot to include that I need to know at which angle the component is on each side. So, for example, I could differentiate between a component that is perpendicular to side 6 and a component that is x amount of degrees from being perpendicular to side 6.
NX 8.5
NX 9.0
re: position matrix
The position matrix will report how much the component has been moved in the assembly; original position vs. current position. The position matrix cannot be used to compare the orientation of two different components unless their original 'as modeled' orientations are also known.
If cylinder A is modeled parallel to the X axis and cylinder B is modeled parallel to the Z axis, the position matrix of each will return 0 rotation in the assembly but they will be 90° to each other. When cylinder A component is rotated to align with the Z axis, the position matrix will now return 90° because the component has been rotated 90° from its original position.