Linear Algebra · Theory · M7
M7-T2 — Two-Dimensional Rotations
A 2D rotation is the simplest rigid motion: a matrix with the cosine and sine of one angle, whose inverse is its transpose.
The plane rotation matrix is the building block of mobile-robot kinematics and of every 3D rotation to come. Deriving it from the columns, and checking its properties by hand, makes the 3D case a straightforward extension.
Learning objectives
After this lesson, you should be able to:
- Derive R(θ) from the images of the two basis vectors.
- Prove R(α)R(β) = R(α + β), Rᵀ = R⁻¹ and det R = 1.
- Rotate points and convert robot-frame vectors to world coordinates.
- Recognise that 2D rotations commute but that angles must be wrapped.
Introduction and motivation
A differential-drive robot with heading θ moves forward in its own x direction; the world sees ẋ = v cos θ, ẏ = v sin θ. Converting a LiDAR bearing, a velocity command or a goal point between the robot and world frames is a 2D rotation each time. Pure pursuit, the Stanley controller and every 2D SLAM front end use exactly this matrix, so it is worth understanding rather than memorising.
The intuition
To know what a linear map does to the whole plane, ask what it does to the two basis vectors; their images are the columns. A rotation by θ turns e₁ = (1, 0) into (cos θ, sin θ) (a point on the unit circle at angle θ) and turns e₂ = (0, 1), which is already 90° ahead, into (−sin θ, cos θ). Place them as columns and you have the matrix.
Interactive figure. The unit square and an F-shaped outline transformed by a matrix. With entries cos 30, minus sin 30, sin 30, cos 30 the shape is only turned, not stretched. Editing the entries breaks that. This figure needs JavaScript to be interactive.
Geometric and physical interpretation
Geometric view. A rotation preserves lengths and angles and does not flip orientation: the image of a shape is congruent to it and has the same handedness. Positive θ is counter-clockwise when viewed with x to the right and y up. Physical view. The same matrix can describe turning an object by θ (active) or re-describing fixed coordinates in a frame turned by θ (passive, which uses R(−θ) = R(θ)ᵀ). For a robot with heading θ, ᵂv = R(θ) ᴮv converts a body-frame vector to the world.
The mathematics
- θ
- the rotation angle in radians, counter-clockwise positive.
- R(θ)
- the 2 × 2 rotation matrix.
- e₁, e₂
- the standard basis vectors (1, 0) and (0, 1).
The rotation matrix
R(θ) = [ cos θ −sin θ ; sin θ cos θ ]
What it means. Column 1 is where (1, 0) goes, column 2 is where (0, 1) goes. Multiply by a point to rotate it about the origin.
Properties
R(α) R(β) = R(α + β) R(θ)ᵀ R(θ) = I det R(θ) = 1 R(θ)⁻¹ = R(−θ) = R(θ)ᵀ
What it means. Rotations add their angles when composed, so in 2D the order does not matter. The inverse never needs a general inversion: transpose it. Determinant +1 means no reflection.
The robot-to-world conversion
ᵂv = R(θ) ᴮv ᴮv = R(θ)ᵀ ᵂv
What it means. The first line expresses a vector measured on the robot in world axes; the second does the reverse with the transpose.
R(θ) has columns (cos θ, sin θ) and (−sin θ, cos θ). Its inverse is its transpose, its determinant is 1, and in 2D rotations add their angles.
Step-by-step derivation: the matrix and its properties
- Matrix. The point at angle θ on the unit circle is
(cos θ, sin θ), soR e₁ = (cos θ, sin θ). The vectore₂is e₁ turned by 90°, soR e₂is that image turned by 90° as well:(cos(θ + 90°), sin(θ + 90°)) = (−sin θ, cos θ). - Orthonormal columns.
(cos θ)² + (sin θ)² = 1for each column, and(cos θ)(−sin θ) + (sin θ)(cos θ) = 0. Orthonormal columns meanRᵀR = I, henceR⁻¹ = Rᵀ. - Determinant.
det R = cos θ cos θ − (−sin θ)(sin θ) = cos²θ + sin²θ = 1. - Composition. Multiply: the (1,1) entry of
R(α)R(β)iscos α cos β − sin α sin β = cos(α + β)and the (2,1) entry issin α cos β + cos α sin β = sin(α + β), by the angle-addition identities. The other two entries follow the same way, soR(α)R(β) = R(α + β), which also equalsR(β)R(α). - Inverse. Setting
β = −αin the composition rule givesR(α)R(−α) = R(0) = I, andR(−α)has the same cosines but opposite sines: the transpose.
Eigenvalues. The characteristic polynomial is λ² − 2 cos θ λ + 1 = 0 with roots cos θ ± i sin θ = e^(±iθ): no real eigenvector (except for θ = 0 or 180°), because every direction turns. The complex eigenvalue exposes the angle, as in the characteristic-equation lesson.
Wrapping. Angles that differ by 2π give the same matrix, so headings are only defined modulo 2π. After adding or subtracting angles, wrap them to (−π, π] (for example with atan2(sin θ, cos θ)), or an error of 359° looks like a huge mistake when it is really 1°.
Rotation about a point. Rotating about a centre c rather than the origin is p′ = c + R(p − c): translate to the origin, rotate, translate back. This hint at the affine structure is made systematic by homogeneous coordinates in lesson 5.
A worked example: rotating points and composing rotations
- A point. Rotate
(1, 0)by 30°:R(30°) = [[0.866, −0.5], [0.5, 0.866]], so the result is(0.866, 0.5). - Another point. Rotate
(2, 1)by 90°:R(90°) = [[0, −1], [1, 0]]gives(−1, 2). The length is √5 before and after ✓. - Composition.
R(30°) R(45°)should beR(75°): the (1,1) entry iscos 30° cos 45° − sin 30° sin 45° = 0.6124 − 0.3536 = 0.2588 = cos 75°✓. - Inverse.
R(30°)ᵀ = [[0.866, 0.5], [−0.5, 0.866]], and multiplying withR(30°)gives the identity ✓. - Robot to world. A robot with heading 60° sees a landmark 3 m ahead and 1 m to its left,
ᴮv = (3, 1). Thenᵂv = R(60°)(3, 1) = (3·0.5 − 1·0.866, 3·0.866 + 1·0.5) = (0.634, 3.098); the length is √10 = 3.162 ✓. - Wrapping. A heading error of
350° − 10° = 340°wraps to−20°.
Robotics application
Mobile robots. Unicycle and bicycle kinematics are ẋ = v R(θ) e₁. Pure pursuit rotates the goal into the robot frame before computing curvature; see pure pursuit and Stanley and cross-track control.
LiDAR. A beam with bearing β and range r gives (r cos β, r sin β) in the sensor frame, which a 2D scan matcher rotates by the estimated heading; see rigid transforms in 2D.
UAVs. The yaw part of attitude is a 2D rotation about the vertical axis; heading-hold controllers work with the wrapped yaw error.
IMU and GPS. Integrating a gyro's yaw rate gives θ; a GPS velocity or magnetometer gives an independent heading, and fusing them means differencing wrapped angles.
Engineering implications and limitations
Practical rules
- Use atan2, never atan.
atan2(y, x)gives the correct quadrant;atan(y/x)loses the sign and fails at x = 0. - Wrap angle differences. Compute
atan2(sin(a − b), cos(a − b)). A raw subtraction near ±180° produces errors of 360°. - Mind the units. Libraries use radians; sensors and humans use degrees. A stray factor of 57.3 is a very common bug.
- Re-normalise the pair (cos, sin). If you integrate a rotation matrix numerically it drifts; recompute it from the angle, or normalise the first column and rebuild the second.
- Check handedness. A flipped y-axis (image coordinates, y down) turns “counter-clockwise” into “clockwise”; carry the sign convention in a comment.
Limits
2D rotations commute and are a one-parameter group, so they hide the difficulties of 3D (non-commutativity, gimbal lock). Do not generalise 2D intuition to 3D without checking, as the next lessons show.
Common misconceptions
“R(θ) rotates the frame by θ.”
It rotates points by θ (active). The coordinates of a fixed point in a frame turned by θ are given by R(−θ) = R(θ)ᵀ.
“Angles can just be added and subtracted freely.”
Angles live on a circle: 359° and −1° are the same heading, so differences must be wrapped.
“The inverse of a rotation needs a matrix inversion routine.”
Transposing is enough, and faster and exact.
“A matrix with cos and sin entries is always a rotation.”
Check the signs: [[cos, sin], [sin, cos]] is not a rotation, and its determinant is cos² − sin², not 1.
Engineering takeaways
- R(θ) = [[cos θ, −sin θ], [sin θ, cos θ]]: its columns are the rotated basis vectors.
- Rᵀ R = I and det R = 1, so R⁻¹ = Rᵀ = R(−θ).
- R(α)R(β) = R(α + β): in 2D the order of rotations does not matter.
- ᵂv = R(θ)ᴮv converts robot-frame vectors to the world; the transpose converts back.
- Use atan2 and wrap angle differences; track degrees versus radians.
References and further reading
Primary papers and authoritative documentation.
- Modern Robotics (Lynch and Park), free preprint: chapter 3.2, rotation matrices (SO(2) in the planar case)
- MIT 18.06SC Linear Algebra (OCW): lecture on orthogonal matrices and rotations
- Boyd and Vandenberghe, Introduction to Applied Linear Algebra (VMLS): geometric transformations: rotation; the site did not load when we last checked
- UCSD ECE276A: Sensing and Estimation in Robotics: 2D rotations and rigid transformations
Knowledge check
Three conceptual questions. Write an answer, then reveal the explanation. Your answers stay in your browser.
Question 1
Rotate (4, 0) by 120° and give the result and its length.
Explanation
R(120°) = [[−0.5, −0.866], [0.866, −0.5]], so the result is 4·(−0.5, 0.866) = (−2, 3.464). Length √(4 + 12) = 4 ✓ (lengths are preserved).
Question 2
A robot with heading −90° sees a cone 2 m ahead (ᴮv = (2, 0)). Where is the cone in world axes relative to the robot, and which way is the robot facing?
Explanation
R(−90°) = [[0, 1], [−1, 0]], so ᵂv = (0, −2): the cone is 2 m in the −y direction. The robot faces −y (heading −90°), so ahead is −y ✓.
Question 3
Two headings are 175° and −170°. What is the smallest signed difference from the second to the first, and what goes wrong with a raw subtraction?
Explanation
Raw: 175 − (−170) = 345°, which suggests a big error. Wrapped: 345° − 360° = −15°. The headings differ by only 15°; the wrapped value is what a controller should use.
What’s next
The 2D rotation has one angle. In 3D a rotation has three degrees of freedom, there is no single angle, and the order of turns matters. The next lesson builds the rotation matrices about each axis and shows exactly how order enters.
Related content
Nothing below is required to finish this lesson.
- BeforeM7-T1: Coordinate Frames
Define a coordinate frame, name the frames of a mobile robot, and say what a transform between two frames means.
Get notified when the next lesson and new labs are released.
One email per new lesson or lab.