Linear Algebra · Theory · M7
M7-T7 — Rotation Composition and Inverse
Most frame bugs are one of two mistakes: multiplying in the wrong order or inverting the wrong way. A simple labelling rule catches both.
The previous lessons gave the algebra of a single transform. Real robots chain five or six: world, odometry, base, sensor mount, sensor. This lesson is about getting the chain right: order of multiplication, inversion of a whole chain, relative rotations, and the difference between fixed-axis and body-axis composition.
Learning objectives
After this lesson, you should be able to:
- Compose a chain of transforms in the correct order using the inner-subscripts rule.
- Invert a chain by reversing it and inverting every factor, without a general matrix inverse.
- Compute the relative rotation and relative pose between two poses.
- Explain the difference between composing about fixed axes and about moving axes, and spot the usual bugs.
Introduction and motivation
A LiDAR scan appears 5 m to the left of the wall in the map. Nothing in the sensor is broken: someone wrote T_BL * T_WB instead of T_WB * T_BL. Because both are valid 4 × 4 matrices the code runs, and the result is plausible-looking but wrong. A written rule that every engineer on the team applies to every product removes this whole class of bug.
The intuition
Treat the subscripts as a chain of labels: T_WB converts from B to W, T_BL from L to B. To convert from L to W, you want B to appear once on the right of the first matrix and once on the left of the second, so they meet and disappear: T_WB T_BL = T_WL. The matrices are applied to the point from the right: the point is first mapped from L to B, then from B to W. If the labels do not meet, the product has no meaning.
Interactive figure. The F-shaped outline transformed by a rotation and a stretch in two different orders. The two results differ unless the stretches are equal, which shows that the order of matrix multiplication matters. This figure needs JavaScript to be interactive.
Geometric and physical interpretation
Geometric view. T_WB T_BL first re-expresses the point relative to the base axes, then places the base in the world. Reading left to right instead describes the same motion as a sequence of moves about the moving frame: start at W, move to B, then from there move to L. Reading right to left describes it as moves about the fixed world axes, applied in reverse. Both views give the same matrix. Physical view. “The robot is here, and the sensor is mounted this far from the robot” is one product; reversing it would mount the sensor relative to the world origin.
The mathematics
- TAB TBC
- composition; the inner B cancels, giving TAC.
- T⁻¹
- inverse, [[Rᵀ, −Rᵀt], [0, 1]].
- RAB
- rotation of frame B relative to frame A.
- Rrel
- relative rotation between two poses: RWAᵀ RWB.
Composition of a chain
TWL = TWB TBL, ʷp = TWB TBL ᴸp
What it means. Apply the right-most matrix to the point first. The product is valid only when adjacent labels match; if they do not, a transform or an inverse is missing.
Inverse of a chain
(T₁T₂ ⋯ Tₙ)⁻¹ = Tₙ⁻¹ ⋯ T₂⁻¹ T₁⁻¹ TBW = TWB⁻¹
What it means. To undo a chain of operations, undo the last first. Each factor is inverted with the closed form from the SE(3) lesson. A transform with swapped labels is the inverse of the original.
Relative rotation
RAB = RWAᵀ RWB (relative orientation of B with respect to A)
What it means. Rotations do not subtract. The difference between two orientations is the rotation that takes one to the other, obtained by composing one with the inverse (transpose) of the other. Its angle is the true angular distance between them.
Match inner labels, apply right to left, and invert a chain by reversing it. The difference of orientations is RₐᵀR_b, not Rₐ − Rb.
Step-by-step derivation: why the order is what it is
- The point passes through the frames. A point
ᴸpis converted to base coordinates byᴮp = T_BL ᴸp, then to the world byʷp = T_WB ᴮp. - Substitute.
ʷp = T_WB (T_BL ᴸp) = (T_WB T_BL) ᴸp, using associativity. So the matrix acting onᴸpisT_WB T_BL, and the inner B has cancelled. - Inverse of a product. We want
(AB)⁻¹. Check(AB)(B⁻¹A⁻¹) = A(BB⁻¹)A⁻¹ = AA⁻¹ = I, so(AB)⁻¹ = B⁻¹A⁻¹: the order reverses. For a chain, the same argument applied repeatedly gives the reversed list of inverses. - Relative rotation. Orientations of A and B in the world satisfy
R_WB = R_WA R_AB(B is A followed by the relative turn). Left-multiply byR_WAᵀ = R_WA⁻¹to getR_AB = R_WAᵀ R_WB. - Relative angle. The angle of
R_ABfollows from its trace,cos θ = (tr R_AB − 1)/2. This is the true angular distance between two attitudes, the quantity used to measure an orientation error. - Fixed versus moving axes. Starting from an orientation
R, a turnQexpressed in the world axes is applied asQ R(pre-multiply); a turn expressed in the body axes is applied asR Q(post-multiply). The two coincide only when Q commutes with R, for instance both are rotations about the same axis.
Sensors on a moving robot. A measurement stamped at time t must use the pose T_WB(t) at that time, not the latest pose. For a spinning LiDAR, each point has its own timestamp and its own pose (motion distortion), so the single product above is applied with a different T_WB per point.
The loop-closure error. Going around a loop of frames and returning to the start should give the identity: T₁T₂T₃T₄ = I. The deviation from identity is the residual that pose-graph optimisation drives to zero.
A worked example: base pose, lidar mount and a point
- Setup (2D). The robot base is at
(2, 1)with heading 90°:T_WB = [[0, −1, 2], [1, 0, 1], [0, 0, 1]]. The LiDAR is 0.3 m forward on the base, unrotated:T_BL = [[1, 0, 0.3], [0, 1, 0], [0, 0, 1]]. - The return. A return 4 m away at 30°:
ᴸp = (3.464, 2, 1). - Correct order.
T_BL ᴸp = (3.764, 2, 1), thenT_WB (3.764, 2, 1) = (−2 + 2, 3.764 + 1, 1) = (0, 4.764, 1). The world point is(0, 4.764). - Wrong order.
T_BL T_WB ᴸp:T_WB ᴸp = (0, 4.464, 1), thenT_BLadds 0.3 to x:(0.3, 4.464, 1). It is off by(0.3, −0.3), about 0.42 m, a believable-looking error. - Inverse of the chain.
T_LW = (T_WB T_BL)⁻¹ = T_BL⁻¹ T_WB⁻¹. Applying it to the world point(0, 4.764)returns(3.464, 2), the original lidar point ✓. - Relative rotation. A drone yaws from 30° to 80°:
R_AB = Rz(30°)ᵀRz(80°) = Rz(50°), relative angle 50°, with trace1 + 2 cos 50° = 2.2856.
Robotics application
SLAM front ends. The scan-to-map pipeline multiplies sensor mount, odometry pose and map correction; each scan point goes lidar → base → odom → map; see TF frames and consistency and scan registration.
Pose graphs. Edge residuals are products of inverses of measured transforms and relative poses; loop closure is the identity-deviation of a chain; see pose graphs.
UAV state estimation. Camera, IMU and LiDAR calibrations chain to the body pose; attitude error is the relative rotation R_estᵀR_true, and its angle is the headline accuracy metric; see extrinsic calibration and the error-state Kalman filter.
Manipulators. Forward kinematics is a product of link transforms in order from base to tool; inverting it gives the tool-to-base chain (Module 8).
Engineering implications and limitations
Practical rules
- Write the labels, always. Name every transform
T_target_sourceand check that the inner names match in each product. If they do not, find the missing inverse. - Compose in one place. Build the chain with one helper function and unit tests with a known point; do not scatter manual multiplications across the code base.
- Test with a known point. Choose a configuration with an obvious answer (robot turned 90°, sensor 1 m forward) and assert the world coordinates.
- Look up the transform at the right time. Use the pose interpolated at the measurement timestamp, not the latest. Moving fast makes a 50 ms mismatch visible.
- Closed-form inverse only. Use
[[Rᵀ, −Rᵀt], [0, 1]]; a generalinvloses orthogonality over time. - Measure attitude error with the relative rotation. The angle of
R_estᵀR_true, not the difference of Euler angles, which can jump by 360° or be wrong near gimbal lock.
Limits
Composition assumes exact, time-aligned transforms. Calibration error, timestamp error and drift in the chain are not captured by the algebra; they must be modelled as uncertainty (Modules 9 and 10).
Common misconceptions
“Order does not matter if both matrices are valid transforms.”
It matters. Both orders are valid matrices, which is exactly why the bug is silent.
“The inverse of T₁T₂ is T₁⁻¹T₂⁻¹.”
It is T₂⁻¹T₁⁻¹: the order reverses.
“The difference between two orientations is RB − RA.”
The difference of rotation matrices is not a rotation. Use RAᵀR_B, whose angle is the true difference.
“Pre- and post-multiplying an incremental rotation are equivalent.”
Pre-multiplying turns about the world axes, post-multiplying about the body axes; they agree only for rotations about the same axis.
Engineering takeaways
- Compose transforms so that inner frame labels cancel: TWB TBL = TWL; apply the right-most factor to the point first.
- Invert a chain by reversing it and inverting each factor: (T₁T₂)⁻¹ = T₂⁻¹T₁⁻¹.
- The relative orientation is RAB = RWAᵀR_WB; its angle, from the trace, is the true angular error.
- Pre-multiply for fixed-axis turns, post-multiply for body-axis turns.
- Test chains with a known point, and use the pose at the measurement timestamp.
References and further reading
Primary papers and authoritative documentation.
- Modern Robotics (Lynch and Park), free preprint: chapter 3.3.1, uses of transformation matrices: changing frames and composing
- Barfoot, State Estimation for Robotics (author-hosted first edition, free to read): chapter 6, composing and inverting poses
- Solà, Deray and Atchuthan, A micro Lie theory for state estimation in robotics: A micro Lie theory: composition and the inverse of the group
- UCSD ECE276A: Sensing and Estimation in Robotics: transform chains and the pose graph
Knowledge check
Three conceptual questions. Write an answer, then reveal the explanation. Your answers stay in your browser.
Question 1
A sensor is mounted at TBS = trans(0.5, 0) (50 cm forward). The robot is at TWB with heading 0° and position (3, 2). Where is a point (2, 1) in the sensor frame, in the world?
Explanation
TWB TBS (2, 1, 1): TBS gives (2.5, 1, 1), then TWB with no rotation adds (3, 2): (5.5, 3). The sensor is 0.5 m ahead of the robot and the point is 2 m ahead, 1 m left of the sensor: world (3 + 0.5 + 2, 2 + 1) = (5.5, 3) ✓.
Question 2
Write TSW (world to sensor) for the chain TWB TBS using only TWB⁻¹ and TBS⁻¹.
Explanation
TSW = (TWB TBS)⁻¹ = TBS⁻¹ TWB⁻¹, i.e. first convert world to base (TBW = TWB⁻¹), then base to sensor (TSB = TBS⁻¹). The labels read S←B then B←W.
Question 3
Two attitude estimates differ: the estimate is Rz(10°)Rx(5°) and the truth is Rz(10°). What is the attitude error angle?
Explanation
Rerr = Restᵀ Rtrue = Rx(5°)ᵀ Rz(10°)ᵀ Rz(10°) = Rx(−5°). The trace of Rx(−5°) is 1 + 2cos 5° = 2.9924, so the angle is arccos((2.9924 − 1)/2) = 5°: the error is 5° about the x-axis.
What’s next
Rotation matrices are exact but use nine numbers. The next lesson compares the compact alternatives (Euler angles, axis-angle and quaternions), and explains the singularity that makes three-angle descriptions risky.
Related content
Nothing below is required to finish this lesson.
- BeforeM7-T6: SE(3)
Describe the group of rigid-body motions and use the structure of a 4×4 transform.
- LabM7-L1: Robot Coordinate Frame Explorer
Chain frames from the world to a sensor on an arm, find the wrong-order and inverse bugs, and bring a measured point back to the world.
Get notified when the next lesson and new labs are released.
One email per new lesson or lab.