<p>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.</p>

<p>This derives from the property that a rotation matrix is an <a href="https://en.wikipedia.org/wiki/Orthogonal_matrix" rel="nofollow noreferrer">orthogonal matrix</a>, 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.</p>

CC BY-SA 3.0
2017-01-13T00:17:14.220Z
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.
sebf
CC BY-SA 3.0
2017-01-13T00:35:30.210Z
@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.
Nathan Reed
CC BY-SA 3.0
2017-01-08T19:36:44.920Z
2017-01-08T19:36:44.920Z
Nathan Reed
<p>I am writing a plugin to export data from 3DS Max. 3DS Max's geometry pipeline is... interesting.</p>

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

<p>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.</p>

<p>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.</p>

<p><strong>How can I determine, either before or after, whether a matrix TRS decomposition is exact?</strong></p>

CC BY-SA 3.0
2017-01-07T22:07:50.357Z
Convert the TRS form back to a matrix and check if it's "close enough" to the original matrix?
Nathan Reed
<transformations><matrix>
Detect a lossy matrix decomposition?
sebf
# Detect a lossy matrix decomposition?

(Asked by: username_0 on 2017-01-07)

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?**

**Tags:** transformations, matrix

> **Comments:**
> **username_1**: Convert the TRS form back to a matrix and check if it's "close enough" to the original matrix?  

---

## 1 answers

### Answer by username_1 on 2017-01-08. Score: 3 | Accepted answer

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](https://en.wikipedia.org/wiki/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.

> **Comments:**
> **username_0**: 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.  
> **username_1**: @username_0 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.  

---

