3D Rotation
Rotation is one of the most conceptually rich transformations in 3D computer graphics. While 2D rotation only ever happens around a single point, 3D rotation happens around an axis a full line in space and this added dimension introduces new complexity: there are infinitely many possible rotation axes, rotations about different axes don't behave the same way, and combining rotations is not as simple as adding angles.
What is Rotation?
Rotation is a transformation that turns every point of an object about a fixed axis by a certain angle θ, while keeping the object's shape and size unchanged. Every point traces a circular arc around the axis of rotation, and the distance from each point to the axis stays constant throughout.
Because 3D space has three independent directions, rotation can occur about:
- The X-axis
- The Y-axis
- The Z-axis
- Or any arbitrary axis passing through any point in space
The Right-Hand Rule and Sign Convention
By convention, computer graphics typically uses the right-hand rule to define positive rotation direction: if the thumb of the right hand points along the positive direction of the rotation axis, the curl of the fingers indicates the direction of positive (counter-clockwise) rotation when viewed from that axis looking back toward the origin.
This convention matters because it determines the sign pattern in the rotation matrices below.
Rotation about the Z-axis
When rotating about the Z-axis, points move within the XY-plane while their z-coordinate stays fixed. This is essentially the same as 2D rotation, with z carried along unchanged.
Derivation: Consider a point at distance r from the origin in the XY-plane, at angle φ from the X-axis: x = r cosφ, y = r sinφ. After rotating by θ, the new angle is φ + θ:
x' = r cos(φ + θ) = r cosφ cosθ - r sinφ sinθ = x cosθ - y sinθ
y' = r sin(φ + θ) = r sinφ cosθ + r cosφ sinθ = x sinθ + y cosθ
z' = zMatrix form:
Rz(θ) = | cosθ -sinθ 0 0 |
| sinθ cosθ 0 0 |
| 0 0 1 0 |
| 0 0 0 1 |Rotation about the X-axis
Here points rotate within the YZ-plane while x remains fixed. Using the same derivation logic (cyclically shifted: X→Y→Z→X):
y' = y cosθ - z sinθ
z' = y sinθ + z cosθ
x' = xMatrix form:
Rx(θ) = | 1 0 0 0 |
| 0 cosθ -sinθ 0 |
| 0 sinθ cosθ 0 |
| 0 0 0 1 |Rotation about the Y-axis
Points rotate within the ZX-plane while y remains fixed:
z' = z cosθ - x sinθ
x' = z sinθ + x cosθ
y' = yMatrix form:
Ry(θ) = | cosθ 0 sinθ 0 |
| 0 1 0 0 |
| -sinθ 0 cosθ 0 |
| 0 0 0 1 |Note the reversed sign pattern: in Rx and Rz, the negative sine appears in the upper-right position of the 2×2 rotation block, but in Ry it appears in the lower-left. This is a direct consequence of following the cyclic order X→Y→Z→X when deriving the formula, and it's a common point of confusion — always double check this when implementing rotation matrices in code.
Rotation about an Arbitrary Axis
In many real applications (robotics, animation, camera control), an object must rotate about an axis that doesn't align with X, Y, or Z — for example, an axis passing through an arbitrary point in an arbitrary direction.
General Procedure
- Translate the object (or axis) so the axis passes through the origin: T(-px, -py, -pz)
- Align the axis with a coordinate axis (commonly Z) using a sequence of rotations about X and Y.
- Rotate by the desired angle θ about that coordinate axis: Rz(θ)
- Undo the alignment rotations (apply their inverses).
- Translate back to the original position: T(px, py, pz)
The full transformation is:
R = T · Rx^-1 · Ry^-1 · Rz(θ) · Ry · Rx · T^-1Rodrigues' Rotation Formula (Direct Method)
A more elegant, direct approach uses Rodrigues' formula, which computes the rotation matrix for rotating by angle θ about a unit vector axis n = (nx, ny, nz) without needing to align axes step by step:
R = I + sinθ · K + (1 - cosθ) · K²where K is the skew-symmetric matrix formed from n:
K = | 0 -nz ny |
| nz 0 -nx |
| -ny nx 0 |This single formula is widely used in robotics, physics engines, and animation software because it avoids gimbal-lock issues that can arise from chaining multiple axis-aligned rotations.
Properties of 3D Rotation Matrices
- Orthogonality: Every proper rotation matrix R satisfies R^-1 = R^T — the inverse equals the transpose. This is a powerful computational shortcut: instead of computing a matrix inverse, you can simply transpose the matrix.
- Determinant = +1: A valid rotation matrix always has determinant +1 (distinguishing it from a reflection, which has determinant -1).
- Preserves length and angle: Like translation, rotation is a rigid-body transformation — it does not change the size or shape of an object.
Non-commutativity: Rotations about different axes generally do not commute:
Rx(θ) · Ry(φ) ≠ Ry(φ) · Rx(θ)This is why the order of rotations matters enormously in 3D (this is also the root cause of "gimbal lock" issues with Euler angles).
Same-axis rotations are additive: Rotating about the same axis twice is equivalent to a single rotation by the sum of angles:
Rz(θ1) · Rz(θ2) = Rz(θ1 + θ2)- Identity at θ = 0: When θ = 0, every rotation matrix reduces to the identity matrix.
Solved Numerical Problems
Problem 1
Rotate the point P(1, 0, 0) by 90° about the Z-axis. Find the new coordinates.
Solution:
θ = 90°, cos90° = 0, sin90° = 1
x' = x cosθ - y sinθ = 1(0) - 0(1) = 0
y' = x sinθ + y cosθ = 1(1) + 0(0) = 1
z' = z = 0New point P' = (0, 1, 0)
This makes sense: rotating a point on the positive X-axis by 90° counter-clockwise about Z lands it on the positive Y-axis.
Problem 2
Rotate the point P(0, 2, 0) by 90° about the X-axis. Find the new coordinates.
Solution:
θ = 90°, cosθ = 0, sinθ = 1
y' = y cosθ - z sinθ = 2(0) - 0(1) = 0
z' = y sinθ + z cosθ = 2(1) + 0(0) = 2
x' = x = 0New point P' = (0, 0, 2)
Problem 3
Rotate the point P(3, 0, 0) by 60° about the Y-axis. Find the new coordinates (use cos60° = 0.5, sin60° = 0.866).
Solution:
z' = z cosθ - x sinθ = 0(0.5) - 3(0.866) = -2.598
x' = z sinθ + x cosθ = 0(0.866) + 3(0.5) = 1.5
y' = y = 0New point P' = (1.5, 0, -2.598
Problem 4
A point P(2, 2, 0) is rotated by 45° about the Z-axis. Find its new position and verify that its distance from the origin remains unchanged.
Solution:
Original distance from origin:
d = √(2² + 2²) = √8 ≈ 2.828Rotation (cos45° = sin45° = 0.7071):
x' = x cosθ - y sinθ = 2(0.7071) - 2(0.7071) = 0
y' = x sinθ + y cosθ = 2(0.7071) + 2(0.7071) = 2.828
z' = 0New point P' = (0, 2.828, 0)
New distance from origin:
d' = √(0² + 2.828²) = 2.828Distance is unchanged (2.828 units), confirming rotation preserves distance from the axis/origin.
Problem 5
A point P(1, 1, 1) is rotated first by 90° about the X-axis, then by 90° about the Y-axis. Find the final coordinates, and comment on whether reversing the order would give the same result.
Solution:
Step 1 — Rotate by 90° about X-axis (cosθ=0, sinθ=1):
y' = y cosθ - z sinθ = 1(0) - 1(1) = -1
z' = y sinθ + z cosθ = 1(1) + 1(0) = 1
x' = x = 1After step 1: (1, -1, 1)
Step 2 — Rotate the result by 90° about Y-axis (cosθ=0, sinθ=1):
z'' = z cosθ - x sinθ = 1(0) - 1(1) = -1
x'' = z sinθ + x cosθ = 1(1) + 1(0) = 1
y'' = y = -1Final point = (1, -1, -1)
Comment: Since rotation matrices generally do not commute, performing the Y-axis rotation before the X-axis rotation would produce a different final result. (Students are encouraged to verify this by reversing the order and comparing.)
Problem 6 (Practice try it yourself)
A point P(0, 3, 4) is rotated by 30° about the X-axis. Using cos30° = 0.866 and sin30° = 0.5, find the new coordinates of the point, and verify that its distance from the X-axis (√(y² + z²)) remains unchanged after rotation.
Conclusion
3D rotation extends the simplicity of 2D rotation into a richer, axis-dependent transformation. Understanding the three standard axis rotation matrices and recognizing why they don't commute is essential before tackling more advanced topics like quaternions, Euler angle systems, and gimbal lock, all of which build directly on the foundations covered here.
Was this article helpful?