Spatial Descriptions: Frames, Rotations & Homogeneous Transforms

The mathematics of position and orientation. Learn coordinate frames, position vectors, rotation matrices (properties, elementary rotations about x, y, z), composition and inverse of rotations, Euler angles and roll–pitch–yaw (and gimbal lock), axis–angle and quaternions, homogeneous transformation matrices (4 × 4) that combine rotation and translation, chaining transforms (world → base → tool → object), inverse transforms, and frame conventions in ROS (tf) — with NumPy code composing frames, transforming points and converting a rotation to a quaternion.

Robots constantly convert between coordinate frames: where is the part in the camera frame, in the robot base frame, in the gripper frame? Homogeneous transforms are the universal tool for these conversions.

Getting frames and conventions right is the single most common source of bugs in robot programming — mastering them saves hours of debugging.

An analogy

A homogeneous transform is like giving directions relative to a landmark: 'from the station (frame A), face north-east and walk 200 m' — rotation plus translation. Chaining directions (station → market → shop) is multiplying transforms.

Frames and vectors

A frame is an origin plus three orthogonal unit axes (right-handed: x × y = z). A point's coordinates depend on the frame it's expressed in. Robots use many frames: world, base, each link, flange, tool centre point (TCP), camera, workpiece/user frames. Always write which frame a quantity is expressed in (notation ᴬp).

Rotation representations

Ways to describe orientation:

Homogeneous transforms

Adding a fourth coordinate (1) turns rotation + translation into one 4 × 4 matrix multiplication. Chaining multiplies left to right along the frame path; the inverse reverses the path. Transforms can be read two ways: as describing frame B's pose in A, or as an operator that moves points. Pure rotation matrices apply to direction vectors (w = 0), full transforms to points (w = 1).

Practical frame management

Hand–eye calibration solves AX = XB for the camera-to-flange transform; tool (TCP) calibration uses the 4-point method; user frames align programs with fixtures so moving a fixture only needs a frame update. ROS tf2 maintains a time-stamped tree of transforms. Rigid-body velocities use twists and screw theory (product of exponentials), the modern alternative to DH parameters; Lie groups SO(3)/SE(3) underpin state estimation.

Formulas

Worked example: Rotate a point

Given: P = (1, 0, 0), R_z(90°)

Find: Rotated P.

Answer: (0, 1, 0)

Worked example: Inverse transform

Given: T = R_z(90°), p = (1, 0, 0)

Find: T⁻¹ translation.

Answer: (0, 1, 0) with rotation R_z(−90°)

Worked example: Quaternion

Given: 180° about x

Find: q.

Answer: (0, 1, 0, 0)

Composing frames and converting rotations

import numpy as np
# Homogeneous transforms: rotate 90 deg about z, translate, and compose frames
def rotz(t):
    c, s = np.cos(t), np.sin(t)
    return np.array([[c, -s, 0], [s, c, 0], [0, 0, 1]])
def T(R, p):
    M = np.eye(4); M[:3, :3] = R; M[:3, 3] = p; return M
T_world_base = T(rotz(np.pi / 2), [1.0, 0.0, 0.0])      # robot base in world
T_base_tool = T(rotz(0.0), [0.5, 0.2, 0.3])            # tool in base frame
T_world_tool = T_world_base @ T_base_tool
np.set_printoptions(precision=3, suppress=True)
print("tool position in world:", T_world_tool[:3, 3])
# Inverse transform and a point expressed in two frames
p_tool = np.array([0.0, 0.0, 0.1, 1.0])                # point 10 cm along tool z
print("point in world:", (T_world_tool @ p_tool)[:3])
print("inverse check (identity):", np.allclose(np.linalg.inv(T_world_tool) @ T_world_tool, np.eye(4)))
# Rotation to axis-angle and quaternion
R = rotz(np.pi / 3)
angle = np.arccos((np.trace(R) - 1) / 2)
q = [np.cos(angle / 2), 0, 0, np.sin(angle / 2)]
print(f"rotation angle {np.degrees(angle):.1f} deg, quaternion (w,x,y,z) = {np.round(q, 4).tolist()}")
# tool position in world: [0.8 0.5 0.3]
# point in world: [0.8 0.5 0.4]
# inverse check (identity): True
# rotation angle 60.0 deg, quaternion (w,x,y,z) = [0.866, 0.0, 0.0, 0.5]

The base is rotated 90° in the world, so the tool's +x offset of 0.5 m in the base frame becomes world +y, and its +y offset becomes world −x: (1 − 0.2, 0 + 0.5, 0.3) = (0.8, 0.5, 0.3). Multiplying transforms in the right order handles this automatically. Quaternions store the same 60° rotation compactly and interpolate smoothly without gimbal lock.

Common mistakes

Applications

Key takeaways

Going further