How do you invert a rigid transform matrix holding only rotation and translation without a general 4x4 inverse, and when does that shortcut break?
answer
- rotation inverse is its transpose
- undo translation, then rotation
- the translation gets rotated too
- scale breaks orthonormality
basics
~20 sTranspose the rotation and rotate the negated translation back: inverse [R | t] = [R^T | -R^T * t]. It breaks once the 3x3 part holds scale or shear, because the transpose then no longer inverts it.
solid answer
~50 sWith column vectors a rigid transform maps `p' = R * p + t`. Solving for `p` gives `p = R^-1 * (p' - t)`, and because a rotation matrix is orthonormal, `R^-1 = R^T`. So the inverse is `[R^T | -R^T * t]` — the classic slip is writing `-t`, forgetting that the offset must be rotated back too. This costs a transpose and a matrix-vector multiply instead of a general 4x4 inverse, and it is exact rather than relying on a division. It breaks when the 3x3 part is `R * S`: with a uniform scale `s` the inverse 3x3 is `R^T / s`; with a non-uniform scale it is `S^-1 * R^T`, which the transpose `S * R^T` gets wrong, so divide each row by its axis's squared length or fall back to a general inverse. Float drift that makes `R` slightly non-orthonormal also degrades it.
code
pseudocode · 15 linesfunction invertRigid(R, t):
// R: 3x3 rotation with orthonormal columns, t: translation
// column vectors: p' = R * p + t
Rinv = transpose(R)
tinv = -(Rinv * t)
return (Rinv, tinv)
function invertOrthogonalScaled(A, t):
// A = R * S: columns perpendicular, lengths are the scale factors
Ainv = transpose(A)
for i in 0..2:
lenSq = dot(column(A, i), column(A, i))
row(Ainv, i) = row(Ainv, i) / lenSq
tinv = -(Ainv * t)
return (Ainv, tinv)go deeper
Recall that a rotation's inverse is its transpose and that inverting a transform undoes translation first, then rotation.
Derive [R^T | -R^T * t] from p' = R * p + t and explain why -t alone is wrong for rotated objects.
Choose the right path per object: rigid shortcut, per-axis scale correction, component inversion or a general inverse, and guard against orthonormality drift.
Decide whether the math library exposes separate rigid and general inverse functions, and how it proves an object is rigid before taking the fast path.
## The structure of a rigid transform A **rigid transform** moves and turns an object without changing its size or shape: a rotation `R` followed by a translation `t`. With the **column-vector convention** (`p' = M * p`) its 4x4 matrix is: ``` | R t | R = 3x3 rotation (orthonormal columns) | 0 1 | t = translation column ``` and it maps a point as `p' = R * p + t`. **Orthonormal** means the columns are unit length and mutually perpendicular, which gives the key property `R^T * R = I`: the transpose of a rotation is its inverse. ## Deriving the inverse 1. Start from `p' = R * p + t`. 2. Subtract the translation: `p' - t = R * p`. 3. Undo the rotation by multiplying by `R^T` on the left: `R^T * (p' - t) = p`. 4. Expand: `p = R^T * p' - R^T * t`. 5. Read off the inverse matrix: rotation part `R^T`, translation part `-R^T * t`. The work is a 3x3 transpose (just reading entries in a different order), nine multiplies and six additions for `R^T * t`, and three negations. A general 4x4 inverse by cofactors costs many times that, needs a division by the determinant, and loses precision when that determinant is small. ## A worked check Let `R` be a 90-degree turn about the vertical `y` axis, the matrix whose columns are `(0, 0, -1)`, `(0, 1, 0)` and `(1, 0, 0)`; let `t = (10, 0, 0)`. 1. Forward: the local point `(1, 0, 0)` becomes `R * (1, 0, 0) + t = (0, 0, -1) + (10, 0, 0) = (10, 0, -1)`. 2. The rows of `R^T` are the columns of `R`, so `R^T * t = (0, 0, 10)` and the inverse translation is `(0, 0, -10)`. 3. Inverse: `R^T * (10, 0, -1) = (1, 0, 10)`; adding `(0, 0, -10)` gives `(1, 0, 0)`. Correct. 4. With the classic slip, translation `-t = (-10, 0, 0)`, the result is `(-9, 0, 10)`: wrong by a large margin, and only for rotated objects, which is why the bug hides in unrotated test scenes. ## When the shortcut breaks | 3x3 part | its inverse | does the plain transpose work? | |---|---|---| | `R` (rotation only) | `R^T` | yes | | `s * R` (uniform scale `s`) | `R^T / s` | no: divide by `s` twice, once to undo the scale already in the transpose and once more to invert it, so use `(s * R)^T / s^2` | | `R * S` (non-uniform scale) | `S^-1 * R^T` | no: the transpose is `S * R^T`, which reapplies the scale; divide row i by the squared length of column i | | general, with shear | needs a general inverse | no | The translation part follows the same rule in every row: it is minus the inverse 3x3 times `t`. ## Practical notes - **Detect the case once.** Many engines know whether an object is rigid from its scale components and pick the fast path; checking that each column has unit length is the fallback test. - **Keep components when you have them.** If the object stores position, rotation and scale, its inverse is `S^-1 * R^T * T(-t)`, built directly with no inversion at all. With non-uniform scale that product is a valid matrix but no longer a plain scale-rotate-translate, so it cannot be stored back as components. - **Watch for drift.** A rotation built by multiplying many small rotations together accumulates rounding error and stops being exactly orthonormal; its transpose then only approximately inverts it, and the object slowly shears. Re-orthonormalise the columns, or rebuild the matrix from a stored orientation, periodically. - **Verify with a product.** `M * inverse(M)` should be the identity to within a small tolerance; it is a cheap unit test with an asymmetric matrix.
- Why is the inverse of a rotation matrix equal to its transpose?Its columns are unit length and mutually perpendicular. Entry (i, j) of R^T * R is the dot product of column i with column j, which is 1 when i equals j and 0 otherwise, so R^T * R is the identity and R^T is the inverse.
- How do you invert a transform you hold as separate position, rotation and scale?Invert each piece and reverse the order: (T * R * S)^-1 = S^-1 * R^T * T(-t), with S^-1 holding the reciprocal scale factors. No general inverse is needed. With non-uniform scale the result is correct as a matrix but is not itself a scale-rotate-translate, so it cannot be stored back as three components.
- What goes wrong if a rotation matrix slowly stops being orthonormal?Its transpose stops being its exact inverse, so world-to-local conversions pick up a small error, and the object itself gradually scales or shears. Re-orthonormalise the columns periodically, for example with Gram-Schmidt, or rebuild the matrix from a stored, normalised orientation.
- The inverse of [R | t] is [R^T | -t]
- Transposing the whole 4x4 matrix inverts a rigid transform
- The transpose trick still works when the matrix contains scale
- Any matrix with translation needs a general 4x4 inverse
- Bugs from a wrong inverse would show up in an unrotated test scene