How to extract rotation matrix and scale vector from a 3D affine transformation?

3.4k Views Asked by At

For the affine transformation: $$ \begin{bmatrix} a & b & c\\ e & f & g\\ i & j & k\\ \end{bmatrix} $$

how do I extract the rotation and scale parts?

According to this answer, the scale along each axis can be extracted by taking the length of the respective matrix column, but what about the sign of the scale? This is especially interesting for me because the matrix might be used to flip around an axis using a scale of -1.

2

There are 2 best solutions below

2
On

A pure rotation matrix will have determinant 1. Find the determinant of the given matrix. That will be the "scale". Dividing the matrix by its determinant gives the pure rotation matrix.

4
On

One reason that you're not finding answers is that there isn't actually an answer in general. Some affine transformations (even without a translation, like this one): $$ \pmatrix{1 & 1 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1} $$ cannot be written as a product of any scale and any rotation. So there's no solution there.

On the other hand, a matrix like $$ \pmatrix{-1 & 0 & 0 \\ 0 & -1 & 0 \\ 0 & 0 & 1} $$ can be written as a product of a scale and a rotation in two different ways:

  1. rotate $180$ degrees in the $xy$-plane, scale $= (1, 1, 1)$

  2. rotate $0$ degrees, scale $= (-1, -1, 1)$

In fact, if you have

rotation by $A$ degrees in the $xy$ plane; scale by $(p, q, 1)$,

that's always the same as "rotate by $A + 180$ degrees, scale by $(-p, -q, 1)$" so the answer is never unique. Even the identity transformation is both "no rotation, scale by $(1,1, 1)$" and "rotate 180 degrees, scale by $(-1, -1, 1)$."

I know that's not the answer you wanted, but it's the truth, and it might help you stop looking for an answer that doesn't exist. (Or it might help you to reformulate your question to one that does have an answer.)