The idea: turn space about an axis

A rotation in 3D turns every point about a fixed line through the origin, the axis, by the same angle θ. Points on the axis stay where they are; every other point moves on a circle around the axis. Like every linear map it is a matrix, and its columns are where î = (1, 0, 0), ĵ = (0, 1, 0) and k̂ = (0, 0, 1) land. The positive direction follows the right-hand rule: point your right thumb along the axis and your fingers curl the positive way (counter-clockwise seen from the tip of the axis).

The three matrices Rx(θ), Ry(θ) and Rz(θ) side by side. In each, the row and column of the fixed axis (1 on the diagonal, 0 elsewhere) are grey and the 2 by 2 block of cos θ and sin θ is shaded, with the turned plane named underneath: y-z for Rx, z-x for Ry, x-y for Rz
Each axis rotation is the 2D rotation R(θ) in one coordinate plane, with a 1 for the axis that stays.

Rx, Ry, Rz: the 2D rotation inside 3D

A turn about the z-axis leaves z alone and turns x and y exactly like the 2D rotation matrix:

Rz(θ) = [cos θ  −sin θ  0;  sin θ  cos θ  0;  0  0  1]

The top-left 2×2 block is R(θ); row 3 and column 3 are (0, 0, 1) because k̂ does not move. For θ = 60° the block is [½ −√3/2; √3/2 ½]. (Demo 1: turn about z, the 2D rotation inside 3D) The other two put the block in the other coordinate planes:

turn aboutmatrixstaysturns
x-axisRx(θ) = [1 0 0; 0 cos θ −sin θ; 0 sin θ cos θ]xy → z
y-axisRy(θ) = [cos θ 0 sin θ; 0 1 0; −sin θ 0 cos θ]yz → x
z-axisRz(θ) = [cos θ −sin θ 0; sin θ cos θ 0; 0 0 1]zx → y

Ry looks like it has the sign in the wrong place: −sin θ sits bottom left. The cyclic order x → y → z → x explains it. About the y-axis the positive turn takes z toward x (not x toward z), so in the (z, x) plane it is the usual 2D rotation, and written in the (x, z) order the minus sign moves down. For θ = 90°, Rx sends ĵ to k̂ and k̂ to −ĵ; the point v = (2, 1, 2) goes to (2, −2, 1). (Demo 2: turn about x)

Every point moves on a circle; the axis stays

Split a point into its part along the axis and its part across it. The turn keeps the part along the axis and turns the part across it in the plane at right angles to the axis. So every point moves on a circle whose centre is on the axis, and the canvas draws that circle for v in light purple while the turn plays.

A point on the axis has no part across it: it does not move at all. In matrix words, the axis direction u is an eigenvector with eigenvalue λ = 1: M·u = u. The other two eigenvalues are cos θ ± i sin θ = e±iθ, not real (unless θ = 180°, where they are −1, −1), because no other direction stays on its own line. Every 3D rotation has such a real axis: a 3×3 real matrix has a real eigenvalue, and for a rotation it is 1. (Demo 5: the axis stays put (λ = 1), where a turn by 90° about (1, 1, 1) has entries ⅓ and (1 ± √3)/3, yet M·(1, 1, 1) = (1, 1, 1) exactly.)

Any axis: Rodrigues' formula

For a unit vector u = (ux, uy, uz) and an angle θ,

R = cos θ·I + (1 − cos θ)·uuT + sin θ·[u]×,   where [u]× = [0 −uz uy; uz 0 −ux; −uy ux 0]

is the matrix of the cross product u × v. Read it term by term: uuTv is the part of v along the axis (kept), and the rest of v is turned by θ in the plane across the axis, with u × v giving the direction a quarter turn on. Put u = (0, 0, 1) and you get Rz back.

A neat case is u = (1, 1, 1)/√3 and θ = 120°: cos θ = −½, sin θ = √3/2 and every entry comes out 0 or 1:

R = [0 0 1; 1 0 0; 0 1 0]:   î → ĵ,   ĵ → k̂,   k̂ → î.

The turn just renames the axes: x becomes y, y becomes z, z becomes x. Three such turns make 360°, and R3 = I. (Demo 4: 120° about (1, 1, 1): x → y → z)

Left: the axes x, y, z in 3D with the diagonal axis (1, 1, 1) drawn in black and a light purple circle about it through the tips of î, ĵ and k̂; curved purple arrows show î going to ĵ, ĵ to k̂ and k̂ to î, each a 120 degree turn. Right: the matrix R = [0 0 1; 1 0 0; 0 1 0] with its columns coloured red, green and blue
The tips of î, ĵ, k̂ sit on one circle about (1, 1, 1), 120° apart; a 120° turn moves each onto the next.

det = 1 and the inverse is the transpose

A rotation keeps every length and every angle, so the columns of M (the images of î, ĵ, k̂) are still unit vectors at right angles: an orthonormal set. That is exactly the statement MTM = I, since entry (i, j) of MTM is column i · column j. A matrix with this property is orthogonal, and its inverse costs nothing:

M−1 = MT (mirror the matrix across its diagonal).

The determinant of an orthogonal matrix is ±1. Rotations have det = +1: volume is kept and the F is turned, never mirrored. Orthogonal matrices with det = −1 are reflections (see 3D Reflection Matrix). Turning back by MT uses the same axis and the angle backwards. (Demo 6: the inverse is the transpose)

The order of the turns matters in 3D

In the plane, two rotations about the origin can be done in either order. In 3D they cannot. Turn 90° about x and then 90° about y, and the matrix is Ry(90°)·Rx(90°) (the later turn is written on the left, because it acts on the result of the first):

ordermatrixsendsas one turn
x first, then yRy(90°)·Rx(90°) = [0 1 0; 0 0 −1; −1 0 0]î → −k̂, ĵ → î, k̂ → −ĵ120° about (1, 1, −1)
y first, then xRx(90°)·Ry(90°) = [0 0 1; 1 0 0; 0 1 0]î → ĵ, ĵ → k̂, k̂ → î120° about (1, 1, 1)

Same two turns, different results: matrix multiplication does not commute, and 3D rotations show it. The canvas keeps the first result in grey and then does the turns the other way round, and the two F's end up facing different ways. (Demo 3: order matters in 3D) Both products are again a single turn about a single axis: the product of two rotations is always a rotation.

Two 3D views side by side, each with the x, y, z axes and a letter F. Left: x first, then y, the matrix Ry(90°)·Rx(90°) and the F lying one way. Right: y first, then x, the matrix Rx(90°)·Ry(90°) and the F lying a different way
Ry(90°)·Rx(90°) ≠ Rx(90°)·Ry(90°): the same two quarter turns in the other order leave the F facing another way.

Reading the angle and the axis back from M

Any rotation matrix, however it was built, is one turn by some θ about some axis u (Euler's rotation theorem). Both come out of M directly:

  • The angle: the trace (sum of the diagonal) is tr M = 1 + 2cos θ, the sum of the eigenvalues 1 + eiθ + e−iθ. For Ry(90°)·Rx(90°) the trace is 0, so cos θ = −½ and θ = 120°.
  • The axis: M − MT = 2 sin θ·[u]×, so u points along (M32 − M23, M13 − M31, M21 − M12). For the matrix above that is (1, 1, −1). At θ = 180° this is 0; then any non-zero column of M + I points along the axis.

The facts panel does this after every turn. All numbers on the canvas are exact: the angles are multiples of 30° and 45°, so every entry has the form (a + b√2 + c√3 + d√6)/n, and sums and products stay in that form.

See also Linear Transformations for the 2D overview, Rotation Matrix (2D), 3D Rotation and Scale Matrices, Quaternions (the same turns as q v q−1, no gimbal lock), 3D Reflection Matrix, 3D Projection Matrix, 3D Shear Matrix, Composing Transforms, Matrix Multiplication, Inverse Matrix, Determinant, Eigenvectors and Changing Coordinates in 3D.

What the page leaves out

Euler angles and their gimbal lock, yaw–pitch–roll conventions, and turning about the body's own axes (intrinsic) instead of the fixed world axes (extrinsic), which reverses the order of the product. Quaternions and the exponential map R = eθ[u]×, the angle-axis interpolation (slerp) that the animation uses internally, rotations about a line that does not pass through the origin (that needs a translation, see Affine Transforms), and rotations in more than three dimensions.