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

Localization & SLAM · Theory · M2

M2-T1 — 2D Rigid-Body Transformations

Every 2D pose is a rotation and a translation. Learn the algebra once and every frame bug becomes easy to find.

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

Lesson M1-T4 introduced frames and poses in words and with component formulas. This lesson gives the matrix form, shows that poses form a group with an identity and inverses, derives the exact motion of a robot along an arc, and lists the numerical traps that cause most transform bugs in practice.

Learning objectives

After this lesson, you should be able to:

  • Write an SE(2) pose as a 3×3 homogeneous matrix and use it to transform points and compose frames.
  • Compute the inverse of a pose and verify it by multiplication.
  • Derive the exact arc update for constant forward and angular velocity and compare it with the midpoint rule.
  • Wrap angles correctly and avoid the common traps of angle arithmetic.

The intuition

A 2D pose answers two questions at once: how is this frame turned? and where is its origin? Those two facts are a rotation followed by a translation. Packing them into one 3×3 matrix lets you chain frames by multiplying matrices, instead of juggling sines and cosines. The price is nothing: the matrix is just a tidy container for the same three numbers.

A transform is something you can do to any point. A pose is the same thing used to describe where a frame is. They are one object seen two ways.

Composing two 2D transformsFrame A at the origin, frame B at (2,1) rotated 90 degrees, and frame C at (3,0) in B rotated by minus 45 degrees. Arrows show T_AB and T_BC. The composed pose T_AC puts C at (2,4) facing 45 degrees. A B C T_AB T_BC T_AB = (2, 1, 90°)T_BC = (3, 0, −45°) T_AC = T_AB ⊕ T_BC = (2, 4, 45°) C sits 3 m along the y axis of B,and B’s y axis points along 90°.
Composition by chaining: C is described in B, B in A. Multiplying their matrices gives C in A.

The mathematics

A pose (x, y, θ) written as a homogeneous matrix, and a point (px, py) extended with a trailing 1:

Homogeneous SE(2) matrix
T=[cos⁡θ−sin⁡θxsin⁡θcos⁡θy001]T=\begin{bmatrix}\cos \theta & -\sin \theta & x \\ \sin \theta & \cos \theta & y \\ 0 & 0 & 1\end{bmatrix}
p∼=[pxpy1]p\sim =\begin{bmatrix}p_{x} \\ p_{y} \\ 1\end{bmatrix}
T p∼=(R p+t, 1)T\,p\sim =(R\,p+t,\,1)
TAB
the pose of frame B in frame A. Applied to a point written in B, it gives that point in A.
R, t
the rotation block (2×2) and the translation (2×1) inside T.
p~
a point with a trailing 1: the “homogeneous” form, which lets a translation be a matrix product.
⊕
pose composition: TAC = TAB TBC.

Group properties

The set of all such matrices is called SE(2), the Special Euclidean group in 2D. It has what any pose algebra needs: closure (composing two poses gives a pose), an identity (x = y = θ = 0), an inverse for every pose, and associativity (T1T2)T3 = T1(T2T3). It is not commutative: T1T2 ≠ T2T1 in general.

The inverse uses the fact that a rotation matrix inverts by transposing:

Inverse of an SE(2) matrix
T−1=[R⊤−R⊤t0⊤1]\mathbf T^{-1} = \begin{bmatrix}\mathbf R^{\top} & -\mathbf R^{\top}\mathbf t\\ \mathbf 0^{\top} & 1\end{bmatrix}
In components
T−1=[cos⁡θsin⁡θ−(cos⁡θ x+sin⁡θ y)−sin⁡θcos⁡θ−(−sin⁡θ x+cos⁡θ y)001]\mathbf T^{-1} = \begin{bmatrix}\cos\theta & \sin\theta & -(\cos\theta\,x + \sin\theta\,y)\\ -\sin\theta & \cos\theta & -(-\sin\theta\,x + \cos\theta\,y)\\ 0 & 0 & 1\end{bmatrix}

Exact motion along an arc

A robot moving with constant forward speed v and turn rate ω for time Δ traces a circular arc. Its pose change in its own starting frame is exact:

Exact arc increment
Δθ=ω Δ\Delta \theta =\omega \,\Delta
Δx=(vω) sin⁡(Δθ)\Delta x=(\frac{v}{\omega })\,\sin (\Delta \theta )
Δy=(vω)(1−cos⁡(Δθ))\Delta y=(\frac{v}{\omega })(1-\cos (\Delta \theta ))
(ω≠0)(\omega \ne 0)
limit ω→0: Δx=v Δ, Δy=0\text{limit}\,\omega \to 0:\,\Delta x=v\,\Delta ,\,\Delta y=0

The new pose is the old pose composed with this increment. The midpoint rule from the odometry lesson, Δx = v Δ cos(Δθ/2), Δy = v Δ sin(Δθ/2), is a second-order approximation of it. For small turns they agree; for large turns in one step the midpoint rule is visibly wrong.

Angles

θ and θ + 2π are the same orientation, but a computer does not know that. Always wrap after adding angles, and compare angles through their wrapped difference:

Angle wrapping
wrap⁡(a)=atan2(sin⁡ a, cos⁡ a)\operatorname{wrap}(a)=\mathrm{atan}2(\sin \,a,\,\cos \,a)
error=wrap⁡(θest−θtrue)\text{error}=\operatorname{wrap}(\theta _{\text{est}}-\theta _{\text{true}})

Never subtract two raw angles and call the result an error. 179° − (−179°) = 358°, but the real error is 2°.

A worked example: chain, inverse and arc

Frame B is at TAB = (2, 1, 90°) in A. Frame C is at TBC = (3, 0, −45°) in B.

  1. Transform a point. The point (1, 0) in B has A-coordinates R(90°)(1, 0) + (2, 1) = (0, 1) + (2, 1) = (2, 2).
  2. Compose. x = 2 + cos 90° · 3 − sin 90° · 0 = 2; y = 1 + sin 90° · 3 + cos 90° · 0 = 4; θ = 90° − 45° = 45°. So TAC = (2, 4, 45°): C sits 3 m along B’s y axis, which points in A’s +y direction.
  3. Invert. With cos 90° = 0 and sin 90° = 1: xinv = −(0·2 + 1·1) = −1, yinv = −(−1·2 + 0·1) = 2, θinv = −90°. So TBA = (−1, 2, −90°).
  4. Verify. Apply TBA to the A-point (2, 2): R(−90°)(2, 2) = (2, −2); adding (−1, 2) gives (1, 0), the original B-point. ✓
  5. Arc versus midpoint. A robot drives v = 1 m/s with ω = π/2 rad/s for one second. Exact: Δθ = 90°, Δx = (1 / (π/2)) sin 90° = 0.6366, Δy = (1 / (π/2))(1 − cos 90°) = 0.6366. Midpoint: (cos 45°, sin 45°) = (0.7071, 0.7071). The midpoint rule is off by 0.070 m after a single step: 7% of the step length. With small steps this vanishes, with big ones it does not.

Exactly this inversion and composition are what you wrote in the Module 1 frames lab. Here it is stated as algebra, so you can check any transform by multiplication.

Engineering implications and limitations

Practical rules

  • Name every transform Tto_from or Tfrom_in consistently (for example odom_T_base). A matrix chain should read like a chain of frame names that cancel: AT_B · BT_C = AT_C.
  • Wrap after every angle addition and compare headings through wrapped differences. Tests with headings near ±180° catch most missing wraps.
  • Prefer matrices or (x, y, cosθ, sinθ) when you average, interpolate or optimise orientation. The average of 179° and −179° is 180°, not 0°.
  • Use the exact arc when steps are large (low-rate wheel odometry, fast turns). The midpoint rule is fine for 50 Hz odometry at moderate speed.
  • Check composition numerically: compose a pose with its inverse and expect the identity to within about 1e-9. A wrong inverse formula passes casual tests and fails this one.

Limits

SE(2) assumes the robot lives on a flat plane. Pitch and roll on ramps, uneven ground or a drone need SE(3) (next lesson). The algebra is the same; the rotation block becomes 3×3 and the angle becomes three parameters.

Common misconceptions

“Composition order does not matter for small motions.”

For small increments the error is small but systematic, and it accumulates exactly like odometry drift. The order is part of the definition, not a detail.

“The inverse of (x, y, θ) is (−x, −y, −θ).”

Only the heading is simply negated. The translation of the inverse is −Rᵀt: it must be rotated back into the other frame.

“Averaging headings is averaging numbers.”

Angles live on a circle. Average the vectors (cos θ, sin θ) and take atan2, or work with rotation matrices.

“The midpoint rule is the exact motion.”

It approximates the arc with a chord at the half angle. It is accurate for small steps and 7% off for a 90° turn in one step.

Engineering takeaways

  1. A 2D pose is a 3×3 homogeneous matrix; composing frames is matrix multiplication.
  2. Poses form a group: closure, identity, inverses, associativity, but no commutativity.
  3. The inverse is (Rᵀ, −Rᵀt), not the negated components.
  4. Exact arc motion is Δx = (v/ω) sinΔθ, Δy = (v/ω)(1 − cosΔθ); the midpoint rule is its small-step approximation.
  5. Always wrap angles and compare headings through wrapped differences.

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

Frame B is at (4, 0, 180°) in frame A. What are the A-coordinates of the point (1, 0) written in B?

Explanation

Rotating (1, 0) by 180° gives (−1, 0). Adding the translation (4, 0) gives (3, 0). The point is one metre from B’s origin in B’s +x direction, but B faces the other way, so it lies toward A’s origin.

Question 2

A colleague computes a heading error as θest − θtrue and gets 358°. What is the real error and how would you compute it?

Explanation

The real error is 2°. Wrap the difference: error = atan2(sin(θest − θtrue), cos(θest − θtrue)). The raw difference confuses two representations of nearly the same orientation.

Question 3

Why would you use the exact arc update rather than the midpoint rule for a robot spinning fast with a 5 Hz odometry stream?

Explanation

Each step then contains a large turn, and the midpoint rule’s error grows with the turn angle per step (about 7% of the step length for 90°). The exact arc formula has no such error, so it removes a systematic bias that would otherwise accumulate.

What’s next

Real robots, and every drone, work in 3D. Next, the same ideas with rotations that do not commute even in the plane of one step.

Practice this lesson

Transform Points Between Coordinate Frames

Implement compose, inverse and point transform for 2D poses and use them to put sensor points into the world frame.

Next lesson

M2-T2 — 3D Rotations and Rigid-Body Transformations

Extend to SO(3) and SE(3): composition order, non-commutativity and the exponential map.

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.