3
$\begingroup$

I am writing a plugin to export data from 3DS Max. 3DS Max's geometry pipeline is... interesting.

As part of my plugin I decompose a transform matrix into a translation, (quaternion) rotation & scale using an inbuilt function. This of course does not always work, such as when a shear is present.

Max does have an affine decomposition function, but I don't want to use that because the resulting components do not all have an analogue in the destination application.

What I'd like to do, is detect when the decomposition is lossy, so I can bake the geometry for the object which uses it, before transmitting it.

How can I determine, either before or after, whether a matrix TRS decomposition is exact?

$\endgroup$
1
  • 3
    $\begingroup$ Convert the TRS form back to a matrix and check if it's "close enough" to the original matrix? $\endgroup$ Jan 7, 2017 at 22:07

1 Answer 1

3
$\begingroup$

You can detect a matrix that can't be decomposed in TRS form by taking its 3×3 upper-left submatrix, interpreting its columns as vectors, and dotting them together in all combinations (1 with 2, 2 with 3, and 1 with 3). For a TRS matrix, the three dot products should all be zero, i.e. the column vectors should be orthogonal to each other. If any of the dot products are nonzero (beyond some epsilon to account for roundoff error) then the matrix is not decomposable as TRS.

This derives from the property that a rotation matrix is an orthogonal matrix, i.e. its column vectors form an orthonormal basis. When you multiply the rotation by a scaling matrix, the column vectors may no longer be unit vectors, but they should still be orthogonal. And the translation part doesn't affect the rotation-scaling part.

$\endgroup$
2
  • $\begingroup$ Thank you. This is the kind of thing I was looking for. There is an edge case I have found which is not detected - a negative scale in the original transform, but from what I've read I'm not sure its possible to detect this. $\endgroup$
    – sebf
    Jan 13, 2017 at 0:17
  • 1
    $\begingroup$ @sebf You can check the sign of the determinant of the 3×3 submatrix. That will detect if there's a handedness flip, which is caused by a negative scale along either 1 or 3 axes. However, if there was a negative scale along 2 axes originally, that's equivalent to a 180° rotation, so it's not possible in that case to tell the difference just from the final transform matrix. $\endgroup$ Jan 13, 2017 at 0:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.