Coordinate frames and homogeneous transforms
Combine rotation and translation into one 3 × 3 matrix, chain transforms from world to base to tool, invert them, and rebuild the two-link arm as a chain of frames.
Lesson 4 of 6 · 40 min · Self-paced · Free
Many frames, one robot
A real robot cell is full of coordinate frames. The world frame is fixed to the room or table. The base frame sits at the bottom of the arm. Each link has a frame that moves with it. The tool frame is at the gripper's fingertips, and a camera frame sits at the camera's lens. Every measurement arrives in some frame: the camera reports where it sees the cup, the joint encoders describe the arm relative to its base, and the task ("put the cup at the corner of the table") is stated in the world frame.
To act, the robot must convert positions between frames quickly and without mistakes. The last lesson handled frames that are rotated relative to each other. Real frames are also shifted. This lesson combines both into a single tool, the homogeneous transform, and uses it to chain frames together.
Rotation plus translation
Suppose frame B is rotated by θ relative to frame A, and B's origin sits at position t = (tx, ty) in A. A point whose coordinates in B are p_B has coordinates in A of:
p_A = R(θ) · p_B + tRead it as: first rotate the point from B's directions into A's directions, then shift it by where B's origin sits in A.
That works, but chaining several of these by hand gets messy: rotate, add, rotate, add, and the bookkeeping piles up. There is a trick that turns the whole thing into a single multiplication.
The homogeneous trick
Add a third coordinate, always equal to 1, to every point: (x, y) becomes (x, y, 1). Then build a 3 × 3 matrix with the rotation in the top-left corner and the translation in the right-hand column:
T = [ cos θ −sin θ tx ]
[ sin θ cos θ ty ]
[ 0 0 1 ]Multiply it by (x, y, 1) using the row-times-column rule, and the first two rows give
x_A = cos θ · x − sin θ · y + tx · 1
y_A = sin θ · x + cos θ · y + ty · 1which is exactly rotate-then-shift. The bottom row just keeps the 1 in place. This 3 × 3 matrix is a homogeneous transform, and the extra coordinate is called a homogeneous coordinate. The payoff: combining frames is now nothing but matrix multiplication.
Naming and chaining
A clear naming habit prevents most errors. Write T_A_B for the transform that takes coordinates in frame B and gives coordinates in frame A. You can read it as "B as seen from A". Then frames chain like dominoes:
T_world_tool = T_world_base · T_base_toolThe inner names match (base next to base) and "cancel", leaving world and tool on the outside. If the inner names do not match, the multiplication is a mistake.
Worked example: the two-link arm as a chain
Go deeper: work through it step by stepabout 2 min
Recall the arm from the two-link lesson: L₁ = 10 cm, L₂ = 8 cm, θ₁ = 30°, θ₂ = 45°. Using the transforms "Rot(θ)" (rotate only) and "Trans(d)" (shift d along the current x-axis), the hand frame is:
T_base_hand = Rot(θ₁) · Trans(L₁) · Rot(θ₂) · Trans(L₂)Read it left to right as instructions to an ant standing at the base: turn by θ₁, walk L₁ along your nose, turn by θ₂, walk L₂. Where the ant ends up is the hand, and the way it faces is the forearm's direction.
Suppose, too, that the gripper's fingertips are 3 cm beyond the end of link 2: add one more Trans(3 cm) to get the tool frame. And suppose the arm is bolted to a table with its base at world position (50, 20) cm, rotated 90° (so the arm's "straight ahead" points along the world's y-axis). Here is the whole chain in Python with the standard library:
import math
def transform(theta_deg, tx, ty):
"""3x3 homogeneous transform: rotate by theta, then shift by (tx, ty)."""
c, s = math.cos(math.radians(theta_deg)), math.sin(math.radians(theta_deg))
return [[c, -s, tx], [s, c, ty], [0.0, 0.0, 1.0]]
def matmul(A, B):
return [[sum(A[i][k] * B[k][j] for k in range(3)) for j in range(3)] for i in range(3)]
def chain(*Ts):
result = transform(0, 0, 0) # identity
for T in Ts:
result = matmul(result, T)
return result
L1, L2, tool = 10, 8, 3
T_base_hand = chain(transform(30, 0, 0), transform(0, L1, 0),
transform(45, 0, 0), transform(0, L2, 0))
T_base_tool = matmul(T_base_hand, transform(0, tool, 0))
T_world_base = transform(90, 50, 20)
T_world_tool = matmul(T_world_base, T_base_tool)
for name, T in [("hand in base", T_base_hand), ("tool in base", T_base_tool),
("tool in world", T_world_tool)]:
heading = math.degrees(math.atan2(T[1][0], T[0][0]))
print(f"{name:13s}: ({T[0][2]:6.2f}, {T[1][2]:6.2f}) cm, facing {heading:5.1f} deg")hand in base : ( 10.73, 12.73) cm, facing 75.0 deg
tool in base : ( 11.51, 15.63) cm, facing 75.0 deg
tool in world: ( 34.37, 31.51) cm, facing 165.0 degThe first line matches the two-link lesson's answer of (10.73, 12.73), as it must. The position of any frame is the right-hand column of its transform, and its facing direction comes from the first column, via atan2. In the world, the tool faces 75° + 90° = 165°, because the base itself is turned 90°.
Check the last line by hand. Rotating (11.51, 15.63) by 90° gives (−15.63, 11.51); adding the base position (50, 20) gives (34.37, 31.51). It agrees.
Order matters
Even in 2D, transforms that include translation do not commute. Compare two instructions to the ant, starting at the origin facing along x:
- Rot(90°) then Trans(10): turn left, then walk 10. The ant ends at (0, 10).
- Trans(10) then Rot(90°): walk 10, then turn left. The ant ends at (10, 0), merely facing a new way.
Same pieces, different results. Pure rotations about one point commuted in the last lesson; once frames are shifted, order is everything. Writing the chain as a sentence ("turn, walk, turn, walk") is a reliable way to get the order right.
Going backwards: the inverse transform
Often you need the opposite direction. A camera fixed above the table reports a cup at world position (38, 32) cm. Where is that in the arm's base frame, so the arm can reach for it? You need T_base_world, the inverse of T_world_base.
Undoing "rotate then shift" means "unshift, then unrotate". Because the inverse of a rotation is its transpose, the inverse transform is:
T_B_A = [ Rᵀ −Rᵀ · t ]
[ 0 0 1 ]For our base (rotated 90°, at (50, 20)), take it in two steps:
unshift: (38, 32) − (50, 20) = (−12, 12)
unrotate: apply R(−90°): (x, y) → (y, −x) gives (12, 12)So the cup is at (12, 12) cm in the base frame. Now the inverse kinematics from the two-link lesson can take over: r² = 12² + 12² = 288, so cos θ₂ = (288 − 100 − 64) / 160 = 0.775 and θ₂ ≈ ±39.19°. A reachable target, with two possible arm shapes.
A quick check is always available: multiply T_world_base by T_base_world and you should get the identity matrix, the transform that changes nothing (ones on the diagonal, zeros elsewhere).
The full pipeline
This example contains the shape of a real pick-up task:
- The camera measures the cup in the camera frame.
- A known transform, found by calibration, converts that to the world or base frame.
- Inverse kinematics finds joint angles that put the tool frame at the cup.
- Forward kinematics, as a chain of transforms, confirms where the tool will really be.
If any transform in the chain is wrong, for instance because the camera was bumped and its calibration is stale, the robot reaches confidently to the wrong place. Many "the robot missed" problems turn out to be a frame error, not a control error.
Knowledge check
Check your understanding
Go further
- Wikipedia — Transformation matrix ↗
Rotation, translation and their combination using homogeneous coordinates, including the 3D 4 × 4 form.
- MIT OpenCourseWare — 2.12 Introduction to Robotics ↗
University lecture notes that build robot kinematics from chains of homogeneous transforms.
Lesson materials · free to download
Sign in to track your progress. Reading is free without an account.