extracting scale vector from a transformation matrix?

Started by
5 comments, last by peter_b 18 years ago
Hello. If i have a transformation matrix, containing translation, rotation, scaling etc.. How can i extract the scale vector from that? (ie. sx,sy,sz). Hope its possible and not as hard as getting the rotation in euler angles from a matrix.. =P Thanks in advance.
Shields up! Rrrrred alert!
Advertisement
hmm, I think you can extract it with something like this :

the matrix is like :m11  m12  m13  m14m21  m22  m23  m24m31  m32  m33  m34m41  m42  m43  m44then the scale should be :sx = length(vector3(m11, m12, m13));sy = length(vector3(m21, m22, m23));sz = length(vector3(m31, m32, m33));


basically, you take the transformed x, y and z axis, and compute their length to get the scale along each axis.

But i'm not sure if this always works.
The scale vector is the vector of singular values of the matrix. You find it by performing the singular value decomposition (SVD) of the matrix.

Much easier, though, is simply knowing it in the first place. Where did the matrix come from? If you generated it yourself, just keep the scale vector around.
It was read from a level file in matrix form.. and since i need to do object transformation, i need to know the scale in order to apply it after the rotation etc.. or it will look borked.. =/

In other words, i have to extract it..
Shields up! Rrrrred alert!
iv written a program that generates random transformation matrixes composed of translation/scale/rotation, and paic's method seems to work in all cases it can come up with.

Can anyone confirm that this method works everytime?
Shields up! Rrrrred alert!
Quote:Original post by peter_b
iv written a program that generates random transformation matrixes composed of translation/scale/rotation, and paic's method seems to work in all cases it can come up with.

Can anyone confirm that this method works everytime?

From a mathematical point of view: The linear matrix part (that is the 3x3 sub-matrix paic's method decomposes) is influenced by rotations and scaling only as long restricting self to rotations, scalings, and translations. Since a rotation matrix is always orthonormal, the length of the basis vectors could be interpreted as scaling factors.

Now it is most likely to scale first, and then to rotate, and at last to translate. If using column vectors
M := T * R * S
else if using row vectors
M := S * R * T

When actually doing so, one sees that paic's method works well with row vectors and the assumption that the scaling factors are positive, since
sx = sqrt( ( R11 * Sx )2 + ( R12 * Sx )2 + ( R13 * Sx)2 )
= sqrt( R112 + R122 + R132 ) * | Sx |
= | Sx |
due to orthonormality of rotation matrices. (I've used paic's indexing scheme.)

If you use column vectors, then the indexing must be "transposed":
sx = sqrt( ( R11 * Sx )2 + ( R21 * Sx )2 + ( R31 * Sx)2 )
= | Sx |

Additionally, you have to spend more effort if also negative scaling (mirroring) is allowed, namely something like sign comparisons. Althought it isn't possible to detect mirrorings over 2 axes (that will be seen as a rotation) it is possible to detect mirroring over 1 or 3 axes. EDIT: But be aware that it isn't possible to detect what axes were originally mirrored.


So, IMHO under the above assumptions paic's solution should be sufficient for all positive scaling factors.

[Edited by - haegarr on March 29, 2006 7:12:06 AM]
thanks guys
Shields up! Rrrrred alert!

This topic is closed to new replies.

Advertisement