Math for Robotics · Lesson 10
Homogeneous Transformation
Est. 35–45 min
Why
Why pack R and t into one matrix
Concept
The big idea: homogeneous coordinates glue rotation and translation
- Write a 2D point as (x, y, 1). The trailing 1 is the homogeneous trick.
- Block layout: top-left R, top-right t, bottom row [0 0 1].
- H₁ · H₂ composes transforms. Apply to (x,y,1) to move a point.
- In 3D: 4×4 with 3×3 R, 3×1 t, bottom [0 0 0 1].
H = [[ R t ], [ 0 0 1 ]] (2D) H = [[ R t ], [ 0 0 0 1 ]] (3D)
How it works
How it actually works, step by step
Build R and t
Same as the previous lesson.
Pack into H
Place R in the upper-left, t in the last column (except bottom), bottom row zeros then 1.
Multiply Hs to compose
H_world_tool = H_world_base · H_base_tool.
Apply to a point
Multiply H by [x,y,1]ᵀ; read the first two entries (2D).
Visual
Visualise it: pose as one object
A robot pose is exactly what a homogeneous transform encodes: orientation plus position of a frame.
Interactive · Robot pose / transformation demo
Tip (x, y)
(152.1, 75.4)
Tip yaw
-5.0°
Simplification: planar 2R arm. Each joint adds a rotation; tip pose is the product of link transforms — the same idea as homogeneous chains on a 6DOF arm.
Worked example
Worked example: compose two planar Hs
Code lab
Code lab: homogeneous 3×3 in the plane
"""Stage 1 L10 — pack R and t into a 3×3 homogeneous matrix (2D)."""
import math
def H(theta_deg, tx, ty):
th = math.radians(theta_deg)
c, s = math.cos(th), math.sin(th)
return (
(c, -s, tx),
(s, c, ty),
(0, 0, 1),
)
def mul(A, B):
return tuple(
tuple(A[i][0]*B[0][j] + A[i][1]*B[1][j] + A[i][2]*B[2][j] for j in range(3))
for i in range(3)
)
def apply(M, x, y):
X = M[0][0]*x + M[0][1]*y + M[0][2]
Y = M[1][0]*x + M[1][1]*y + M[1][2]
return X, Y
H1 = H(30, 0.5, 0.1)
H2 = H(-10, 0.2, 0.0)
H12 = mul(H1, H2)
p = apply(H12, 0.1, 0.0)
print("H1 (30°, t=(0.5,0.1)):")
for row in H1:
print(" ", tuple(round(v, 4) for v in row))
print("H1·H2 applied to (0.1, 0) → ({:.4f}, {:.4f})".format(*p))
print("Bottom row stays [0, 0, 1] — that is the homogeneous trick.")Expected output
H1 (30°, t=(0.5,0.1)): (0.866, -0.5, 0.5) (0.5, 0.866, 0.1) (0, 0, 1) H1·H2 applied to (0.1, 0) → (0.7672, 0.2342) Bottom row stays [0, 0, 1] — that is the homogeneous trick.
Real world
4×4 matrices in robot stacks
- URDF / robot description link origins as 4×4 poses
- Camera pose from vision code comes as R and t (OpenCV gives rvec/tvec) — pack them into one 4×4 H
- Robot controllers store tool and work-object frames as position + orientation — exactly what one H holds
Mistakes
Common mistakes and confusions
Hardware & safety
Hardware lab and safety notes
Use the paper arm again: each joint gets one 3×3 H. Multiplying H1·H2 should give the tip you measure with a ruler — that is how real arm code computes FK.
- Set link 1 at 30° with the pin at (0, 0); link 2 at −10° relative to link 1.
- Write H1 and H2 on paper, multiply, apply to the tip point.
- Measure the real tip and compare (allow 2–3 mm).
Debugging
Debugging: when it doesn’t work
| Symptom | Likely cause | Fix |
|---|---|---|
| Translation ignored | Point written as (x, y, 0) instead of (x, y, 1) | Points need the homogeneous 1 |
| Bottom row is not [0, 0, 1] | Typo while building H | Rebuild: [[R, t], [0 0 1]] |
| Tip off by a full link | Multiplied H2·H1 instead of H1·H2 | Parent first: base→link1 then link1→link2 |
| Direction vector moved when it shouldn't | Used 1 instead of 0 for a direction | Directions use 0 so translation is skipped |
Think
Think about it
Think
Why does the bottom row stay [0,0,1] after multiplying two rigid Hs?
Experiment
Try it in the lab: read a block layout
Experiment
Read a block layout
You will need
- Notebook
- homog_2d.py output
Steps
- Copy one printed H1 matrix.
- Circle the 2×2 R block and the t column.
- Confirm bottom row is 0,0,1.
Interactive · Robot pose / transformation demo
Tip (x, y)
(152.1, 75.4)
Tip yaw
-5.0°
Simplification: planar 2R arm. Each joint adds a rotation; tip pose is the product of link transforms — the same idea as homogeneous chains on a 6DOF arm.
You should always be able to point to R and t inside H.
Knowledge check
Check your understanding
Knowledge check
1. Homogeneous 2D transforms are usually…
2. Bottom row of a planar H is…
3. Composition of poses becomes…
4. In 3D, rigid H is typically…
Practice quiz
Mini assignment
Hands-on assignment
Mini assignment
Draw one H
Hand-write a 3×3 H for θ=90°, t=(0.1, 0.2). Apply it to (0.05, 0) on paper.
Deliverables
- Matrix
- Result point
Do this, step by step
- Hand-write H for θ = 90°, t = (0.1, 0.2).
- Apply it to (0.05, 0, 1). Write the result.
- Change
homog_2d.pyto print your H applied to the same point and compare. - Now apply it to the direction (1, 0, 0). What changes?
Stuck? Hints, one at a time
- Hint 1: H = [[0, −1, 0.1], [1, 0, 0.2], [0, 0, 1]].
- Hint 2: H·(0.05, 0, 1) = (0.1, 0.25, 1) → point (0.10, 0.25).
- Hint 3: H·(1, 0, 0) = (0, 1, 0) — directions only rotate, they don't shift.
Challenges (pick by level)
- 🟢 Easy: Write H for θ = 0°, t = (0.3, 0).
- 🟡 Medium: Compute H⁻¹ using [[Rᵀ, −Rᵀt], [0 0 1]] and check H·H⁻¹ = I.
- 🟠 Hard: Write the 4×4 3D version for a rotation about z and test it on (1, 0, 0, 1).
Next step
Next, Lesson 11: Math → Robot Connection uses H chains for real FK. Related: DH parameters and 4×4 transforms in Stage 8 — Kinematics & IK.
Sources
Self-attested for now — keep artifacts in your lab notebook.
Complete
Today's goal
0 of 1 done today
Mark this lesson complete when you have worked the experiment, knowledge check, and assignment (even roughly).