Stage 01 · Lesson 10/12

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

  1. Build R and t

    Same as the previous lesson.

  2. Pack into H

    Place R in the upper-left, t in the last column (except bottom), bottom row zeros then 1.

  3. Multiply Hs to compose

    H_world_tool = H_world_base · H_base_tool.

  4. 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

homog_2d.py · Python
"""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
SymptomLikely causeFix
Translation ignoredPoint 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 HRebuild: [[R, t], [0 0 1]]
Tip off by a full linkMultiplied H2·H1 instead of H1·H2Parent first: base→link1 then link1→link2
Direction vector moved when it shouldn'tUsed 1 instead of 0 for a directionDirections use 0 so translation is skipped
NoteChange one thing at a time. Most Stage 1 bugs are units (degrees vs radians, mm vs m), order of multiplication, or a frame that was never named.

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

  1. Copy one printed H1 matrix.
  2. Circle the 2×2 R block and the t column.
  3. 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

Loading 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

  1. Hand-write H for θ = 90°, t = (0.1, 0.2).
  2. Apply it to (0.05, 0, 1). Write the result.
  3. Change homog_2d.py to print your H applied to the same point and compare.
  4. Now apply it to the direction (1, 0, 0). What changes?

Stuck? Hints, one at a time

NoteTry the task first. Read one hint, try again, and only then read the next one.
  1. Hint 1: H = [[0, −1, 0.1], [1, 0, 0.2], [0, 0, 1]].
  2. Hint 2: H·(0.05, 0, 1) = (0.1, 0.25, 1) → point (0.10, 0.25).
  3. 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

0-day streak
Daily goal:lessons, quizzes or assignments a day

Mark this lesson complete when you have worked the experiment, knowledge check, and assignment (even roughly).

Stuck somewhere?

Ask a doubt about this lesson

Saved with this lesson's id and your email so we can reply. Privacy · or email contact@aihubstation.in