Vectors &
Linear Algebra.
Vectors are the language of space — they describe direction, magnitude, colour, velocity, and transformation. Linear algebra is the mathematics behind 3D graphics, machine learning, physics engines, and everything that moves on screen.
A quantity with both magnitude and direction. In 2D: (x, y). In 3D: (x, y, z). Think of it as an arrow in space.
A plain number — no direction. Multiplying a vector by a scalar stretches or shrinks it without changing its direction.
A rectangular grid of numbers. Matrices represent transformations — rotation, scale, shear, projection — applied to vectors.
Why does this matter for code? Every pixel position, colour value (r, g, b), mouse coordinate, force in a physics simulation, and weight in a neural network is a vector. Understanding vectors means understanding how programs reason about space.
Notation & vocabulary
The symbols and terms you'll encounter across maths, physics, and shader code.
| Notation | Name | Meaning |
|---|---|---|
| v = (3, 4) | 2D vector | An arrow from the origin to the point (3, 4) |
| |v| | Magnitude / length | The length of the arrow: √(x² + y²) |
| v̂ | Unit vector | A vector of length 1 pointing in the same direction: v / |v| |
| a · b | Dot product | Scalar: a.x·b.x + a.y·b.y. Tells you how parallel two vectors are |
| a × b | Cross product | 3D only. Returns a new vector perpendicular to both a and b |
| M · v | Matrix–vector multiply | Applies transformation M to vector v — rotation, scale, projection |
| lerp(a,b,t) | Linear interpolation | a + t·(b − a). Slides smoothly from a (t=0) to b (t=1) |
Activity — Vector playground
Drag the sliders to change vectors A and B. Watch the sum, dot product, and angle update live.
Core operations
The building blocks used in graphics, physics, and machine learning.
Combine two displacements. Moving 3 right then 2 right = 5 right. Used for velocity + position updates every frame.
Stretch or shrink a vector. Multiplying velocity by 0.98 each frame creates drag. Negative s flips direction.
Returns a scalar. If a·b = 0, vectors are perpendicular. If > 0, they point roughly the same way. Used in lighting calculations.
Strip magnitude, keep direction. Essential before computing angles or projections — ensures consistent behaviour regardless of vector length.
Returns a vector perpendicular to both inputs. Used to compute surface normals in 3D graphics, which tells the GPU which way a face is pointing.
Smoothly blend between two values. t=0 → a, t=1 → b, t=0.5 → midpoint. Used everywhere: animation, colour mixing, camera movement.
Activity — Matrix rotation
A 2×2 rotation matrix transforms every point of a shape. Drag the slider to see it live.
Where vectors show up in code
Linear algebra is everywhere in creative and technical computing.