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

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.

• You must have $i=j=0$ for this to represent an affine transformation. – amd Nov 8 '18 at 18:38
• The OP is a little confused, I believe. As you can see from comments on my answer, the software returns a translation and a 3x3 matrix (which OP says represents an affine transformation, but you and I know represents the somewhat more restrictive linear transformation). I, too, thought that OP was representing affine transformations using homogeneous coords, but that appears not to be what's going on. – John Hughes Nov 8 '18 at 20:22

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)$$."

• Also: Divide $\pmatrix{2 & 0 \\ 0 & \frac{1}{2}}$ by its determinant (which is $1$), and you don't get a rotation. – John Hughes Nov 9 '18 at 16:43