Skip to the lesson
FixTheRobot Explore Robotics / Linear Algebra / M7 Rotations and Rigid-Body Transformations / M7-T2

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.

  • Lesson 2 of 9
  • Module 7: Rotations and Rigid-Body Transformations
  • Rotations and rigid bodies
  • About 7 minutes to read

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.

Columns of a rotation matrixRotating the plane by theta sends the first basis vector to cos theta, sin theta and the second basis vector to minus sin theta, cos theta. Those two images are the columns of the rotation matrix. R e₁ = (cos θ, sin θ) R e₂ = (−sin θ, cos θ) e₁e₂ R(θ) = [ cos θ   −sin θ                  sin θ   cos θ ] Rᵀ R = I, det R = +1R(α) R(β) = R(α + β)R(θ)⁻¹ = R(−θ) = R(θ)ᵀ
The columns of R(θ) are the rotated basis vectors; the properties follow from them.

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.

This matrix is a rotation by 30°: the arrows are its columns, the unit square is turned rigidly and the shape keeps its size and handedness. Tick the box to see the inverse rotation undo it. Then edit the entries so the columns are no longer perpendicular unit vectors and watch it stop being a rotation.

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

  1. Matrix. The point at angle θ on the unit circle is (cos θ, sin θ), so R e₁ = (cos θ, sin θ). The vector e₂ is e₁ turned by 90°, so R e₂ is that image turned by 90° as well: (cos(θ + 90°), sin(θ + 90°)) = (−sin θ, cos θ).
  2. Orthonormal columns. (cos θ)² + (sin θ)² = 1 for each column, and (cos θ)(−sin θ) + (sin θ)(cos θ) = 0. Orthonormal columns mean RᵀR = I, hence R⁻¹ = Rᵀ.
  3. Determinant. det R = cos θ cos θ − (−sin θ)(sin θ) = cos²θ + sin²θ = 1.
  4. Composition. Multiply: the (1,1) entry of R(α)R(β) is cos α cos β − sin α sin β = cos(α + β) and the (2,1) entry is sin α cos β + cos α sin β = sin(α + β), by the angle-addition identities. The other two entries follow the same way, so R(α)R(β) = R(α + β), which also equals R(β)R(α).
  5. Inverse. Setting β = −α in the composition rule gives R(α)R(−α) = R(0) = I, and R(−α) 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 be R(75°): the (1,1) entry is cos 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 with R(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

  1. R(θ) = [[cos θ, −sin θ], [sin θ, cos θ]]: its columns are the rotated basis vectors.
  2. Rᵀ R = I and det R = 1, so R⁻¹ = Rᵀ = R(−θ).
  3. R(α)R(β) = R(α + β): in 2D the order of rotations does not matter.
  4. ᵂv = R(θ)ᴮv converts robot-frame vectors to the world; the transpose converts back.
  5. Use atan2 and wrap angle differences; track degrees versus radians.

References and further reading

Primary papers and authoritative documentation.

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.

Next lesson

M7-T3 — Three-Dimensional Rotation Matrices

Build rotations about the coordinate axes and compose them, noting that the order matters.

Nothing below is required to finish this lesson.

  • Before
    M7-T1: Coordinate Frames

    Define a coordinate frame, name the frames of a mobile robot, and say what a transform between two frames means.