RobotGuide

Math foundations · topic A1 · 40 hours

Linear algebra & rigid-body rotation

Every coordinate transform a robot performs is matrix arithmetic. Quaternions, rotation matrices, and Lie groups are the shared language of everything downstream — kinematics, calibration, optimization. Skip this and the rest of the stack stays a black box.

Foundations stage · Intermediate
Algorithm · Proficient System software · Hands-on Embedded & controls · Aware Mechanical · Hands-on

What to learn

The lesson · plain words

In plain words: every part on a robot, every millisecond, is answering the same question — «where am I, and which way am I facing?» The math that answers those two questions is this entire page. It is not hard; it only has many symbols. This page turns every symbol back into words.

You learned in school that a point on a line takes 1 number, on a plane 2, in space 3. Robotics adds exactly one new trouble: 3 numbers say «where» but not «facing» — standing in the same spot, pointing at the ceiling and pointing at the door are completely different poses. Orientation takes another 3 numbers. Six numbers together; roboticists call the package a «pose». Everything on this page is about how to store and compute these 6 numbers properly.

Rotation matrices: a lookup table of coordinates

Rotation matrices sound intimidating; they are really a three-column lookup table: where the x, y, z axes of the new frame point inside the old frame. Copy the three columns down and you have the 3×3 matrix. There is no further mystery.

Two practical payoffs: transforming any point is a single matrix multiply (9 multiply-adds, microseconds); and a rotation matrix never breaks — no angle fails to compute. The cost: of the 9 numbers only 3 are free; the other 6 are trailing constraints. In the figure below, drag the point on the circle and watch the matrix entries follow live — a matrix is not a table, it is the ledger of a rotation.

Interactive figure · drag it and see

What this figure shows: drag the point on the unit circle and the rotation-matrix entries update in real time. Takeaway: a rotation matrix is just the new frame's axes written in old-frame coordinates — columns of unit length, mutually perpendicular, which is exactly where the 6 redundant numbers go.

Quaternions: 4 numbers doing the job of 9

Quaternions are not mysticism; they are the 3D upgrade of «complex multiplication = rotation» (the complex-number version is the figure below): 4 numbers encoding «around which axis, by how many degrees». They save memory, interpolate smoothly, and multiply faster than matrices; the cost is that humans cannot read them. The engineering convention in one sentence: store and transmit quaternions; convert to Euler angles only when a human has to look.

One trap you must know: q and −q encode the same rotation (the double cover). To test whether two quaternions «point the same way», check the sign of their dot product first — which is why every quaternion interpolation routine checks signs before blending.

Interactive figure · drag it and see

What this figure shows: on the left, complex multiplication adds angles — 45° + 30° in one multiply; on the right, the 3D version, a quaternion rotation written as q·v·q*. Takeaway: quaternion multiplication composes rotations the same way complex multiplication does, which is how 4 numbers can encode any 3D rotation and interpolate through it smoothly.

Gimbal lock: why Euler angles «twitch»

Euler angles mean rotating about three axes in turn (say yaw about z, then pitch about the new y, then roll about the new x). The three axes behave like the three rings of a gimbal: when the middle ring reaches 90°, the outer and inner rings point along the same direction — three degrees of freedom collapse into two. At that instant the program «does not know which axis to move», the pose flips near the singularity, and to the eye it looks like «the motor twitched».

Remember the conclusion: Euler angles are for humans, not for computation — above all, never interpolate or integrate in them.

RepresentationNumbersStrengthFatal flawUsed for
Rotation matrix9Intuitive, never singular6 redundant numbersDerivation, textbooks
Quaternion4Smooth interpolation, fastUnreadable, ±q doubleStorage, transport, state
Euler angles3Humans read themGimbal lockUI display, logs
Rotation vector3Cheapest, no singularityCannot compose directlyOptimization variables, Lie algebra

Interactive figure · drag it and see

What this figure shows: a three-ring gimbal; push pitch toward 90° with the slider and watch the outer and inner rings merge into one hinge. Takeaway: at pitch ±90°, yaw and roll become the same rotation — the singular instant where three numbers carry only two degrees of freedom.

The coordinate chain: a robot's world is a metro transfer

The camera reports «the cup is at (0.2, 0.1, 0.8) in my frame»; the arm needs «where is the cup in the base frame». Two transfers in between: the camera is bolted to the arm tip (one fixed rotation + translation), and the tip sits in the base frame through another rotation + translation. The homogeneous transform (SE(3)) packs each rotation + translation into one 4×4 matrix, multiplied down the chain — like riding a metro: at each stop you only need «which way is the next stop from here».

A detail people get wrong for a lifetime: transforming a point adds the translation (a point has a position); transforming a direction vector does not (a direction has only an orientation). Same matrix — the difference is whether the trailing coordinate is 1 or 0.

Interactive figure · drag it and see

What this figure shows: one fixed point tracked simultaneously in three frames — base, tip, camera — while the two 4×4 matrices convert between the ledgers. Takeaway: every sensor lives in its own frame; the robot's shared reality is the bookkeeping that converts between them.

Computing backwards: from base coordinates back to tip coordinates

The previous figure ran forward: tip-frame coordinates, one rotation and one translation, base-frame coordinates. Half of real engineering runs the other way — a sensor sees the target in base coordinates and asks «where should the tip go». So you must also compute backwards.

Backwards is not «divide». The inverse of a rotation is its transpose: swap rows and columns; pull off the translation first, then rotate: p_t = Rᵀ(p_b − t). Why do the order and the sign both flip? Forward is «rotate, then translate»; backwards must «translate back, then rotate back».

Watch the figure: the point never moves, only the ledger does. It flips direction by itself every few seconds; use the button to flip it by hand. Note the numbers inside Rᵀ are the same as in R, rows and columns swapped — which is why inverting a transform in robotics costs almost nothing.

Interactive figure · drag it and see

What this figure shows: one point computed forward (tip → base) and backward (base → tip) using p_b = R·p_t + t and p_t = Rᵀ(p_b − t). Takeaway: the inverse of a rigid transform is transpose-plus-subtract — no matrix inversion anywhere, which is why tf lookups are effectively free.

Three sentences to take away

① A rotation matrix is a coordinate lookup table; ② a quaternion is a 4-number rotation — store poses with it; ③ Euler angles are for display — keep them out of the math. Get these three and you are ahead of many people who «have used tf but cannot say why». Full proofs and hand computations wait in the derivation layer.

Three questions — do you really get it?

1. The decisive engineering reason to store orientation in quaternions rather than Euler angles is?

  • AIt saves memory
  • BInherently higher precision
  • CNo gimbal lock, smooth interpolation
Show answer

C. Memory is a side benefit; the core issue is that Euler angles have gimbal lock and interpolation flips near the singular pose. Quaternion interpolation (slerp) is smooth end to end.

2. Applying the same homogeneous transform to a point versus to a direction vector differs how?

  • AA point gets a trailing 1 (receives translation), a vector gets 0 (does not)
  • BNo difference
  • CA vector must be normalized, a point must not
Show answer

A. Translation means something for position and nothing for direction — the trailing 1 or 0 decides whether the translation column is added.

3. Geometrically, the three column vectors of a rotation matrix are?

  • AWhere the new frame's three axes point in the old frame
  • BThree eigenvalues
  • CThe rotation axis and angle
Show answer

A. Hence each column has unit length and the columns are mutually perpendicular — those 6 constraints are the 6 redundant numbers.

Keep going deeper

Links without a marker stay on this site; the rest point to the Chinese edition until its translation batch lands.

How it fails in the field

You have learned enough when

You can hand-derive the conversion between a rotation matrix and a quaternion, explain why Euler angles cannot be interpolated (gimbal lock), and write down the composition and the inverse of an SE(3) transform.

The Chinese edition carries the full topic page for Linear algebra & rigid-body rotation, including the complete outline, depth requirements per career track, and further derivations: robotguide.dev/k/A1/.