TL;DR
A rotation matrix is a small grid of numbers that turns a point or vector around the origin by a fixed angle. Multiply a vector by it and you get the same vector, turned. Lengths stay the same, and so do the angles between any two vectors, so nothing gets stretched or squashed.
Every 2D rotation matrix is built from just two numbers, the cosine and the sine of the angle. Two of them compose by multiplication, and undoing a rotation is as simple as flipping the sign of the angle.
Where you'll see it: rotating sprites and cameras in games, orienting robot arms and drones, and any 3D graphics pipeline that has to spin a model.
Intuition
Suppose you want to spin a flat map by 30 degrees. Every point on the map has to move along a circle around the centre, and the amount it moves depends on how far it started from the centre. A rotation matrix packages that whole motion into one object. You do not track each point separately. You multiply once, and every point in the plane is carried around by the same angle.
The reason it works is that a rotation is determined by where it sends two simple vectors. Send the unit vector along the x-axis to some new spot, and send the unit vector along the y-axis to another spot, and every other vector follows by combining those two. The matrix simply writes down where those two basis vectors land, one per column.
For a counterclockwise rotation by an angle , the -axis vector lands at and the -axis vector lands at . The plot below shows how those two numbers change as the angle grows. Both are periodic, and they trade off: when one is near its largest value, the other is near zero.
- cos θ
- sin θ
The math
The 2D rotation matrix
For a counterclockwise rotation by angle in the plane,
Applying it to a vector gives, by the rule for matrix-vector multiplication,
The first column of is where the x-axis unit vector lands, and the second column is where the y-axis unit vector lands. This is the same column picture described in linear transformations.
Two properties that define a rotation
A rotation matrix satisfies
where is the transpose (rows and columns swapped) and is the identity matrix. The first condition says the columns are orthonormal: each has length 1, and they are perpendicular (their dot product is zero). The second, on the Determinant, says the matrix preserves area and orientation, which is what a rotation should do. A reflection also preserves area, but it flips orientation, and its determinant is . That is why a matrix with is not a rotation.
The first condition gives the inverse for free. Since , we have . Algebra with the cosine and sine shows , so undoing a rotation is the same as rotating by the negative angle.
Composition adds angles
Rotating by and then by should equal rotating by . Matrix multiplication is how we express "one map after another", so
In 2D the order does not matter: , because . In three dimensions it is not, which is one of the main surprises when moving from the plane to space.
Rotations in three dimensions
A rotation about the -axis by angle keeps the -coordinate fixed and rotates the - plane:
Rotations about the - and -axes have the same form, placed in different rows and columns. A general 3D rotation can be written as a product of three such matrices, which is the idea behind Euler angles.
Worked examples
Take , so and .
- .
- Apply it to : the first entry is , and the second is .
- The result is . The point on the positive -axis moved to the positive -axis, a quarter turn counterclockwise.
Rotate by . Here and .
- The rotated x-entry is .
- The rotated y-entry is .
- So .
- Check the length. Before: . After: . The length is unchanged, as a rotation requires.
- Undo it: apply to and you get back up to rounding. That is the inverse property at work.
Show that two rotations by make one rotation by .
- .
- Multiply . The top-left entry is .
- The top-right entry is . The bottom-left is , and the bottom-right is .
- The product is , which is exactly from the first example. Two turns in the same direction give a quarter turn in total, as the formula predicts.
Tradeoffs and failure modes
A rotation matrix is the right tool when you need to apply one fixed rotation to many points, or to chain rotations with a single product. It is not always the best representation for storing or interpolating rotations.
| Situation | Problem | Better choice |
|---|---|---|
| Repeatedly multiplying many rotations | Rounding error builds up, and the matrix slowly stops being orthonormal | Periodically re-orthogonalise the matrix, or store the rotation as a quaternion |
| Smoothly animating a 3D rotation between two poses | Interpolating matrix entries does not give a true rotation in between | Quaternion slerp (spherical linear interpolation) |
| Describing 3D orientation with three angles | Gimbal lock: at certain orientations two axes align and one degree of freedom is lost | Quaternions, or a full rotation matrix |
| Rotating around a point other than the origin | A plain rotation always pivots around | Translate to the origin, rotate, translate back; or use a homogeneous matrix |
| Screen coordinates where points down | Positive angles look clockwise on the screen | Keep the same matrix but know the convention, or flip the sign of |
Two practical warnings. First, a matrix with determinant looks like a rotation but reflects, so check when you load matrices from outside. Second, in code, angles are almost always in radians, while people often think in degrees. Passing where the function expects radians rotates by about 1719 degrees (30 radians), which is a common bug.
History
Leonhard Euler showed in the 1770s that any rotation of three-dimensional space is a rotation about some single axis, and he developed the angle-based description that now bears his name. The matrix form came later, once matrix algebra was being formalised. Arthur Cayley and others in the 1850s treated matrices as objects in their own right, which made it natural to write a rotation as a single array of numbers.
William Rowan Hamilton's quaternions, introduced in 1843, gave a different and very compact way to describe 3D rotations. Quaternions avoid gimbal lock and interpolate smoothly, and they are still standard in aerospace and computer graphics. Rotation matrices stayed the everyday tool for physics and engineering, and they became ubiquitous when computer graphics and robotics needed to move objects in space many times per second.
Check yourself
QuestionWrite the 2D rotation matrix for an angle , and say which way it turns vectors when is positive.Show answer
. With positive, it turns vectors counterclockwise in the standard - orientation.
QuestionRotate the vector by counterclockwise. What do you get?Show answer
Using and : the x-entry is , and the y-entry is . The result is . The length is 2, as expected.
QuestionWhy is the inverse of a rotation matrix equal to its transpose, and what property of the columns guarantees this?Show answer
The columns of a rotation matrix are orthonormal: each has length 1 and they are perpendicular. That means , because the dot product of column with column is 1 when and 0 otherwise. Multiplying on the right by gives .
QuestionA sprite on a game screen should turn to face a new direction by a positive angle . The screen's -axis points down. Will a standard rotation matrix with that turn the sprite clockwise or counterclockwise as seen on screen, and what would you change?Show answer
The matrix is the same, and the mathematical rotation is counterclockwise in - coordinates. Because points down, that appears clockwise on screen. To get the visual direction you want, either negate the angle or flip the sign of the -axis when you convert between world and screen coordinates. Pick one convention and keep it consistent across the code.