Math for Robotics · Lesson 07
Transformations
Est. 35–45 min
Why
Why “rotate then shift” is the daily robot move
Concept
The big idea: rigid transforms (R, t)
- A rigid transform maps points without stretching: rotation + translation.
- Formula (column vectors): p_W = R · p_A + t
- R is 2×2 (planar) or 3×3 (spatial). t is the origin of {A} expressed in {W}.
- Order matters: rotate-then-translate is the usual “frame pose” story.
p_W = R(θ) · p_A + t
How it works
How it actually works, step by step
Express the point in the local frame
p_A is where the point sits relative to frame {A}.
Rotate into world orientation
Multiply by R so the local axes line up with world axes.
Shift by the frame origin
Add t — the location of {A}’s origin in world.
Inverse when you need the other way
p_A = Rᵀ (p_W − t) for a pure rotation R (R⁻¹ = Rᵀ).
Visual
Visualise it: move a frame and watch a local point
Drag the frame’s position and angle. A fixed local point’s world coordinates follow p_W = R p_A + t.
Interactive · Coordinate-frame manipulator
Point in world
(95.0, 77.7)
p_world = origin + R(θ) · p_local
Worked example
Worked example: θ=30°, t=(0.5, 0.1) m
Code lab
Code lab: apply R and t
"""Stage 1 L07 — rigid transform: rotate then translate a point."""
import math
theta = math.radians(30)
c, s = math.cos(theta), math.sin(theta)
# Point in frame {A}
px_a, py_a = 0.20, 0.05 # metres
# Origin of {A} in world, and rotation of {A} relative to world
tx, ty = 0.50, 0.10
px_w = c * px_a - s * py_a + tx
py_w = s * px_a + c * py_a + ty
print(f"θ = 30°, t = ({tx}, {ty}) m")
print(f"p in {{A}} = ({px_a}, {py_a}) m")
print(f"p in world = ({px_w:.4f}, {py_w:.4f}) m")
print("Formula: p_W = R(θ)·p_A + t")Expected output
θ = 30°, t = (0.5, 0.1) m
p in {A} = (0.2, 0.05) m
p in world = (0.6482, 0.2433) m
Formula: p_W = R(θ)·p_A + tReal world
Tool offsets and camera extrinsics
- Tool offset from flange to gripper tips
- Camera extrinsics relative to the robot base
- Moving a part from a conveyor frame into the arm base frame
Mistakes
Common mistakes and confusions
Hardware & safety
Hardware lab and safety notes
Use a mug and your graph-paper desk. Put a dot sticker on the mug handle: that point never moves in {mug}, but its {table} coordinates change every time you turn or slide the mug.
- Mark the mug centre as the origin of {mug}; +x points to the handle.
- Measure the sticker in {mug} (e.g. 6 cm along x).
- Turn the mug 30° and slide it to (20, 10) cm. Predict the sticker in {table}, then measure it.
Debugging
Debugging: when it doesn’t work
| Symptom | Likely cause | Fix |
|---|---|---|
| Result is off by the translation rotated | Added t before rotating | p_W = R·p_A + t — rotate first |
| Sticker lands mirrored | Used R(−θ) or swapped sin signs | R(θ) = [[c, −s], [s, c]] for anticlockwise θ |
| Inverse gives nonsense | Used −R instead of Rᵀ | p_A = Rᵀ·(p_W − t) |
| Numbers 1000× off | t in mm, p in m | Same unit for R·p and t |
Think
Think about it
Think
If R is identity, what does the transform reduce to?
Experiment
Try it in the lab: move the frame
Experiment
Move the frame
You will need
- coordinate-frame interactive
- Notebook
Steps
- Note a local point’s world coordinates at θ=0, t=(0,0).
- Translate the frame; confirm world point shifts by the same amount.
- Rotate only; confirm distance from frame origin stays constant.
Interactive · Coordinate-frame manipulator
Point in world
(95.0, 77.7)
p_world = origin + R(θ) · p_local
Rigid motion preserves distance from the frame origin to the local point.
Knowledge check
Check your understanding
Knowledge check
1. Rigid transform preserves…
2. p_W = R p_A + t means…
3. For a rotation matrix, R⁻¹ equals…
4. t represents…
Practice quiz
Mini assignment
Hands-on assignment
Mini assignment
Transform story
Write a 8–12 line story of a point on a mug: express it in {mug}, then in {table} after you rotate and slide the mug. Include numbers.
Deliverables
- Story with numbers
- One sketch
Do this, step by step
- Measure the sticker in {mug}: p_A = (6, 0) cm.
- Turn the mug 30° anticlockwise and slide its centre to t = (20, 10) cm. Predict p_W by hand.
- Measure the real sticker position in {table}. Note the error.
- Change
transform_2d.pyto your numbers and confirm.
Stuck? Hints, one at a time
- Hint 1: R·p_A = (6·cos30°, 6·sin30°) = (5.20, 3.00) cm.
- Hint 2: p_W = (5.20 + 20, 3.00 + 10) = (25.20, 13.00) cm.
- Hint 3: A 3–5 mm error is fine — your mug centre is only an estimate.
Challenges (pick by level)
- 🟢 Easy: Same mug, θ = 0°, t = (20, 10). Where is the sticker?
- 🟡 Medium: Use the inverse to go back from p_W = (25.20, 13.00) to p_A.
- 🟠 Hard: Write
apply(theta_deg, t, p)andinvert(theta_deg, t)and test that invert(apply(p)) = p for 10 random points.
Next step
Next, Lesson 8: Frames & Reference Frames chains many such transforms. Related: camera-to-world transforms in Stage 11 — Computer Vision.
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).