TactivergeLite

Lite / Textbooks / The Mathematics of Machines / Chapter 5

5. Matrices and transformations

Version 1 · Technically checked (automated checks only) · 3 source lessons · Full interactive version

Introduction

A 2×2 matrix is a machine that takes in a vector and gives back a moved one. Its columns tell you where the two axis arrows land, which is enough to know where everything else goes. This chapter multiplies matrices and vectors, builds the rotation matrix from scratch, and shows why the order of two transformations matters and how to undo one.

Figure 5.1. Where the columns land (described in words)

A unit square with corners (0,0), (1,0), (1,1), (0,1) is transformed by the matrix with columns (1, 0) and (1, 1). The first axis arrow stays at (1, 0), the second moves to (1, 1), and the square becomes a parallelogram with the same area, because the determinant is 1.

Explanation

Built from 3 School lessons. Each part is the lesson's own explanation.

5.1 A matrix is a machine that moves vectors

Four numbers in a box can rotate, stretch, shear or flip an entire plane at once. How do they know where everything goes?

The recipe

For M = [a b; c d] and v = (x, y): M·v = (a·x + b·y, c·x + d·y). Each output component is one row of M dotted with v. A 2×2 matrix takes a 2D vector to another 2D vector.

Columns are where the axes land

M·(1, 0) = (a, c), the first column. M·(0, 1) = (b, d), the second column. Any vector (x, y) = x·(1, 0) + y·(0, 1), so M·v = x·(column 1) + y·(column 2). To design a matrix, decide where (1, 0) and (0, 1) should go and write those as columns. Grid lines stay straight, parallel and evenly spaced: that's what 'linear' means.

The determinant

det M = ad − bc is the factor by which areas change. det = 1: areas kept (rotations). det = 2: doubled. Negative: the plane is flipped over (a mirror image). det = 0: the plane is squashed onto a line or a point, information is lost, and the matrix cannot be undone.

Common mix-ups

Open the Lite lesson: A matrix is a machine that moves vectors

5.2 The rotation matrix, built from scratch

Every robot, game engine and spacecraft turns things with the same four entries: cos, −sin, sin, cos. Where does that minus sign come from?

Using R(θ)

To rotate a point about the origin by θ (anticlockwise positive): x′ = x cos θ − y sin θ, y′ = x sin θ + y cos θ. For a clockwise rotation, use a negative θ: cos stays the same, sin changes sign. To rotate about some other pivot, shift the pivot to the origin, rotate, then shift back.

What makes it a rotation

Its columns are unit length and perpendicular to each other, so lengths and angles are kept (it is 'orthogonal'), and det = 1, so it doesn't mirror. A matrix with orthonormal columns but det = −1 is a reflection, not a rotation.

Same matrix, two stories

R(θ)·p can mean 'turn the point p by θ' or 'p is given in a frame turned by θ; here it is in the outer frame'. Both are the same calculation. Robotics uses the second story constantly: a link frame rotated by θ1 turns the link's own coordinates into the base frame's.

Derivation: Deriving R(θ)
  1. A matrix is fixed by where it sends (1, 0) and (0, 1): those images are its columns.

  2. Rotating (1, 0) by θ lands on the unit circle at angle θ: (cos θ, sin θ). That's column 1.

  3. (0, 1) starts at 90°, so after rotating it is at θ + 90°: (cos(θ + 90°), sin(θ + 90°)) = (−sin θ, cos θ). That's column 2, and the source of the minus sign.

  4. So R(θ) = [cos θ −sin θ; sin θ cos θ], and R(θ)·(x, y) = (x cos θ − y sin θ, x sin θ + y cos θ).

  5. Check lengths: (x cos θ − y sin θ)² + (x sin θ + y cos θ)² = x²(cos² + sin²) + y²(sin² + cos²) + (cross terms that cancel) = x² + y². Lengths are kept.

  6. Check area: det R = cos θ · cos θ − (−sin θ) · sin θ = cos²θ + sin²θ = 1. No stretching, no flipping.

Common mix-ups

Open the Lite lesson: The rotation matrix, built from scratch

5.3 Order matters: composing and undoing matrices

Shear then rotate, or rotate then shear? A robot's hand ends up in a different place. Why should order matter for multiplication?

Multiplying matrices

(A·B) entry in row i, column j = row i of A · column j of B. For 2×2: [a b; c d]·[e f; g h] = [ae + bg af + bh; ce + dg cf + dh]. The product A·B means 'first B, then A', because (A·B)·v = A·(B·v): the matrix nearest the vector acts first.

Order matters

In general A·B ≠ B·A. Physical intuition: put a book flat, rotate it 90° about a vertical axis, then flip it about a front-to-back axis; now do it the other way round. Different result. Planar rotations happen to commute, R(α)R(β) = R(α + β) = R(β)R(α), but mix in a shear, a scale or 3D rotations and order becomes everything.

Undoing: the inverse

The inverse M⁻¹ satisfies M⁻¹·M = I (the identity, [1 0; 0 1]). For 2×2: M⁻¹ = (1/det)·[d −b; −c a], which exists only when det ≠ 0. For rotations it is beautifully cheap: R(θ)⁻¹ = R(−θ) = R(θ)ᵀ (swap rows and columns). Undoing a turn is turning back.

Common mix-ups

Open the Lite lesson: Order matters: composing and undoing matrices

Worked examples

A matrix is a machine that moves vectors: example 1

Find [2 −1; 1 3]·(4, −2).

Solution

Row 1: 2×4 + (−1)×(−2) = 8 + 2 = 10. Row 2: 1×4 + 3×(−2) = 4 − 6 = −2. Answer (10, −2).

The rotation matrix, built from scratch: example 1

Rotate (3, 4) by 90° clockwise.

Solution

θ = −90°: cos = 0, sin = −1. x′ = 3×0 − 4×(−1) = 4, y′ = 3×(−1) + 4×0 = −3. (4, −3): length still 5.

Order matters: composing and undoing matrices: example 1

Find the inverse of M = [2 1; 5 3] and check it.

Solution

det = 6 − 5 = 1. M⁻¹ = [3 −1; −5 2]. Check row 1 · col 1: 3×2 + (−1)×5 = 1; row 1 · col 2: 3×1 + (−1)×3 = 0. ✓

Interactive figures, in words

Figure 5.2 from A matrix is a machine that moves vectors

Try each preset and describe it in words. Then choose Custom and build: (a) a matrix that triples heights only, (b) one that swaps x and y, (c) one that squashes the plane onto a line. For each, watch where the orange (1, 0) and green (0, 1) arrows land, and the determinant.

The matrix grid shows the plane before (fine grid) and after (blue grid) applying the matrix. An orange arrow shows where (1, 0) lands, a green arrow where (0, 1) lands, and a purple patch shows the transformed unit square. A test point (1.5, 1) and its image P′ are joined by a dashed arrow. The readout lists the matrix, both columns, P′ and the determinant.

The interactive versions are in the full chapter.

Laboratory

These run in a browser on the full site (they need a faster connection). Simulations are simplified educational models.

Practice

Each question links to its Lite lesson, where your answer is checked on our server and a wrong answer gets a hint. Answers are never sent to your device.

  1. [3 1; 0 2]·(2, 5): what is the first component?
    Answer it in “A matrix is a machine that moves vectors”
  2. Which matrix sends (1, 0) to (0, 2) and (0, 1) to (−1, 0)?
    Answer it in “A matrix is a machine that moves vectors”
  3. What is the determinant of [4 2; 3 1]?
    Answer it in “A matrix is a machine that moves vectors”
  4. Which matrix is R(90°)?
    Answer it in “The rotation matrix, built from scratch”
  5. The point (5, 12) is rotated by 73°. What is its distance from the origin afterwards?
    Answer it in “The rotation matrix, built from scratch”
  6. Rotate (3, 1) by 90° about the pivot (2, 1) (not the origin). What is the new y coordinate?
    Answer it in “The rotation matrix, built from scratch”
  7. [1 2; 3 4]·[5 6; 7 8]: what is the entry in row 2, column 1?
    Answer it in “Order matters: composing and undoing matrices”
  8. In A·B·v, which transformation is applied to v first?
    Answer it in “Order matters: composing and undoing matrices”

Engineering applications

Robot frames

A camera on a robot arm sees the world in its own frame. A chain of rotation (and translation) matrices converts what it sees into the frame of the robot's base.

Graphics and screens

Every rotated, scaled or sheared shape on a screen is drawn by multiplying its corner coordinates by a matrix, usually millions of times a second.

Watch (optional)

Streaming video uses a lot of data. Everything you need is in the text.

Summary

Glossary

Matrix multiplication
Multiplying matrices combines rows of the first with columns of the second: each entry of the result is a dot product of a row and a column. Field Guide
2D rotation matrix
A 2D rotation by angle θ anticlockwise maps (x, y) to (x cos θ − y sin θ, x sin θ + y cos θ), written as a 2×2 matrix. Field Guide
Vector addition
Vectors are added component by component: the x parts add, the y parts add, and the result is the single vector with the same effect as both. Field Guide

Project: A two-joint arm with matrices

Compute the tip position of a two-link planar arm for three pairs of joint angles using rotation matrices. Then swap the order of the two rotations in your calculation and show, with numbers, that the answer changes.

Deliverables

Write it up on paper or in your own notes. Lite never stores what you write.

References

Further reading from the lessons

← 4. Vectors6. Rates of change →