Localization & SLAM · Theory · M2
M2-T2 — 3D Rotations and Rigid-Body Transformations
In 3D, the order in which you rotate changes the outcome. SLAM for drones and cameras depends on handling it correctly.
A wheeled robot on a flat floor has one rotation angle. A camera, a drone or a legged robot has three, and they do not behave like numbers: swapping two rotations changes the result. This lesson builds SO(3) and SE(3), their composition and inverse, and the exponential map that turns a small rotation vector into a rotation matrix.
Learning objectives
After this lesson, you should be able to:
- Describe SO(3) and SE(3) and state the properties of a rotation matrix.
- Show with an example that 3D rotations do not commute, and read a product of rotations in the right order.
- Compose and invert 4×4 rigid-body transforms.
- Use the Rodrigues formula to convert an axis and angle into a rotation matrix.
The intuition
Hold a book flat. Turn it a quarter turn about the vertical axis, then a quarter turn about the axis pointing from its spine to its fore-edge. Now start over and do the two quarter turns in the opposite order. The book ends up facing different ways. In 2D this cannot happen: every rotation turns about the same axis, so the order does not matter. In 3D, the axes themselves are moved by the rotations, and the final orientation depends on the sequence.
In 2D, rotations add. In 3D, they multiply, and multiplication of rotations is not commutative.
The mathematics
A 3D rotation is a 3×3 matrix R with two properties: it keeps lengths and handedness.
The set of all such matrices is SO(3), the Special Orthogonal group. Because Rᵀ R = I, the inverse is the transpose, and there are only three free numbers in nine entries. A rigid-body transform adds a translation:
- SO(3)
- rotations: 3×3 matrices with RᵀR = I and det R = 1. Three degrees of freedom.
- SE(3)
- rotations and translations: 4×4 matrices as above. Six degrees of freedom.
- t
- translation vector (3×1).
- TAB TBC
- composition: C in B, then B in A. The matrix on the left is applied last to a point.
Elementary rotations
Axis and angle: the exponential map
Every rotation is a turn by an angle θ about a unit axis n. Define the skew-symmetric matrix K of n, with K v = n × v. The Rodrigues formula gives the rotation matrix:
The rotation vector ω = θ n has three numbers and no constraints: it is the natural variable for optimisation, and the map ω → R is the exponential map of SO(3). For small ω, R ≈ I + [ω]×, which is why small errors in orientation can be treated as a 3-vector. This is used from Module 4 onward.
A rotation has three degrees of freedom, but no three-number representation is free of problems everywhere. That is the subject of the next lesson.
A worked example: order matters
Take a 90° rotation about z, Rz, and a 90° rotation about x, Rx:
- Product one. Rz Rx = [[0, 0, 1], [1, 0, 0], [0, 1, 0]]. Applied to the vector (1, 0, 0), the result is its first column: (0, 1, 0). Read right to left: first Rx (which leaves x alone), then Rz (which turns x into y).
- Product two. Rx Rz = [[0, −1, 0], [0, 0, −1], [1, 0, 0]]. Applied to (1, 0, 0) it gives (0, 0, 1). First Rz turns x into y, then Rx turns y into z.
- Compare. (0, 1, 0) ≠ (0, 0, 1). The two orderings differ by a quarter turn in the result: this is not a small effect that can be ignored.
- Check the structure. Each product has orthonormal columns and determinant +1, so both are valid rotations; the group is closed, just not commutative.
- Invert one. (Rz Rx)ᵀ = Rxᵀ Rzᵀ = [[0, 1, 0], [0, 0, 1], [1, 0, 0]]. The order reverses when you invert a product: (AB)⁻¹ = B⁻¹A⁻¹.
A camera mounted on a robot with a roll and a yaw offset shows exactly this: swapping the order of the two mounting rotations in a configuration file moves every point of the world.
Engineering implications and limitations
Where 3D transform bugs hide
- Order of rotation composition, including Euler-angle conventions (next lesson). Document it once and test it with a non-trivial case such as the example above.
- Active versus passive rotation: rotating a vector versus rotating the frame. The matrices are transposes of each other.
- Right-handed versus left-handed frames: some imaging and graphics libraries use different conventions. A reflection has determinant −1, and no rotation can fix it.
- Numerical drift: after thousands of multiplications, RᵀR is no longer exactly I. Re-orthonormalise (for example with an SVD or Gram-Schmidt) or use a parameterisation that stays valid.
- Frames of camera and robot: a camera typically has z forward, x right, y down; a robot has x forward, y left, z up. The fixed change between them is itself a rotation to be applied exactly once.
Limits
A 3×3 matrix uses nine numbers for three degrees of freedom, so it is redundant and constrained. Optimisers must keep it on SO(3): they do this by updating with small rotations R ← exp([δ]×) R rather than adding to the matrix entries. This is the reason the exponential map matters in SLAM.
Common misconceptions
“Rotations about different axes commute if the angles are small.”
They commute to first order only. The error is second order in the angles, which is small but systematic and relevant when composing thousands of increments.
“A rotation matrix has nine independent numbers.”
It has three degrees of freedom. The other six numbers are fixed by the orthonormality constraints.
“The inverse of a product is the product of inverses in the same order.”
(AB)⁻¹ = B⁻¹A⁻¹: the order reverses.
“Any matrix with orthonormal columns is a rotation.”
Its determinant must also be +1. With −1 it is a reflection, which changes handedness.
Engineering takeaways
- SO(3) is the set of 3×3 matrices with RᵀR = I and det R = 1; SE(3) adds a translation as a 4×4 matrix.
- 3D rotations do not commute: the order of composition is part of the answer.
- The inverse of a rotation is its transpose; the inverse of an SE(3) transform is (Rᵀ, −Rᵀt); the inverse of a product reverses the order.
- The Rodrigues formula R = I + sinθ K + (1 − cosθ) K² turns an axis and an angle into a rotation matrix.
- Optimisers update rotations with small exponential-map increments instead of adding to matrix entries.
References and further reading
Primary papers and authoritative documentation.
- Barfoot, T. D. (2017). State Estimation for Robotics. Cambridge University Press, chapters 6 and 7: rotations, transformations and the exponential map.
- Solà, J., Deray, J. and Atchuthan, D. (2018). A micro Lie theory for state estimation in robotics. arXiv:1812.01537.
- Blanco, J. L. (2010). A tutorial on SE(3) transformation parameterizations and on-manifold optimization. University of Málaga technical report.
- Lynch, K. M. and Park, F. C. (2017). Modern Robotics. Cambridge University Press, chapter 3.
Knowledge check
Three conceptual questions. Write an answer, then reveal the explanation. Your answers stay in your browser.
Question 1
A robot first yaws 90° about its z axis and then pitches 90° about its own (new) y axis. A teammate computes Ry(90°) Rz(90°). Is that right?
Explanation
No. Successive rotations about the moving (body) axes multiply on the right in the order performed: Rz Ry. Writing Ry Rz applies them about fixed axes in the opposite sequence and gives a different orientation (by the same non-commutativity as in the worked example). The convention must be stated and tested with a non-trivial case.
Question 2
Why does an optimiser update a rotation as R ← exp([δ]×) R instead of adding δ to the entries of R?
Explanation
Adding to the entries breaks the constraints RᵀR = I and det R = 1, so the result is no longer a rotation. Multiplying by the exponential of a small rotation vector keeps R on SO(3) and uses exactly three parameters for the three degrees of freedom.
Question 3
The matrix [[0, 1, 0], [1, 0, 0], [0, 0, 1]] has orthonormal columns. Is it a rotation?
Explanation
No. Its determinant is −1: it swaps the x and y axes, which is a reflection. A rotation must have determinant +1, otherwise it changes the handedness of the frame.
What’s next
Three numbers per rotation are enough, but there are many ways to choose them, and each has its own failure. Next: matrices, Euler angles, axis-angle and quaternions compared.
Related content
Nothing below is required to finish this lesson. The last 2 entries are lessons of other courses on this site that teach the background or go further.
- BeforeM2-T1: 2D Rigid-Body Transformations
Write, compose and invert SE(2) transforms and apply them to points.
- LabM2-L2: Diagnose a Pose-Transformation Error
A pose chain gives a wrong result: find the composition-order, inverse or angle-wrapping error among 3D and 2D variants.
- Linear AlgebraSO(3)
The group of 3D rotations: what makes a matrix a rotation, and why rotations cannot be added.
- Linear AlgebraSE(3)
Rigid-body transformations as a group: composition, inverse and the homogeneous form.
Get notified when the next lesson and new labs are released.
One email per new lesson or lab.