Rotations
A rotation turns space around a fixed point without stretching, squashing, or reflecting it. Rotations are exactly the orthogonal matrices with determinant — the “rigid motions” that preserve every length and every angle. They’re used to augment training images, orient robots and point clouds, and constrain neural-network weights to stay well-behaved.
A real-life example: rotating a photo
When an app straightens a tilted photo, it applies a rotation matrix to every pixel coordinate. The picture turns, but nothing about it distorts — distances between features and the angles of lines are all preserved. That “turn without distort” is the defining property of a rotation, and it’s why rotations are a safe, label-preserving data augmentation in computer vision.
Rotations in 2-D
Rotating the plane counter-clockwise by angle sends the basis vectors to
so — since the columns of a matrix are the images of the basis vectors — the rotation matrix is
Watch it turn
The shape below is multiplied by as sweeps. The matrix updates live; notice that the shape’s size and proportions never change — only its orientation:
Rotations in 3-D and beyond
In 3-D you rotate about an axis. The three elementary rotations fix one axis and rotate the other two:
In dimensions, a Givens rotation is the identity matrix with a rotation block placed in rows/columns and — it rotates within one coordinate plane and leaves the other axes fixed. The 2-D matrix is the special case .
Properties
flowchart TD R["Rotation R(θ)"] --> O["orthogonal: RᵀR = I"] R --> D["det(R) = +1 (no reflection)"] R --> L["preserves lengths: ‖Rx‖ = ‖x‖"] R --> A["preserves angles between vectors"] R --> NC["3-D+ rotations do NOT commute"] R --> C2["2-D rotations DO commute (Abelian)"]
Rotations are orthogonal matrices, so (rotating back is just the transpose), and they preserve distances and angles. A subtlety that bites in robotics and graphics: in 3-D and higher, rotations do not commute — rotating about then differs from then . Only in 2-D (all rotations about the same origin) do they commute.
NumPy
import numpy as np
def R2(theta):
c, s = np.cos(theta), np.sin(theta)
return np.array([[c, -s], [s, c]])
x = np.array([3.0, 4.0])
R = R2(np.pi / 2) # 90° counter-clockwise
print("rotated:", np.round(R @ x, 4)) # [-4, 3]
# rotations preserve length and are orthogonal
print("length preserved:", np.allclose(np.linalg.norm(R @ x), np.linalg.norm(x)))
print("RᵀR = I:", np.allclose(R.T @ R, np.eye(2)))
print("det(R) = +1:", np.round(np.linalg.det(R), 6))
# 3-D rotations do NOT commute
def Rz(t): c,s=np.cos(t),np.sin(t); return np.array([[c,-s,0],[s,c,0],[0,0,1]])
def Rx(t): c,s=np.cos(t),np.sin(t); return np.array([[1,0,0],[0,c,-s],[0,s,c]])
a, b = Rz(0.5) @ Rx(0.5), Rx(0.5) @ Rz(0.5)
print("Rz·Rx == Rx·Rz ?", np.allclose(a, b)) # Falseimport numpy as np
def R2(theta):
c, s = np.cos(theta), np.sin(theta)
return np.array([[c, -s], [s, c]])
x = np.array([3.0, 4.0])
R = R2(np.pi / 2) # 90° counter-clockwise
print("rotated:", np.round(R @ x, 4)) # [-4, 3]
# rotations preserve length and are orthogonal
print("length preserved:", np.allclose(np.linalg.norm(R @ x), np.linalg.norm(x)))
print("RᵀR = I:", np.allclose(R.T @ R, np.eye(2)))
print("det(R) = +1:", np.round(np.linalg.det(R), 6))
# 3-D rotations do NOT commute
def Rz(t): c,s=np.cos(t),np.sin(t); return np.array([[c,-s,0],[s,c,0],[0,0,1]])
def Rx(t): c,s=np.cos(t),np.sin(t); return np.array([[1,0,0],[0,c,-s],[0,s,c]])
a, b = Rz(0.5) @ Rx(0.5), Rx(0.5) @ Rz(0.5)
print("Rz·Rx == Rx·Rz ?", np.allclose(a, b)) # Falserotated: [-4. 3.]
length preserved: True
RᵀR = I: True
det(R) = +1: 1.0
Rz·Rx == Rx·Rz ? Falserotated: [-4. 3.]
length preserved: True
RᵀR = I: True
det(R) = +1: 1.0
Rz·Rx == Rx·Rz ? FalseWhy this matters for ML
- Data augmentation: rotating images (and 3-D point clouds) generates new, correctly-labeled training examples, improving model robustness.
- Orthogonal weight constraints / initializations keep signal norms stable through deep networks (rotations don’t amplify or shrink).
- PCA and SVD decompose transformations into rotations and scalings; the rotation part reorients data onto its principal axes.
🧪 Try It Yourself
Exercise 1 – Rotate a vector 90°
Exercise 2 – Rotations preserve length
Exercise 3 – 3-D rotations don’t commute
Recap
- A rotation turns space rigidly: in 2-D, axis rotations in 3-D, Givens rotations in -D.
- Rotations are orthogonal () with ; they preserve lengths and angles.
- 2-D rotations commute; 3-D+ rotations do not — order matters.
- In ML they drive data augmentation, stable weight constraints, and the rotational part of PCA/SVD.
🎓 Chapter 3 complete
You’ve built the full geometric toolkit on top of Chapter 2’s algebra: norms → inner products → lengths & distances → angles & orthogonality → orthonormal bases → orthogonal complements → function inner products → projections → rotations. Similarity, distance, orthogonality, and projection are now concrete operations you can compute and picture — and they’re the direct mechanics behind PCA, regression, SVMs, and embeddings.
Head back to the Analytic Geometry Overview for the full map, or revisit Chapter 2 — Linear Algebra.
If this helped you, consider buying me a coffee ☕
Buy me a coffeeWas this page helpful?
Let us know how we did
