Extract Euler rotation from matrix using Maya

1.1k views Asked by At

I am trying to extract the rotation of an object based on these values:

[ 0.00000000, 0.00000000, 0.00000000,
0.33333334, -0.53828228, 0.00000000,
0.66666669, -1.07656455, 0.00000000,
1.00000000, -1.61484683, 0.00000000 ]

I am not quite sure how to do that properly.. I found a few solutions online but none worked for me since all values used on those examples were a bit different from the one above. Does anyone know how to extract that using Python/OpenMaya? I would appreciate any help. Thanks in advance.

1

There are 1 answers

1
robthebloke On

The numbers you have specified seem a little strange (and don't really have any context). Anyhow, within Maya, there are a few options for converting a matrix to Euler rotation angles.

  1. Construct an MTransformationMatrix (one of the Maya API classes) and provide the matrix in question to the constructor. The eulerRotation() method will return the values (although you may be limited to an XYZ rotation ordering?)

  2. Create a transform node. Specify the rotation-order you want to use by setting the rotation order flag on the node (e.g. xyz, zyx, etc). Use cmds.xform to set the matrix for the transform. Now just use cods.getAttr to read the rotation angles.

  3. Call: MEulerRoation MEulerRoation::decompose(const MMatrix &matrix, RotationOrder ord), passing in the matrix, and the desired rotation order.