25 min

Rotation order matters: two turns are a sequence, not a set

Two rotations about different axes land somewhere different depending on which one you do first, and the gap between the two answers is itself a rotation you can measure.

Where you are. You can write RxR_x, RyR_y and RzR_z and read a rotation matrix by its columns. This lesson is about what happens the first time you use two of them together.

Pick up your phone

Reading this will not work. Get the actual phone.

Put it flat on the desk in front of you, screen up, with the top edge pointing away from you. Now do two things, in this order.

One. Tilt it up towards you: lift the far edge and stand the phone on its bottom edge, so the screen faces you.

Two. Turn the whole thing a quarter turn to the left, as though the desk under it were a turntable.

Look at where the screen ended up. It faces off to your right, edge-on to you; from your seat you cannot read it at all.

Now put it back exactly as it started, flat and screen up with the top away, and do the same two things in the other order.

One. Turn it a quarter turn to the left, still lying flat. The top edge now points to your left.

Two. Tilt it up towards you, lifting whichever edge is furthest away now.

The screen faces you.

Same phone, same two motions, ninety degrees each time, and your hands were not sloppy. The screen ended up pointing in two directions a quarter turn apart. That gap is not an error, an approximation, or a convention you can define away. It is arithmetic, and it is the most common source of orientation bugs that read as “almost right, but wrong.”

seen from the left front of the desk, looking down · the gold bar is the phone's top edge · the dashed panel is the screen start flat on the desk screen up · top away 1 · tilt up 90° standing · screen faces you 2 · turn left 90° screen faces right no screen in sight 1 · turn left 90° still flat · top now points left 2 · tilt up 90° screen faces you top edge on the left same two turns, opposite orders · the two results are 120° apart
A phone on a desk given a ninety-degree tilt and a ninety-degree turn in both possible orders; tilting first leaves the screen facing right, turning first leaves the screen facing the reader

Wider than the screen; scroll it sideways.

The idea in one paragraph

Rotations about different axes do not commute. Doing turn A and then turn B leaves the object in a different orientation from doing B and then A, and the difference is not small. Matrix multiplication says exactly this, which is why the standard notation R=R2R1R = R_2\,R_1 has a reading order you cannot swap: the rightmost matrix acts first. Rotations about the same axis do commute, and every rotation in a plane shares one axis, which is why nothing in two dimensions ever prepared you for this. The disagreement between the two orders shrinks fast as the turns get smaller, roughly as the square of the angle, and that single fact explains why angular velocities add like ordinary vectors while rotations do not.

The second turn cannot know what the first one did

Here is the intuition, and it is worth more than the algebra.

Both of your turns were about axes fixed in the room, not in the phone. The tilt was about the left-to-right axis of the desk. The turntable spin was about the vertical axis of the room. Neither axis moved when you moved the phone.

So on the second run, when you finally got round to tilting, the phone was no longer lying where it had been. You had already spun it a quarter turn, so the desk’s left-to-right axis now ran through the phone the long way instead of the short way. The same physical axis went through a different part of the object, and it therefore did a different job.

That is the whole mechanism. A rotation moves the body. The next rotation acts on wherever the body now is.

The matrices say the same thing

Write the tilt as Rx(90)R_x(90^\circ) and the turntable spin as Rz(90)R_z(90^\circ). Your first run was tilt then turn, so the tilt goes on the right:

A = Rz(np.pi/2) @ Rx(np.pi/2)     # tilt first, then turn
B = Rx(np.pi/2) @ Rz(np.pi/2)     # turn first, then tilt

Both are perfectly good rotation matrices; both are orthonormal with determinant +1+1. They are simply not the same matrix. Read them by their columns, which is where each body axis lands:

the phone’s own axistilt, then turnturn, then tilt
x, out its right edgeends up at +y (pointing away from you)ends up at +z (pointing up)
y, out its top edgeends up at +z (pointing up)ends up at −x (pointing left)
z, out of the screenends up at +x (pointing right)ends up at −y (pointing at you)

Every one of the three axes lands a full 90° away from where the other order put it. The last row is the one your eyes checked on the desk: screen to the right, or screen towards you.

The gap is itself a rotation

You now have two orientations and no obvious way to describe how far apart they are. There is a clean answer: ask what single rotation carries one onto the other. That rotation is ABA\,B^{\top}, since BB^{\top} undoes BB and AA then applies the other order.

Run it and you get a rotation of 120° about the axis (1,1,1)/3(-1, 1, 1)/\sqrt{3}. Not a strange numerical residue; a large, specific, perfectly ordinary rotation. Two 90° turns taken in the wrong order leave you a third of a full revolution away from where you meant to be.

That 120° is worth a second look, because each individual axis moved only 90°. The two facts are not in conflict: one rotation has to move all three axes at once, and the cheapest single turn that relocates all three together is a 120° twist about a diagonal, which cycles the axes round rather than swinging each one 90° on its own. This is why “how far apart are these two orientations” has to be asked of the orientation as a whole, never axis by axis.

where the phone's own three axes ended up, in each order x y z tilt, then turn x → +y · y → +z · z → +x 120° apart one twist about the axis (−1, 1, 1) x y z turn, then tilt x → +z · y → −x · z → −y every one of the three axes ends up 90° away from where the other order put it
The phone's three body axes after each order, and the single one-hundred-and-twenty-degree twist that carries one result onto the other

Wider than the screen; scroll it sideways.

The one case where order is safe

Rotations about the same axis do commute, and the reason is not deep: they just add. Turn 30° about the vertical and then 50° about the vertical, and you have turned 80° about the vertical. Reverse them and you have still turned 80°.

in a plane there is only one axis to turn about: the one sticking out of the page start 80° both orders land here 30° 50° two turns about one axis, taken in either order R(30°) · R(50°) R(50°) · R(30°) both equal R(80°) one axis · the angles simply add
Two turns about a single axis: thirty then fifty, and fifty then thirty, both arriving at eighty degrees

Wider than the screen; scroll it sideways.

This is why two dimensions never warned you. Every rotation of a plane is a rotation about the same axis, the one sticking out of the page; there is only one axis available. So in 2D, R(a)R(b)=R(b)R(a)R(a)\,R(b) = R(b)\,R(a) always, angles add, and the whole business feels like arithmetic on a single number. Step up to 3D and you get a choice of axis, and with the choice comes the ordering problem. It is the choice of axis that breaks commutativity, not the extra dimension.

Which axis are you turning about?

Try one more thing with the phone. Start flat again, tilt it up towards you so the screen faces you, and then, instead of using the desk as a turntable, spin the phone in its own plane about the axis coming straight out of the screen at you, carrying the top edge round towards your left.

You get the second answer: screen towards you, top edge on the left.

This is the rule that catches everyone. Turning about axes glued to the body, in the order tilt-then-spin, gives you the same matrix as turning about axes fixed in the room in the order spin-then-tilt. Body-frame sequences multiply in the opposite order from world-frame sequences. Both descriptions are correct, both are used in real libraries, and they are mirror images of each other.

How wrong will an order mistake make you?

Not always 120°. Take both turns to be the same angle θ\theta and measure how far apart the two orders end up:

each turnhow far apart the two orders land
90°120°
45°33.7°
30°15.4°
10°1.74°
0.44°
0.017°

Below about 30°, halving the angle drops the disagreement to very nearly a quarter of what it was: 30° to 15° divides it by 3.94, and 10° to 5° by 3.99. The gap grows like θ2\theta^2, and for small θ\theta it is almost exactly θ2\theta^2 radians read off in degrees. At 10° the measured gap is 1.741° against a predicted 1.745°; at 1° the two agree to five significant figures.

That is a genuinely useful thing to know in both directions. It is bad news, because a controller applying tiny corrections thousands of times a second gets an order error so small per step that no test will ever catch it, while the errors quietly accumulate. It is good news, because it is exactly why angular velocity is a vector. Rates of turn are the θ0\theta \to 0 limit, where the ordering penalty vanishes entirely, so you may add angular velocities about different axes component by component and be exactly right. Finite rotations never get that privilege. Hold on to that distinction; it is what makes the Jacobian a matrix rather than something much worse.

Interactive: choose two axes and two angles, toggle which one is applied first, and watch the two results side by side. Static fallback: with 90° about x and 90° about z, tilt-then-turn leaves the screen facing right and turn-then-tilt leaves it facing you; the two results are 120° apart, about the axis (1,1,1)/3(-1, 1, 1)/\sqrt{3}.

Review

Why the order changes the answer

Rotations about different axes do not commute, and the reason is physical rather than algebraic. A rotation moves the body, and the next rotation acts on wherever the body now is. Tilt the phone first and the desk’s left-to-right axis then runs through it the long way instead of the short way, so the same physical axis does a different job. That is why a product of rotation matrices has a reading order you cannot swap: the rightmost matrix acts first, the same way encrypt of compress of x runs compress first. Rotations about the same axis are the safe case, because they simply add. Every rotation of a plane shares one axis, which is why two dimensions never warned you. It is the choice of axis that breaks commutativity, not the extra dimension.

The gap between two orders is itself a rotation

To say how far apart two orientations are, ask what single rotation carries one onto the other. For two ninety-degree turns taken in both orders, that rotation is one hundred and twenty degrees about a diagonal axis. Not a strange numerical residue; a third of a full revolution. Each individual axis moved only ninety degrees, and the two facts do not conflict: one rotation has to move all three axes at once, and the cheapest single turn that relocates all three cycles them round a diagonal rather than swinging each one on its own. Euler proved the general form in seventeen seventy-five. Any motion of a rigid body that leaves one point fixed is one rotation about one axis, however many turns you built it from. So the distance between two orientations is asked of the orientation as a whole, never axis by axis.

Why small angles hide an order mistake

Take both turns to be the same angle and the disagreement between the two orders grows like the square of that angle. At ninety degrees it is one hundred and twenty degrees; at ten degrees, one and three quarters; at one degree, under two hundredths of a degree. That is bad news and good news at once. Bad, because a controller applying tiny corrections a thousand times a second makes an order error too small for any test to catch, and it is a systematic bias rather than noise, so it accumulates instead of averaging away. Good, because it is exactly why angular velocity is a vector. Rates of turn are the limit as the angle goes to zero, where the ordering penalty vanishes, so angular velocities about different axes may be added component by component and be exactly right. Finite rotations never get that privilege.

Check yourself

1. A colleague argues that since orientation is three numbers, composing two rotations should be adding two three-number vectors. Refute it with the phone.

Both of your runs consist of the same two turns, so both would give the same “sum”: 90° about x plus 90° about z. But the two runs end up 120° apart. A single addition cannot produce two different answers from the same inputs, so composition of rotations is not vector addition. The three numbers are a description of an orientation, not a quantity you may add.

2. Why did none of this ever bite you in two dimensions?

Because every rotation of a plane is about the same axis, the one perpendicular to the page. Rotations that share an axis commute, and their angles simply add. Two dimensions is not a simpler version of the general case; it is the special case where the choice of axis does not exist. The moment you get a choice of axis, order becomes part of the meaning.

3. Read R = Rz(0.4) @ Ry(0.2) @ Rx(0.1) out loud. Which turn happens first, and about which axes are these turns taken?

Rightmost first: turn 0.1 rad about x, then 0.2 rad about y, then 0.4 rad about z. All three are about axes fixed in the reference frame this matrix is written in, not axes carried along by the body. If you wanted body axes, this same product describes the sequence z, then the new y, then the newest x, which is the reverse ordering.

4. Two subsystems each report the tool’s orientation. Whenever the tool is both tilted and panned by 90°, their answers differ by exactly 120° about (−1, 1, 1)/√3, and at small angles they agree closely. Diagnosis?

One of them composes the two rotations in the opposite order to the other. That specific 120° gap is the signature of swapping a 90° x-turn with a 90° z-turn. The near-agreement at small angles is the second clue: an order mistake costs roughly θ2\theta^2, so it hides at small angles and blows up at large ones. Look for a transposed product or a fixed-axis convention meeting a body-axis one, not for a sensor fault.

5. A drift corrector applies a rotation of about 0.05° to a pose estimate, 1000 times a second, alongside another small rotation about a different axis. Does getting the order wrong matter?

Per step, almost not at all: the disagreement scales as θ2\theta^2, so at 0.05° it is 0.0000436°, which no assertion you would think to write is ever going to catch. But it is a systematic bias in a fixed direction, not noise, so it accumulates instead of averaging away. At 1000 steps a second that is up to 0.044° per second, about 2.6° a minute, if the steps keep pulling the same way. Order errors of this kind never announce themselves; they show up as slow orientation drift that survives every unit test.

6. State the exact condition under which two 3D rotations commute.

When they are about the same axis, in which case their angles add. The degenerate cases fall out of that: either rotation being the identity, or a 180° turn composed with itself. Anything else and the order changes the answer. “Nearly the same axis” and “very small angles” both make the difference small, but neither makes it zero.

Do this

Open code/rotations_lab.py and run part2_order_matters(), which builds both products and applies them to the same point.

  1. Run it as written and confirm the two printed points differ. If Rx, Ry and Rz are still stubs from the previous lesson, fill them in first; the solutions are in solutions/rotations_lab.py.

  2. Add three lines to it. Compute D = (Rz(a) @ Rx(a)) @ (Rx(a) @ Rz(a)).T, then recover the angle of that gap with np.degrees(np.arccos((np.trace(D) - 1) / 2)). At a = np.pi/2 you should get 120. That trace formula is worth keeping: it turns any rotation matrix into “how big a turn is this”, which is the honest way to measure the distance between two orientations.

  3. Loop the same measurement over a in 90, 45, 30, 10, 5 and 1 degrees and print the gap next to np.degrees(a**2). Watch the two columns converge as the angle shrinks. You have just measured, rather than been told, why angular velocities add and rotations do not.

  4. Finally, put the phone back on the desk and repeat the two runs while narrating which axis each turn is about. Thirty seconds. The muscle memory of “the second turn acts on a body that has already moved” is what actually stops you writing the product backwards at two in the morning.

What you can now do

You can look at any product of rotation matrices and say which turn happens first and about which frame’s axes. You can explain why two dimensions never raised this and why the choice of axis, not the extra dimension, is what breaks commutativity. You can measure the gap between two orientations as a single angle, predict how an order mistake scales with the size of the turns, and recognise the signature of a swapped composition in someone else’s bug report.

What you can now do

You can say which turn happens first in any product of rotation matrices, explain why two dimensions never warned you, and estimate how much an order mistake will cost.