Skip to the lesson
FixTheRobot Explore Robotics / Localization & SLAM / M2 Mathematical Foundations / M2-T2

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.

  • Lesson 2 of 7
  • Module 2: Mathematical Foundations
  • Theory
  • About 8 minutes to read

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.

Rotations do not commuteTwo products of the same two quarter-turn matrices. Rz Rx applies Rx first and then Rz, sending the x axis to the y axis. Rx Rz applies Rz first and then Rx, sending the x axis to the z axis.Rz · Rx (Rx acts first) x axisRx xRz y Rx · Rz (Rz acts first) x axisRz yRx z Same two quarter turns, different order: the x axis ends up on y in one case and on z in the other. Rx leaves the x axis alone, so in the first product only Rz moves it.
The same two quarter turns multiplied in the two possible orders send the x axis to different axes. Matrix products act right to left.

The mathematics

A 3D rotation is a 3×3 matrix R with two properties: it keeps lengths and handedness.

Rotation matrix conditions
R⊤ R=IR^{\top}\,R=I
det⁡ R=+1\det \,R=+1

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:

SE(3) transform and inverse
T=[Rt01]T=\begin{bmatrix}R & t \\ 0 & 1\end{bmatrix}
T−1=[R⊤−R⊤ t01]T^{-1}=\begin{bmatrix}R^{\top} & -R^{\top}\,t \\ 0 & 1\end{bmatrix}
T p∼=(R p+t, 1)T\,p\sim =(R\,p+t,\,1)
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

Rotations about z and x
Rz⁡(a)=[cos⁡ a−sin⁡ a0sin⁡ acos⁡ a0001]\operatorname{Rz}(a)=\begin{bmatrix}\cos \,a & -\sin \,a & 0 \\ \sin \,a & \cos \,a & 0 \\ 0 & 0 & 1\end{bmatrix}
Rx⁡(a)=[1000cos⁡ a−sin⁡ a0sin⁡ acos⁡ a]\operatorname{Rx}(a)=\begin{bmatrix}1 & 0 & 0 \\ 0 & \cos \,a & -\sin \,a \\ 0 & \sin \,a & \cos \,a\end{bmatrix}

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:

Rodrigues formula
K=[0−nznynz0−nx−nynx0]K=\begin{bmatrix}0 & -n_{z} & n_{y} \\ n_{z} & 0 & -n_{x} \\ -n_{y} & n_{x} & 0\end{bmatrix}
R=I+sin⁡θ K+(1−cos⁡θ) K2R=I+\sin \theta \,K+(1-\cos \theta )\,K^{2}

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:

The two rotations
Rz=[0−10100001]\mathrm{Rz}=\begin{bmatrix}0 & -1 & 0 \\ 1 & 0 & 0 \\ 0 & 0 & 1\end{bmatrix}
Rx=[10000−1010]\mathrm{Rx}=\begin{bmatrix}1 & 0 & 0 \\ 0 & 0 & -1 \\ 0 & 1 & 0\end{bmatrix}
  1. 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).
  2. 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.
  3. 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.
  4. Check the structure. Each product has orthonormal columns and determinant +1, so both are valid rotations; the group is closed, just not commutative.
  5. 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

  1. 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.
  2. 3D rotations do not commute: the order of composition is part of the answer.
  3. 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.
  4. The Rodrigues formula R = I + sinθ K + (1 − cosθ) K² turns an axis and an angle into a rotation matrix.
  5. Optimisers update rotations with small exponential-map increments instead of adding to matrix entries.

References and further reading

Primary papers and authoritative documentation.

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.

Practice this lesson

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.

Next lesson

M2-T3 — Rotation Matrices, Quaternions, and Pose Representation

Choose among rotation matrices, Euler angles, axis-angle and quaternions and convert safely between them.

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.

  • Before
    M2-T1: 2D Rigid-Body Transformations

    Write, compose and invert SE(2) transforms and apply them to points.

  • Lab
    M2-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 Algebra
    SO(3)

    The group of 3D rotations: what makes a matrix a rotation, and why rotations cannot be added.

  • Linear Algebra
    SE(3)

    Rigid-body transformations as a group: composition, inverse and the homogeneous form.