Splits a Matrix3 into Q * S (the polar decomposition), returned as (Q, S, det): Q is an orthogonal matrix (a rotation, or a rotation with a flip when the determinant is negative), S is symmetric positive semi-definite (the stretch), and det is the determinant of the input. A singular input is allowed: the missing directions of Q are filled in so it stays orthogonal. Computed by an iterative eigen-solver at float precision, so Q * S matches the input to about 1e-6 for well-scaled input.
m := Matrix3.{ 0, -2, 0, 3, 0, 0, 0, 0, 1 };
q, s, det := polar_decomp(m);
assert(abs(det - 6) < 0.0001);
back := q * s;
for 0..8 assert(abs(back.floats[it] - m.floats[it]) < 0.0001);polar_decomp :: (M: Matrix3) -> (Q: Matrix3, S: Matrix3, det: float)
Splits the matrix into an orthogonal Q and a symmetric S with M = Q * S, and also
returns the determinant of M.
Parameters
- M: Matrix3
- the matrix to split.