Skip to main content

3D rotation about arbitrary axis

Short answer

To rotate about an arbitrary axis, first translate so the axis passes through the origin, rotate it onto the z-axis via Rx(α) then Ry(β), apply the desired rotation Rz(θ), then undo the alignment rotations and translation. The composite matrix is T⁻¹·Rx(−α)·Ry(−β)·Rz(θ)·Ry(β)·Rx(α)·T.

Explain the steps required to rotate an object in 3D about an arbitrary axis (a line which is not parallel to any one coordinate axis).

Let the axis pass through the points P1(x1, y1, z1) and P2(x2, y2, z2). The idea is to make the axis coincide with a coordinate axis (z), rotate about it, and then undo the first transformations.

Axis vector V = P2 − P1 = (a', b', c'), length L = √(a'² + b'² + c'²). Unit vector u = (a, b, c) = V/L. Let d = √(b² + c²).

Steps

  1. Translate the axis so that P1 is at the origin: T(−x1, −y1, −z1).
  2. Rotate about the x-axis by angle α to bring the axis into the xz plane, with cosα = c/d and sinα = b/d.
Rx(α) = | 1  0     0    0 |
        | 0  c/d  -b/d  0 |
        | 0  b/d   c/d  0 |
        | 0  0     0    1 |
  1. Rotate about the y-axis by angle β to bring the axis onto the z-axis, with cosβ = d and sinβ = a. The axis must turn clockwise (seen from +y) to reach the z-axis, so the matrix has the clockwise form:
Ry(β) = | d  0 -a  0 |
        | 0  1  0  0 |
        | a  0  d  0 |
        | 0  0  0  1 |
  1. Rotate about the z-axis by the required angle θ: Rz(θ).
  2. Apply the inverse of step 3: Ry(−β).
  3. Apply the inverse of step 2: Rx(−α).
  4. Translate back: T(x1, y1, z1).

Composite matrix

M = T(P1) · Rx(−α) · Ry(−β) · Rz(θ) · Ry(β) · Rx(α) · T(−P1)

Each point of the object is multiplied by M: P' = M·P. When d = 0 (the axis is along the x-axis), the Rx step is skipped.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Computer Graphics chapter 4 questions →