Chapter 4
Matrices as Transformations
You've seen 2x2 grids of numbers everywhere. In code, in textbooks, in API docs. But a matrix isn't just numbers arranged in a box -- it's a snapshot of a transformation, frozen in notation.
The last chapter showed that a linear transformation is fully determined by what it does to the basis vectors. This chapter makes that idea concrete: the basis vectors' landing spots become the columns of the matrix. That's the entire connection between "transformation" and "matrix." Once you see it, matrix-vector multiplication stops being a memorized formula and starts being obvious.
The basis vectors that define everything
Before any transformation happens, we need to see what we're working with. The standard basis vectors are and . Every vector in the plane is some combination of these two.
The vector ? That's . The vector ? That's . These two basis vectors are the ingredients, and the coordinates are the recipe.
These two basis vectors define the coordinate system. Every other vector is a combination of them.
Where do the basis vectors land?
Now apply a linear transformation. We don't need to describe what happens to every single point. We just need to say where and end up. Everything else follows.
Suppose lands at and lands at . The original basis vectors are shown dashed. The new positions are shown solid. Notice how the entire grid has been warped -- but it's still made of straight, evenly-spaced lines. That's the signature of a linear transformation.
A transformation is completely described by where and land.
Reading the matrix
Here's the key move. Take those two landing spots and pack them into columns:
The first column is where lands. The second column is where lands. That's it. That's what a matrix is.
The first column is the new . The second column is the new .
Every time you see a 2x2 matrix, you can read it as a transformation. The left column tells you where the horizontal basis vector goes. The right column tells you where the vertical basis vector goes. The matrix is the transformation.
Applying the matrix to a vector
Now for the payoff. Take a vector . Before the transformation, that means -- one part , two parts .
After the transformation, the recipe stays the same but the ingredients change. We still want one part of the first basis vector and two parts of the second. But now those basis vectors have moved:
Multiply = "take x of the first column, plus y of the second." That's it.
The blue arrow is 1 copy of the new (which is ). The green arrow is 2 copies of the new (which is ). Add them up and you get the orange result: .
Matrix-vector multiplication isn't some arbitrary rule. It's just saying: "use the same recipe with the new ingredients."
The formal bit
Here's the general formula. A matrix times a vector:
You might have learned this as "row times column" -- multiply across, add up. That procedure gives the right answer, but it hides the meaning. The column view makes the meaning visible: scales the first column, scales the second column, and you add the results.
Think of it this way: the input coordinates tell you the recipe -- how much of each basis vector you need. The matrix columns are the ingredients -- the new basis vectors. Same recipe, different ingredients.
This also makes it clear why matrix-vector multiplication is linear. Scaling the input just scales the recipe. Adding two inputs adds two recipes. The structure is preserved because you're always just combining columns.
Worked example: UI scaling
Suppose you're building a drawing tool and the user drags a resize handle that doubles the width and halves the height. What matrix describes this transformation?
The horizontal basis vector should map to -- stretched horizontally. The vertical basis vector should map to -- compressed vertically. Pack those into columns:
Apply this to the four corners of a unit square:
The unit square becomes the rectangle .
The unit square stretched to double width, half height. A diagonal matrix scales each axis independently.
Notice something about that matrix: it's diagonal. When a matrix is diagonal, the axes don't mix. only affects , and only affects . That's because the new still points along the -axis (just longer), and the new still points along the -axis (just shorter). Diagonal matrices are pure scaling -- no rotation, no shearing.
In code, this is the matrix you'd pass to a transform function when a user resizes an element. And now you know exactly what those four numbers mean.
Key Takeaway: A matrix is a transformation written down. Its columns tell you where the basis vectors land. Matrix-vector multiplication is just a linear combination of those columns -- same recipe, different ingredients.
What's next
We can describe a single transformation as a matrix. What happens when we apply one transformation after another? You might guess we multiply the matrices -- and you'd be right. But why does matrix multiplication work the way it does, and why does the order matter? That's Chapter 5: Matrix Multiplication -- composition of transformations.