Coordinate Frames, Transforms, and Homogeneous Matrices
What You'll Learn
- 1Attach a right-handed coordinate frame to every body and read a rotation matrix as projected axis directions
- 2Assemble a 4x4 homogeneous transform from a rotation and a translation
- 3Compose a chain of frames by matrix multiplication in the correct order
- 4Invert a pose with the transpose rule and verify it with a round trip
Every joint encoder, camera pixel, and gripper command is meaningless until you say which frame it is expressed in: 400 mm in the base frame and 400 mm in the camera frame may point at two different bolts. The transform between frames is the arithmetic that makes coordinates comparable. This lesson builds rotation matrices from the right-hand rule, packs them into homogeneous 4x4 transforms, and works a frame chain with numbers you can multiply by hand.
Theory and Foundations
A coordinate frame is an origin plus three mutually perpendicular unit axes x, y, z obeying the right-hand rule: curl the fingers from x toward y and the thumb points along z. A rigid body carries its own frame, and a transform answers one question: given a point in frame B, what are its coordinates in frame A?
For a rotation of angle about the z axis only the x and y rows change, giving the building block used everywhere in robotics.
Rotations about the other axes follow the same cyclic pattern, and all three satisfy with , which is why the transpose is the inverse.
A rotation alone cannot move a point between two origins, so robotics packs rotation and translation into one 4x4 block called a homogeneous transform.
The upper left 3x3 block rotates, the upper right column translates, and the bottom row stays fixed at zeros with a final one. Appending a one to a point gives the homogeneous column the block expects.
Transforms compose in the order they are applied, so the A to C chain multiplies A to B on the left of B to C, and any nested chain runs left to right.
Inversion has a closed form that avoids a general 4x4 solver, because a rotation inverts by transpose and the translation compensates for that rotation.
The product of a transform and its inverse returns the identity, since and . These same blocks are the raw material of the Denavit-Hartenberg table, where each joint contributes one transform built from its own four parameters.
Key Formulas
Worked Examples
| Frame pair | Typical transform | Example value | Where it is used |
|---|---|---|---|
| base to tool flange | revolute about z plus reach | 0.90 m extension | joint encoder reading |
| flange to gripper | fixed offset along tool axis | 0.18 m | ISO 9409 tool adapter |
| base to world | fixed mount correction | 0.05 m, 0.2 deg | cell calibration |
| camera to base | hand-eye result, 4x4 | 0.001 m residual | bin picking |
Real-World Examples
- Hand-eye calibration - Solving the camera-to-hand equation typically leaves a 0.1 to 0.3 mm residual, the floor for grasp accuracy.
- ROS 2 tf2 tree - Frames such as base_link, odom, and tool0 are republished continuously with a 10 s cache that drops stale transforms.
- Tool center point offsets - A 0.18 m gripper offset rotated through a 90 deg wrist error moves the tip by 0.18 m, so TCP calibration is checked each shift.
- ISO 9409-1 flanges - The 50 mm adapter pattern fixes the tool frame origin at the flange face, so one transform covers every tool on a changer.
đĄMultiply in application order
Composing Poses With a Transform Library
Hand multiplication is how you learn the order; a library is how you ship it, and the rules stay identical. Build the rotation and the translation separately, multiply in application order, and let the translation column fall out of the product instead of adding offsets componentwise. A round trip through the inverse is the cheapest regression test available, because a reversed product shows up as a constant positional error on the order of a link length rather than as noise that calibration could absorb.
import numpy as np
def rot_z(deg):
t = np.radians(deg)
return np.array([[np.cos(t), -np.sin(t), 0.0],
[np.sin(t), np.cos(t), 0.0],
[0.0, 0.0, 1.0]])
def make_T(R, p):
T = np.eye(4)
T[:3, :3] = R
T[:3, 3] = p
return T
T_AB = make_T(rot_z(90), np.array([1.0, 0.0, 0.0]))
T_BC = make_T(rot_z(90), np.array([0.5, 0.0, 0.0]))
T_AC = T_AB @ T_BC
p_A = T_AC @ np.array([1.0, 0.0, 0.0, 1.0])
print(np.round(p_A[:3], 3)) # [0. 0.5 0. ]
print(np.allclose(T_AC @ np.linalg.inv(T_AC), np.eye(4))) # True
Publishing the Frame Chain With tf2
A controller never asks a matrix for a pose at runtime; it asks a transform buffer, and the buffer only answers when the frames are connected and the data is fresh. Republishing a static mount transform at 100 Hz costs almost nothing and keeps the cache ahead of the ten-second expiry, while a lookup that raises usually means a frame was never broadcast rather than that the arithmetic is wrong. Frame names carry the same weight as the numbers: base_link, odom, and tool0 form one tree, and a child that is given a second parent is rejected outright.
import rclpy
from rclpy.node import Node
from geometry_msgs.msg import TransformStamped
from tf2_ros import TransformBroadcaster
class FlangeFrame(Node):
def __init__(self):
super().__init__('flange_tf')
self.send = TransformBroadcaster(self)
self.timer = self.create_timer(0.01, self.tick)
def tick(self):
msg = TransformStamped()
msg.header.stamp = self.get_clock().now().to_msg()
msg.header.frame_id = 'base_link'
msg.child_frame_id = 'tool0'
msg.transform.translation.x = 0.90
msg.transform.rotation.w = 1.0
self.send.sendTransform(msg)
rclpy.init()
rclpy.spin(FlangeFrame())
Common Mistakes
Multiplying the chain in the wrong order
Fix: Write frames as superscript-subscript pairs and cancel adjacent labels: A T B times B T C leaves A T C.
Rotating the translation instead of the rotation
Fix: The composed translation is R left times p right plus p left, so rotate only the second translation.
Inverting a pose element by element
Fix: Use R transpose for the rotation and minus R transpose times p for the offset; a general 4x4 inverse wastes cycles.
Key Takeaways
- A rotation matrix stores projected axis directions and satisfies R transpose times R equals identity with determinant one.
- A 4x4 transform packs a 3x3 rotation, a 3x1 translation, and a fixed bottom row 0 0 0 1.
- Chains multiply left to right: A T C equals A T B times B T C, so 90 deg twice gives 180 deg.
- The inverse is a transpose and minus R transpose times p, verified by the round trip through both frames.
Frequently Asked Questions
Why does the inverse of a transform use a transpose?
Because a rotation matrix is orthonormal, its columns are unit vectors at right angles, so and the inverse equals the transpose. The translation is then rotated back as , since the offset was expressed in the original frame.
Do I need a 4x4 matrix if nothing rotates?
Yes, and the cost is small. One uniform block lets the same multiply routine handle fixed offsets, joint rotations, and camera extrinsics without branching on identity blocks.
What breaks if I mix up two frames?
Every point inherits a rigid error: a rotation error grows with distance from the origin, so 1 deg at 1 m of reach already produces 17 mm of offset.
Interview Questions
Q1: Where does the point 1, 0, 0 go under a 90 deg z rotation with translation 0.2, 0.1, 0?
The rotation maps 1, 0, 0 to 0, 1, 0, then the offset adds 0.2 and 0.1, giving 0.2, 1.1, 0 in the target frame.
Q2: How do you invert a pose in firmware?
Transpose the 3x3 block, compute minus R transpose times p with three dot products, and keep the bottom row 0 0 0 1; no general solver is needed.