RST decomposition of a general skew-free 3D transformation
First of all, I refer you to D3DMatrixDecompose. If you want to break a standard 3D transformation matrix into its rotational, translational and scaling parts, without caring how it’s done, then look no further. If your needs are a little more specific and you’re sure you aren’t reinventing this wheel, then read on.
There is nothing clever about this decomposition, but it’s a question that comes up more often than I’d expect, so here’s the lowdown. I assume that your matrix is in DirectX-standard row-vector representation (so vout = vinM) and that the skew components are zero (M14 = M24 = M34 = 0). You should visualise the matrix like this:

First, we extract the translation:
vtranslation = (M41, M42, M43)
Then the scaling factors:
sx = √(M112 + M212 + M312)
sy = √(M122 + M222 + M322)
sz = √(M132 + M232 + M332)
The rotation matrix is then the upper-left 3×3 minor, after scaling back to unity.
Mrotation = M;
// Remove translation
Mrotation41 = 0;
Mrotation42 = 0;
Mrotation43 = 0;
// Normalise
Mrotation11 /= sx;
Mrotation21 /= sx;
Mrotation31 /= sx;
Mrotation12 /= sy;
Mrotation22 /= sy;
Mrotation32 /= sy;
Mrotation13 /= sz;
Mrotation23 /= sz;
Mrotation33 /= sz;
Leave a Reply