1

I've been trying to figure out the 2D rotation value as seen from orthographic "top" view for a 3D object with XYZ rotation values in Maya. Maybe another way to ask this could be: I want to figure out the 2D rotation of a 3D obj's direction.

Here is a simple image to illustrate my question: Sample image for the question

I've tried methods like getting the twist value of an object using quaternion (script pasted below), to this post I've found: Component of a quaternion rotation around an axis.

If I set the quaternion's X and Z values to zero, this method works half way. I can get the correct 2D rotation even when obj is rotated in both X and Y axis, but when rotated in all 3 axis, the result is wrong.

I am pretty new to all the quaternion and vector calculations, so I've been having difficulty trying to wrap my head around it.

;)

def quaternionTwist(q, axisVec):
    axisVec.normalize()

    # Get the plane the axisVec is a normal of
    orthonormal1, orthonormal2 = findOrthonormals(axisVec)

    transformed = rotateByQuaternion(orthonormal1, q)

    # Project transformed vector onto plane
    flattened = transformed - ((transformed * axisVec) * axisVec)
    flattened.normalize()

    # Get angle between original vector and projected transform to get angle around normal
    angle = math.acos(orthonormal1 * flattened)

    return math.degrees(angle)

q = getMQuaternion(obj)
# Zero out X and Y since we are only interested in Y axis.
q.x = 0
q.z = 0
up = om2.MVector.kYaxisVector
angle = quaternionTwist(q, up)

3 Answers 3

1

Can you get the (x,y,z) coordinates of the rotated vector? Once you have them use the (x,y) values to find the angle with atan2(y,x).

Sign up to request clarification or add additional context in comments.

1 Comment

This has helped me solve the problem. I have been overthinking when a simple atan on orientation vector was the solution. I've posted the final working code as a separate answer.
0

I'm not familiar with the framework you're using, but if it does what it seems, I think you're almost there. Just don't zero out the X and Z components of the quaternion before calling quaternionTwist().

The quaternions q1 = (x,y,z,w) and q2 = (0, y, 0, w) don't represent the same rotation about the y-axis, especially since q2 written this way becomes unnormalized, so what you're really comparing is (x,y,z,w) with (0, y/|q2|, 0, w/|q2|) where |q2| = sqrt(y^2 + w^2).

1 Comment

Thanks for the explanation on the X and Z components. So, I've removed q.x = 0 and q.z = 0, however, I still cannot get the 2D rotation to match when I rotate the 3D obj's Z rotation. Rotating only X and Y does. I assume I am correctly retrieving the twist rotation about the axis vector (y-axis) but I feel like I am missing another step...
0

Here is a working code for Maya using John Alexiou's answer:

matrix = dagPath.inclusiveMatrix() #OpenMaya dagPath for an object
axis = om2.MVector.kZaxisVector
v = (axis * matrix).normal()
angle = math.atan2(v.x, v.z) #2D angle on XZ plane

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.