View Full Version : decomposing a maya matrix

 3dsensei04 April 2008, 12:38 PMHey There, I'm having trouble figuring out how to decompose a maya matrix to get the rotations. I've spend the last courple of days learning about matrices, and now my head hurts. And I just can't seem to get the right values when I try to decompose it. can someone help ? Thanks, Anders P.S. is maya left- or rigth-handed space
Dirk Bialluch
04 April 2008, 05:34 PM
There are several solutions for this (provided that you want to decompose the matrix within Maya's environment):

a) use the decomposeMatrix node that ships with Maya
b) use the MTransformationMatrix class in a plug-in command
c) use the MTransformationMatrix class in a python script (have not tried that yet)

Cheers,
Dirk

Robert Bateman
04 April 2008, 11:49 AM
MMatrix someTransform;

// get axes...
MVector xaxis = MVector( someTransform.matrix[0][0],
someTransform.matrix[0][1],
someTransform.matrix[0][2] );
MVector yaxis = MVector( someTransform.matrix[1][0],
someTransform.matrix[1][1],
someTransform.matrix[1][2] );
MVector zaxis = MVector( someTransform.matrix[2][0],
someTransform.matrix[2][1],
someTransform.matrix[2][2] );

// get scale
MVector scale = MVector( xaxis.length(),
yaxis.length(),
zaxis.length() );

// get rotation as quat
MQuaternion rotate = someTransform;

// or as eulers if you prefer
// (there will be problems with singularities though)
MEulerRotation eulers = rotate.asEulerRotation();

// get translation
MVector trans = MVector( someTransform.matrix[3][0],
someTransform.matrix[3][1],
someTransform.matrix[3][2] );

LEN3D
04 April 2008, 01:03 AM
general decomposition of matrix is very very difficult...

i've tried to do this but...

i found the best way is not to do this if possible...

a way to do this is "Polar Decomposition", refer to the book series "Graphic Gems" for more information, it's still very painstaking...

good luck!

Kuroyume0161
05 May 2008, 05:00 PM

I'm (still) trying to decompose Cinema 4D rotation matrices into a non-native rotation system (actually any of six Euler rotation systems: XYZ, XZY, etc.). Eberly's Euler extraction code works perfectly when the rotation matrix is a concatenation of the non-native rotations directly and before the application gets its grubby hands on the matrix. After that, their HPB anti-gimbal lock system destroys any means for ubiquitous success in the extraction process (using ANYTHING, and that includes Eberly, Shoemake, Polar Decomposition, SVD, vector-vector component, you name it - I've tried them all for years).

My problem is one of exact representation. I'm dealing with rigged figures with bone hierarchies to which these rotations are used. Since the bone deformations of the polygon object's points are on a per-axis basis, equivalent rotations (different rotations that would put a vector in the same orientation as if using the original rotations) won't ever work here (ever).

I'm contemplating a departure method from any available since none of these consider general matrix decomposition into a specific Euler rotation set attempting to get exact representations back. This is totally untried and hypothetical but involves finding the three rotations about the system, in sequence, that minimize the angular distance at each step. So, unlike quaternions which give the minimal angle between two points on a sphere I need the minimal component jumps along the axial system. Think of how a point is plotted in 3D space - you are given three coordinates (x,y,z) and the point is essentially moved along each axis by the amount per coordinate. Translation is communative - the order doesn't matter and any order will yield the same results. Rotations, as we are all painfully aware, are in no way communative. So the order is essential to how the minimization is accomplished - as different orders will yield different results.

For instance, let's say that I have a vector along the x-axis (0d,0d,0d) and the rotation order is XYZ. The vector is rotated in some way. I need to determine its rotation component angles from a matrix (of seemingly unknown origin as it were) so that they make sense with respect to the rotation order and have the minimal solution. In my mind, I have already considered that the minimal solution may not be what the user intended - that's why it needs to be tested. In an ideal world, the code would be working on incremental changes (deltas) which could use previous Euler rotations to make the results sensible. Unfortunately, this is not always the case (IK is a big problem here).

Sorry for going off-topic here. This is just one of those things that irks me. The problem continues to exist and very few mathematicians are really working on it. The mantra is 'use quaternions' - but that is not always possible. Not every developer has total control of the 3D system in which they are working. Some of us, like me, even have to reconcile two different systems maintaining numerical representations of one applied to the systemic application of the other. Mathematicians obviously don't work in the real world... ;)

CGTalk Moderation
05 May 2008, 05:00 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.

1