[Intermediate] — Rotations, homogeneous transforms, and the frame bookkeeping that causes more robotics bugs than any algorithm.
Why this comes first
Everything downstream is transforms. Forward kinematics is a chain of them. Inverse kinematics inverts one. SLAM estimates them. The camera sees in its frame and the gripper acts in another.
Get the frame conventions right once and most of the maths follows. Get them wrong and the robot moves smoothly, confidently, in the wrong direction — which is the hardest kind of bug, because nothing crashes.
Frames
A frame is a coordinate system attached to something: the world, the robot base, each link, the tool, the camera, the map.
The notation that saves you, and it’s worth adopting rigidly:
And then the subscripts cancel like units:
Adjacent indices must match. If they don’t, you’ve composed backwards. This one convention catches most transform errors before you run anything, and it’s the reason to write the sub/superscripts even when it feels fussy.
Read two ways — both are correct and the ambiguity is a real source of confusion:
- It converts coordinates from into
- It describes the pose of frame as seen from
Rotations
Rotation matrices
A 3×3 matrix whose columns are the axes of the rotated frame expressed in the original:
It’s a member of — orthonormal with determinant :
That last identity is the useful one. Inverting a rotation is a transpose — free, and numerically exact. No matrix inversion anywhere in your kinematics.
The elementary rotations:
with and analogous.
Nine numbers for three degrees of freedom — heavily redundant, which is both a weakness (storage, and numerical drift off the manifold) and a strength (no singularities, and composition is a plain matrix multiply).
Renormalise periodically. Multiply enough rotation matrices in floating point and drifts away from . Re-orthogonalise (Gram–Schmidt or SVD) in anything long-running.
Euler angles
Three sequential rotations — roll, pitch, yaw. Intuitive, compact, and the source of a genuine trap.
The order matters, and there are 12 valid conventions. ZYX (yaw-pitch-roll) is standard in aerospace and robotics, but “roll pitch yaw” alone doesn’t specify it. Rotations do not commute — rotate 90° about then and you get somewhere different than then . Try it with a book.
And then gimbal lock:
At pitch = ±90°, the first and third axes align. You lose a degree of freedom — two of your three parameters now do the same thing, and the representation is singular. Nearby, the angles change violently for small motions.
That’s not a bug in a particular convention. Every three-parameter representation of 3D rotation has a singularity somewhere — it’s a topological fact, and it’s the reason Apollo 11’s IMU had a physical gimbal-lock warning.
Use Euler angles for display and human input. Do not use them in your state representation.
Quaternions
Four numbers, , unit norm.
for a rotation of about axis .
Why they win:
- No singularities. No gimbal lock, anywhere
- Compact — 4 numbers, and renormalising is one division
- Composition is cheap — quaternion multiplication, fewer operations than a matrix multiply
- Interpolation works — SLERP gives constant-rate rotation along the shortest path. Interpolating Euler angles gives visible wobble, and interpolating rotation matrices element-wise gives something that isn’t a rotation at all
What bites:
- Not intuitive. You cannot read a quaternion and picture the orientation
- Double cover: and are the same rotation. Handle it explicitly, especially when comparing orientations or computing an error — the shortest path may require flipping the sign
- Convention split: vs . Eigen uses one, ROS uses the other. Check, every time — this is a real and common bug
- Renormalise after accumulating
The practical rule for the whole section:
| Use | For |
|---|---|
| Quaternions | storing and propagating orientation |
| Rotation matrices | transforming vectors, composing chains |
| Euler angles | display, config files, human input |
| Axis-angle | rotation errors and control (it’s a natural “how far off am I”) |
Homogeneous transforms
Rotation and translation in one 4×4 matrix:
Points get a 1 appended: .
The point of the fourth row is that it makes rotation-then-translation a single matrix multiply, so composing a chain of joints is just multiplying matrices. Without it you’d carry and separately and write out by hand at every link.
The inverse has a closed form — never call a general 4×4 inverse:
Note the . Negating the translation alone is wrong, and it’s a classic error. The intuition: to undo “rotate then translate”, you undo the translation in the rotated frame.
Vectors vs points. A point has and is affected by translation. A direction has and is not — which is correct, because rotating a velocity or a surface normal should not move it. The homogeneous form handles this automatically, which is a large part of why it’s used.
Transform trees
A real robot has many frames, and they form a tree:
world
│
map
│
odom
│
base_link
╱ │ ╲
link1 laser camera
│
link2
│
tool0
Every edge is a transform. Some are fixed (camera bolted to the base), some change every cycle (joint angles), some are estimated (map → odom, from SLAM).
The transform between any two frames is the product along the path, inverting where you travel against an edge. Finding camera → tool0 means going up to base_link and back down.
This is exactly what ROS’s tf2 does, and it does one more important thing: it buffers transforms with timestamps, so you can ask “where was the camera relative to the gripper at the moment that image was captured”. Because sensors have latency and the robot moved in the meantime, using the current transform for an old measurement is wrong — and this is a subtle, real, and very common source of error. → ROS and Robot Software
Conventions to pin down
Agree these on day one and write them in the README. Every one of them has bitten someone.
Axis convention. ROS uses x forward, y left, z up (right-handed) for robot bodies, and z forward, x right, y down for optical camera frames. Those are different, deliberately, and mixing them is a rite of passage.
Handedness. Right-handed nearly everywhere in robotics; some graphics and CAD tools are left-handed.
Units. Metres and radians, always, internally. Convert at the boundary — display, config, user input. Degrees creeping into the maths is a recurring bug, and it’s silent because the numbers look plausible.
Angle wrapping. Is your angle in or ? Angular error must wrap — the error between 179° and −179° is 2°, not 358°. A controller that doesn’t wrap will command a full rotation the wrong way around, dramatically. Use atan2(sin(e), cos(e)) and stop thinking about it.
Quaternion ordering. or . Stated above; stated again because it keeps happening.
Debugging transforms
The practical checklist, since this is where the time goes:
Visualise. RViz, or draw the axes. A frame in the wrong place is obvious visually and invisible numerically. This alone is worth setting up early.
Check the identity cases. Zero joint angles should put the tool somewhere you can predict by looking at the robot.
Check determinants and norms. and . A determinant of means you’ve mirrored something — usually a flipped axis convention.
Move one joint at a time and confirm the tool frame moves the way it physically does. This finds sign errors immediately.
Read the subscripts. is meaningless — . Most composition bugs are visible in the notation before they’re visible in the robot.
Related
- Forward Kinematics — chaining these into a robot
- Jacobians — the derivative of this chain
- Linear Algebra — matrices and orthogonality
- Robotics map
Software engineering
Infrastructure & security
Computer science
Hardware & engineering