liveBook · Manning

Rotation

As explained in Geometry for Programmers

A rotation is a geometric transformation that turns points around a fixed center, axis, or origin while preserving distances and angles.

Rotation turns a plane around a fixed point. In the standard 2D form, that point is the origin: every input coordinate (xi, yi) becomes a new coordinate (xr, yr) at an angle t measured in radians. It is one of the common transformations used in graphics and design. section 4.1.3

Figure 4.5 Three examples of standard square rotations. All rotations go around the zero point (0, 0).
04-05

Square positions make the central rule visible: the shape turns, while the zero point (0, 0) stays fixed. section 4.1.3

Use the coordinate formulas xr = cos(t)·xi + sin(t)·yi and yr = -sin(t)·xi + cos(t)·yi. The sine and cosine terms determine how much each original coordinate contributes after the turn. Getting those terms swapped is an easy mistake, so relate them to the geometry rather than memorizing an isolated pattern. section 4.1.3

A practical way to reason about the formula is to check its ingredients:

  • The angle t is in radians. section 4.1.3
  • Sine is continuous, periodic with period 2π, and odd: sin(-x) = -sin(x). section 4.1.3
  • For small x, sin(x) is approximately x; the stated example at x = 0.244 has about 1% relative difference. section 4.1.3
  • A rotation about a shape's center can be expressed as a composition of transformations rather than as a separate special case. section 4.1.3

Homogeneous coordinates turn rotation, translation, scaling, shear, and perspective into instances of matrix multiplication. This is useful when several operations must run together: multiply their matrices into one composite transformation, then apply that one matrix to each point. The same approach extends to 3D, where homogeneous points and vectors have four components and transformations use 4 × 4 matrices. section 4.3.2 section 4.7

Rotate, translate, then translate back

A center rotation can be assembled from three matrices: translate the intended center to the origin, apply a rotation matrix, then translate back. For example, matrices a1, a2, and a3 are multiplied as c = a3*a2*a1. Applying c to the four corners of a rectangle produces its transformed corners with one matrix-vector multiplication per point. section 4.3.2

Matrix form also makes reversal systematic. Projective transformations compose into another single projective transformation and have inverse operations, so an inverse transformation can map transformed points back. In homogeneous space, multiplying a matrix or point coordinates by a nonzero scalar can represent the same point or transformation mathematically. section 4.3.2 section 4.7

Choose the direct formula when rotating an individual 2D point is all that is needed. Choose homogeneous transformation matrices when rotation must share an implementation with translation, scaling, or other composable operations; that avoids maintaining separate routines for every partial case. section 4.1.3 section 4.3.2

How Geometry for Programmers covers it

How deep it goes
Derives a 2D coordinate formula, reviews sine behavior, and develops homogeneous matrix composition through 3D extensions.
Examples
Uses rotated squares, a center-rotation composition, and a rectangle transformed by composed SymPy-style matrices.
What it assumes
Introduces a sine-and-cosine reminder before using radians and rotation coordinates; no advanced prerequisite is stated.
What you can do after
Build it from scratch, apply 2D rotation formulas, and combine rotations with other transformations as one matrix.
How it connects
Connects rotation to translation, scaling, shear, projective transformations, homogeneous coordinates, matrix multiplication, and inverse transformations.

Also explained in

Compare how 4 books explain rotation →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Geometry for Programmers. The section links point to the parts of the book it draws on.