Capstone — Linear Algebra in Practice
Linear Algebra Fundamentals
Chapter 10 · Capstone — Linear Algebra in Practice
One continuous worked project, touching every chapter of this course in the order a real engineer would actually reach for each idea: building a small 2D sprite transform pipeline for a game, then using the exact same mathematics to analyze where players click on the resulting screen.
Part 1 — A Sprite Transform Pipeline
A sprite sits at world position p = [10, 5], facing along f = [1, 0]. The player is at q = [13, 9], so the direction from the sprite to the player is d = q − p = [3, 4], magnitude 5. The dot product f · d = 3 is positive, and cos(θ) = 3/(1×5) = 0.6, giving θ ≈ 53.1° — the player is roughly ahead of the sprite, well within a typical detection cone.
Knowing the player is roughly ahead isn't enough for AI logic — turning left or right needs a side. The 2D pseudo-cross-product from Chapter 3, f₁d₂ − f₂d₁ = (1)(4) − (0)(3) = 4, is positive, meaning d is counter-clockwise from f — the player is to the sprite's left. This single sign is the entire "which way should the AI turn" decision.
This sprite needs to render mirrored (it's facing left in its base art) and scaled up 1.5×. Combining a flip matrix Flip = [[-1, 0], [0, 1]] and a scale matrix Sc = [[1.5, 0], [0, 1.5]] uses Chapter 4's real matrix multiplication, not entry-wise multiplication — and here, Flip × Sc = Sc × Flip = [[-1.5, 0], [0, 1.5]].
A × B ≠ B × A "in general" — and diagonal matrices are exactly the honest exception: since each only scales along its own axis independently, two diagonal matrices always commute. It's still worth combining them with real matrix multiplication rather than assuming this always holds — the moment a rotation enters the mix, order matters again immediately.
Packaging the combined flip-and-scale matrix together with the translation to p = [10, 5] needs Chapter 5's homogeneous coordinates: T = [[-1.5, 0, 10], [0, 1.5, 5], [0, 0, 1]]. Applying T to the sprite's own local origin [0, 0, 1] gives [10, 5, 1] — exactly Step 1's world position p, confirming the transform is correct. Applying it to a corner point of the sprite's local bounding box, [2, 1, 1], gives [7, 6.5, 1] — that corner's actual position in the world.
The renderer needs a mapping from world x-coordinates to screen pixels, pixel = m·world + c. Two known calibration points — world 2 → pixel 100, world 5 → pixel 250 — give the system 2m + c = 100, 5m + c = 250. Gaussian elimination (R2 → R2 − 2.5·R1) gives 0m − 1.5c = 0 → c = 0, then back-substitution gives 2m = 100 → m = 50. So pixel = 50 × world — checked against both original points.
A player clicks at world point [7, 6.5] — Step 4's own transformed corner. Before inverting, check the sprite's transform isn't degenerate: det([[-1.5, 0], [0, 1.5]]) = -2.25, nonzero — safe to invert. The inverse is [[-2/3, 0], [0, 2/3]]. Subtracting the translation first ([7,6.5] − [10,5] = [-3, 1.5]) and applying the inverse gives [2, 1] — exactly Step 4's original local corner. The click round-trips perfectly back to sprite-local space.
The control scheme offers three inputs: up = [0, 1], right = [1, 0], and a diagonal up-right = [1, 1] (both keys held at once). Row-reducing the three as rows shows up + right = [1, 1] = up-right exactly — the third row reduces to [0, 0]. Rank 2, not 3: the diagonal input adds no genuinely new reachable direction beyond combining the other two, which is exactly what a player pressing both keys already produces.
Part 2 — Feeding Into Player-Click Analysis
A UI element sits at the sprite's own world position, [10, 5] (Step 1). Four recorded player clicks, centered around it, come out (relative to that center) as (1,1), (-1,-1), (2,2), (-2,-2) — every click lies exactly on the line y = x. Computing the covariance matrix from these points: Cov = [[2.5, 2.5], [2.5, 2.5]].
Solving the characteristic equation (trace 5, det 0): λ² − 5λ = 0 → λ = 0 or λ = 5.
| λ | Eigenvector | What it means |
|---|---|---|
| 5 | [1, 1] | The direction of maximum spread — all the click variance lives along this diagonal |
| 0 | [1, -1] | Zero spread perpendicular to that diagonal — this direction carries no information at all |
[1, 1] — with zero information lost. This synthetic dataset was deliberately built to be this clean; real click data is essentially never perfectly lossless like this, but the mechanism — eigenvectors of a covariance matrix ranking directions by variance — is exactly what a real PCA-based dimensionality reduction tool does at scale.
This is, in essence, exactly what a real 2D game engine's rendering pipeline and its analytics tooling both look like under the hood — every step traceable to a specific chapter of this course, none of it abstract math floating free of the actual code.
What This Course Doesn't Cover
In the interest of an honest accounting: calculus-based optimization (how gradient descent's update rule is actually derived), formal vector space theory (axiomatic proofs over abstract fields), and numerical stability at scale were all named in Chapter 1 as deliberately out of scope, each reserved for its own future course under this same Maths for Programmers subject — Calculus & Optimization, and Numerical Methods & Floating-Point Computation respectively. This course is the direct, concrete foundation those subjects will each build on, not a substitute for studying them when their own turn comes.
This Course's Throughline, Restated
Where This Course Connects
Reusing Chapter 1's own five connections: this course is the direct foundation under Machine Learning Fundamentals and Neural Networks & Deep Learning's use of vectors and matrices, Blender Fundamentals and Vector Graphics/Figma's own transform tooling, and Data Science Fundamentals' use of PCA for dimensionality reduction — all of which this capstone touched directly. Within this subject's own future courses, Calculus & Optimization will build directly on Chapter 5's transformations and Chapter 9's eigenvalues (gradient descent is, at its core, repeatedly applying a transformation), and Numerical Methods & Floating-Point Computation will build directly on Chapter 6's elimination and Chapter 7's inverse computations, where floating-point rounding actually starts to matter at scale.
Hands-On Exercises
A different sprite faces f = [0, 1] (facing "up"). The player is at direction d = [-2, 2] relative to the sprite. Using this chapter's own Steps 1–2 technique, compute the dot product to determine roughly how far off "ahead" the player is (find the angle), and the 2D cross product to determine whether the AI should turn left or right.
A second calibration check uses two new points: world 3 → pixel 160, world 6 → pixel 310. Using this chapter's own Step 5 technique (Gaussian elimination on pixel = m·world + c), solve for m and c, and verify your answer against both points. Do these calibration constants match Step 5's own values, or is this a genuinely different mapping?
For each of the eight steps in this chapter's own worked project, name the specific linear algebra topic it relied on, without looking back at the step labels — just from the description of what each step actually does.
📄 View solutionChapter 10 Quick Reference
- Full worked project: vectors/dot product (Ch.2) → 2D cross product (Ch.3) → matrix multiplication (Ch.4) → homogeneous transforms (Ch.5) → calibration system (Ch.6) → determinant/inverse unprojection (Ch.7) → input-scheme independence (Ch.8) → PCA on click data (Ch.9)
- Out of scope: calculus-based optimization, formal vector space theory, and numerical stability at scale — each reserved for its own future course
- This course's throughline: a small, consistent toolkit (vectors, matrices, transformations, systems, determinants, eigenvalues) reused across genuinely different problems, not a new technique per problem
- This course is the direct foundation this subject's own future courses will each build on — Calculus & Optimization on transformations/eigenvalues, Numerical Methods on elimination/inverses
- Course complete — Linear Algebra Fundamentals, 10 chapters, from vectors to eigenvalues