A7 · Lesson 49 · Rotations, reflections and coordinate frames
Orthogonal matrices at work, from a phone's accelerometer to a radio's constellation
A phone's accelerometer measures along the phone's own axes. To know which way is down in the room, the reading has to be turned into the room's coordinates. A robot arm chains a rotation and a shift for every joint, and a radio receiver turns its whole constellation back by the carrier's phase error. All of these are orthogonal matrices (lesson 24): matrices whose columns are perpendicular unit vectors, so they move vectors without stretching them. In three dimensions they also have a habit that 2D rotations don't: the order you apply them in matters.
- The first arrow is a vector ; the second is rotated by the angle \mathbf{x}.
- All three keep the same length. Turning the rotation through a full circle brings it back; moving the mirror swings the reflection twice as fast, because a reflection doubles the angle between the vector and the mirror.
Predict
Rotate the vector by 90° about the axis, then 90° about the axis. Now do it in the other order. Do you land in the same place?
No. About first, lies on the axis and doesn't move; then 90° about takes it to . About first takes it to ; then 90° about turns that to . In matrix terms : 3D rotations don't commute, which is why orientation is specified with an agreed order of axes.
Name it
Orthogonal matrices
is orthogonal when . Then:
- , so undoing it costs nothing;
- and angles are kept;
- : for a rotation, for a reflection.
Rotations
In the plane, turns vectors counterclockwise by . In space, the rotations about the coordinate axes are
with , . A product applies first. Every 3D rotation turns about some axis by some angle , and its trace gives the angle: .
Reflections
The Householder reflection across the plane perpendicular to a unit vector is
It sends to and leaves every vector perpendicular to alone. is symmetric and orthogonal, so . Choosing along reflects onto the first axis, the step that QR factorization (lesson 28) repeats column by column in numerical libraries.
Coordinate frames
A sensor mounted on a robot is rotated by and shifted by from the robot's frame, so a point it measures sits at . Stacking both into one homogeneous matrix makes the shift a matrix product too:
A chain of joints is a product of such matrices, read right to left from the tool back to the base.
Worked example
A phone lies rolled 30° about its own axis. Its accelerometer reads m/s² in the phone's axes. What is that in the room's axes, where the phone's frame is relative to the room?
Show the solution
- Multiply by . The first entry stays 0, and the second is
- Third entry.
- Read the result. Straight down at 9.81 m/s²: gravity, as it should be for a phone at rest.
- Going the other way. From the room to the phone uses , the inverse for free. This is the first step of every orientation filter.
Answer m/s² in the room's axes: gravity, straight down.
Worked example
Find the Householder reflection that sends onto the first axis.
Show the solution
- Aim for the axis. , so aim for : which normalizes to .
- Build .
- Check. a reflection.
- The mirror. It's the line through the origin halfway between and , so lands on the axis with its length unchanged.
Answer .
Worked example
A rotation is . By what single angle does it turn space, about its own axis?
Show the solution
- Diagonal of . Multiplying out, the diagonal is , and : 0.766, 0.694 and 0.906, so
- Angle from the trace. gives and .
- Compare. Two turns of 40° and 25° about different axes add up to one turn of 46.9°, less than their sum because the axes aren't the same.
Answer it turns space by 46.9° about its own axis.
Check
Rotate the vector counterclockwise by 120°. What is the new component?
Check
A 3D rotation matrix has trace 2.5. Through what angle does it rotate?
Check
Write Rx(t), Ry(t) and Rz(t) returning the 3D rotation matrices for an angle in degrees. Set R = Rz(a) @ Ry(b) @ Rx(c) with a = 35, b = 20, c = 60; ortho to the largest entry of ; det to its determinant; v to R @ [1, 2, 3]; and gap to the distance between v and Rx(c) @ Ry(b) @ Rz(a) @ [1, 2, 3].
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write householder(x) returning the reflection with the unit vector along , so that . Set H = householder(x) for the starter's random 4-vector, Hx = H @ x, and detH to its determinant.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A lidar is mounted on a robot at t = (0.1, 0, 0.3) m, turned by yaw = 150° about the robot's axis. Build its homogeneous transform T from lidar to robot, set pw to the robot-frame position of the lidar point (2, 0, 0), Tinv to the inverse built from and , and back to Tinv applied to pw.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A receiver expects a symbol at amplitude 1 and angle 20°, but a carrier phase error of −25° has turned the whole constellation. It received . Rotate it back by .
(a)
What is the corrected ?
(b)
What is the corrected ?
Check
is a real orthogonal matrix with . What does it do?
Check
Show that turning by and then by in the plane is a single turn by .
Step 1
What is the top-left entry of ?
Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.
Step 2
Write it as a single cosine.
Step 3
Doing the same for the bottom-left entry, , gives what?
Explain why
Why is the inverse of a rotation matrix just its transpose? What does that save in practice?
A rotation's columns are the rotated coordinate axes, which are still perpendicular unit vectors. So in , each entry is the dot product of two of those columns: 1 for a column with itself and 0 for two different ones, which makes and . In practice, converting between frames in both directions costs only a transpose, no elimination and no rounding error from inverting, which matters when an orientation filter does it a thousand times a second.
Practice
Keep practicing
8 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.