Matrices: Grids That Act on Vectors
When a crate thumps onto a deck, Harbour Hopper squashes its sprite for a moment — wider and shorter — before it springs back. Every corner of the crate moves by the same rule, and games write rules like that as a small grid of numbers: a matrix.
The rule
Each output number is one row dotted with the vector.
A 2×2 matrix has two rows and two columns. Multiplying it by a vector gives a new vector, and each output number is the dot product of one row with the input:
The landing squash is . The crate's top-right corner, measured from the crate's centre, becomes : half as wide again, and half as tall.
The identity matrix leaves every vector alone. It's the "do nothing" rule, and it's where the squash ends up when the crate has recovered.
Sizes must match: a matrix needs as many columns as the vector has components. A 2×2 acts on 2D vectors, a 3×3 on 3D ones. Two matrices can also be multiplied together into a single matrix that does both jobs, which the next lessons rely on.
Why a grid rather than a formula? A matrix is data. The game can store it, pass it around, send it to the graphics card, and apply the very same one to every corner of every crate in a stack: thousands of vectors, one rule.
The shortcut
Run along the row, down the vector: pair the numbers up, multiply each pair, add. One row gives one output number.
Top row
(2, 1) with (4, −1): 2 × 4 + 1 × (−1) = 8 − 1 = 7.
The trap is pairing the vector with the columns instead of the rows. For this matrix that gives , a different and wrong answer. It's the classic transposition slip, and the "along the row" chant prevents it.
Drills
Answer fast — trust the rule.
What does the identity matrix, rows (1, 0) and (0, 1), do to (7, −2)?
The landing squash has rows (1.5, 0) and (0, 0.5). Where does the corner (2, 2) go?
Multiply the matrix with rows (1, 2) and (−1, 0) by the vector (3, 4).
Which vector can a 3×3 matrix multiply?
Remember
- Matrix times vector: each output number is one row dotted with the vector.
- The identity matrix changes nothing; a 2×2 acts on 2D vectors, a 3×3 on 3D ones.
- Trap: pairing with columns instead of rows gives a different, wrong answer.
