Rotation Matrices
Spin a logo by exactly 90^\circ, tilt a steering wheel by
33.7^\circ, sweep a clock hand smoothly through every angle in between —
there's a matrix for that, and it's built directly out of sine and cosine. Every rotating icon,
every turning clock hand, every spinning wheel you've ever seen on a screen is running the same
short formula underneath, over and over, many times a second.
To rotate the whole plane about the origin by an angle \theta, we
only need to know where \hat{\imath} and
\hat{\jmath} go — and trigonometry tells us exactly, straight from the
unit circle. The point \hat{\imath}=(1,0) sits at angle
0^\circ on the unit circle; rotating it by \theta
just moves it round to angle \theta, landing at
(\cos\theta, \sin\theta) — that's the very definition of sine and
cosine. The point \hat{\jmath}=(0,1) sits at angle
90^\circ; rotating it by \theta moves it to
angle 90^\circ+\theta, which the angle-sum identities turn into
(-\sin\theta, \cos\theta). Stacking those two landing spots as columns
gives the rotation matrix:
R(\theta) = \begin{bmatrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \end{bmatrix}.
Turn the dial
Spin the angle below. The grid rotates rigidly — distances and angles are perfectly preserved,
nothing stretches or skews. Watch the readout: it is exactly the two columns we just derived,
(\cos\theta,\sin\theta) and (-\sin\theta,\cos\theta),
updating live as \theta sweeps round.
Worked example: the 90° quarter-turn
Set \theta = 90^\circ. Since \cos 90^\circ = 0
and \sin 90^\circ = 1, the formula collapses to something beautifully
simple:
R(90^\circ) = \begin{bmatrix} 0 & -1 \\ 1 & 0 \end{bmatrix}.
Check it against \hat{\imath}=(1,0) directly:
R(90^\circ)\begin{bmatrix}1\\0\end{bmatrix} = \begin{bmatrix}0\cdot 1 + (-1)\cdot 0\\ 1\cdot 1 + 0\cdot 0\end{bmatrix} = \begin{bmatrix}0\\1\end{bmatrix}
— exactly where the first column says it should land. Try
\hat{\jmath}=(0,1) too:
R(90^\circ)\begin{bmatrix}0\\1\end{bmatrix} = \begin{bmatrix}-1\\0\end{bmatrix},
the second column. No surprises — the matrix multiplication just hands back the columns we
already knew, because that's all a matrix ever does.
Worked example: rotating a point by 45° and 60°
Some angles give clean, memorable trig values, which makes them perfect for practising by hand.
At 45^\circ, \cos 45^\circ=\sin 45^\circ=\tfrac{\sqrt2}{2},
so:
R(45^\circ)\begin{bmatrix}1\\0\end{bmatrix} = \begin{bmatrix}\tfrac{\sqrt2}{2}\\[2pt]\tfrac{\sqrt2}{2}\end{bmatrix}
— the point (1,0) swings up to sit exactly on the diagonal line
y=x, as you'd expect from splitting a right angle clean in half. At
60^\circ, \cos 60^\circ=\tfrac12 and
\sin 60^\circ=\tfrac{\sqrt3}{2}, so rotating the vector
(2,0) gives:
R(60^\circ)\begin{bmatrix}2\\0\end{bmatrix} = \begin{bmatrix}2\cdot\tfrac12\\[2pt]2\cdot\tfrac{\sqrt3}{2}\end{bmatrix} = \begin{bmatrix}1\\\sqrt3\end{bmatrix}.
Notice the length is unchanged either way: (1,0) and
(2,0) had lengths 1 and
2, and so do their rotated images — a rotation never stretches
anything, it only turns it. Check the second one: the rotated vector is
(1,\sqrt3), with length
\sqrt{1^2+(\sqrt3)^2}=\sqrt{1+3}=\sqrt4=2 — exactly the length we
started with.
Worked example: composing two rotations
What happens if you rotate by 30^\circ and then, on the result, rotate
again by 60^\circ? Intuitively the two turns should just add up to one
90^\circ turn — and matrix multiplication confirms it exactly, because
applying R(30^\circ) and then R(60^\circ) is
the single matrix R(60^\circ)R(30^\circ):
R(60^\circ)R(30^\circ) = \begin{bmatrix}\tfrac12 & -\tfrac{\sqrt3}{2}\\[2pt]\tfrac{\sqrt3}{2} & \tfrac12\end{bmatrix}\begin{bmatrix}\tfrac{\sqrt3}{2} & -\tfrac12\\[2pt]\tfrac12 & \tfrac{\sqrt3}{2}\end{bmatrix} = \begin{bmatrix}0 & -1\\1 & 0\end{bmatrix} = R(90^\circ).
The messy square roots all cancel out, leaving exactly the clean 90^\circ
matrix from the first worked example. That is not a coincidence of these particular numbers — the
top-left entry of the product works out to
\cos60^\circ\cos30^\circ - \sin60^\circ\sin30^\circ, which is precisely
the angle-sum identity for \cos(60^\circ+30^\circ). Multiplying rotation
matrices and adding angles are, quietly, the exact same fact — angles of rotation simply add when
you compose them, R(a)R(b)=R(a+b), however ugly the intermediate matrix
multiplication looks. This is a first, gentle taste of a much bigger idea for later: composing two
transformations — doing one, then another — is always the same as multiplying their
matrices together, the subject of
composing
transformations.
Rotations that don't distort
A rotation is a rigid motion: it preserves every length and every angle, so it
never changes area — its
determinant
is exactly 1. Its columns are perpendicular unit vectors, which makes
it an orthogonal matrix, and undoing a rotation is simply rotating back:
R(\theta)^{-1} = R(-\theta). Rotations are the workhorses of computer
graphics, robotics and any place a thing needs to turn without warping.
You can check the "unit vector" claim yourself: the first column has length
\sqrt{\cos^2\theta + \sin^2\theta}, which the Pythagorean identity
\cos^2\theta+\sin^2\theta=1 collapses straight to
1, for every angle \theta — no
exceptions, no special cases. And the inverse rule is worth a quick check too: rotating
(1,0) by 30^\circ and then by
-30^\circ should land you exactly back where you started, since
\cos(-30^\circ)=\cos(30^\circ) and
\sin(-30^\circ)=-\sin(30^\circ) — the second rotation is the mirror
image of the first, undoing it perfectly.
-
Which way is "positive"? By the standard maths convention used on this page,
a positive angle rotates counterclockwise — the same direction the unit circle
is traced out. But plenty of graphics and screen-coordinate systems flip the
y-axis to point down the screen instead of up, and in that
flipped world the very same formula makes a positive angle look like it spins
clockwise. This mismatch is a real, recurring source of bugs when translating
rotation maths straight into game or graphics code — always check which way "up" points in your
coordinate system before trusting the sign of an angle.
-
A rotated vector never changes length — use that as a sanity check. If you ever
compute R(\theta)v and the result is longer or shorter than
v, you've made an arithmetic slip somewhere (or your matrix wasn't a
genuine rotation matrix at all, perhaps because a stray scale factor crept in). Length
preservation is a fast, free way to check your work every single time.
Everywhere. Every CSS rotate(θ) or SVG transform="rotate(...)" on a
webpage compiles down to precisely this 2\times2 matrix. Every
video-game camera swivel, steering-wheel turn, or spinning power-up icon runs the same
\cos\theta,\sin\theta arithmetic, typically sixty times a second, so
fast you'd never guess trigonometry was involved.
It even shows up somewhere much less digital: a figure skater or gymnast spinning through a
"triple" or "quad" jump is, from the judges' point of view, rotating their body through
3\times360^\circ or 4\times360^\circ before
landing. Sports-broadcast graphics that overlay a spinning angle tracker on a replay are, quite
literally, plotting R(\theta) applied to a marker on the skater's
shoulders, frame by frame, exactly as the chart above plots it applied to a grid.
Old game consoles and early graphics chips couldn't easily afford to compute
\cos\theta and \sin\theta from scratch for
every single frame, so engineers leaned on a clever shortcut called CORDIC —
a way of building up any rotation out of nothing but a sequence of tiny, pre-known "micro-rotations"
using only additions and bit-shifts, no multiplication or trig tables required. The 1980s
scientific calculator in a drawer somewhere probably still rotates this way today, one tiny nudge
at a time, all in the service of the very same matrix on this page.
See it explained