Linear algebra · 02 · One number for alignment · 8 min
The dot product
Multiply two vectors? There's more than one way — and the most useful produces a single number that measures how much two arrows agree. It's called the dot product, and it quietly runs your search engine.
Build the intuition
The recipe and its meaning
Multiply matching slots, then total: (3,2)·(1,4) = 3+8 = 11. Geometrically this equals |a||b|cos θ — big when arrows point together, zero when perpendicular, negative when opposed. Alignment, distilled to one number.
Zero means perpendicular
Dot product zero ⇔ arrows at right angles ⇔ the vectors share nothing. This gives algebra a way to test geometric independence without drawing anything — the workhorse trick behind projections, coordinates, and compression.
Projection: the useful shadow
How much of force a acts along direction b? The dot product extracts exactly the component of one vector along another — its shadow. Physics uses it for work (force · displacement); graphics uses it for lighting (surface · light direction).
See it move
Watch the dot-product readout as you steer: positive when the arrows cooperate, zero at right angles, negative in opposition.
A worked example
Do these users have similar taste?
Rate three genres −2…2. Ana: (2, 1, −2) — loves sci-fi, hates romance. Ben: (2, 0, −1). Cara: (−2, 0, 2).
Ana·Ben:
Ana·Cara:
Positive: kindred spirits — recommend Ben's favorites to Ana. Negative: opposite tastes. Recommender systems are this, at scale.
Out in the world
How 3D scenes get their shading
Every pixel's brightness in a 3D render comes from dotting the surface's normal vector with the light's direction: faces toward the light glow (dot near 1), faces away go dark (dot below 0). Your GPU computes trillions of these per second.
Common confusion, cleared
“The dot product is a vector.”
It's a plain number (a scalar) — that's its point. There's a different product (the cross product) that yields vectors; don't let them blur.
“Bigger dot product always means better aligned.”
Length inflates it too: a huge vector slightly off-axis can out-dot a small one dead-on. For pure alignment, normalize first (that's cosine similarity).
Recap
- Dot product: multiply matching slots and total — equals |a||b|cos θ.
- Positive = agreeing, zero = perpendicular, negative = opposing.
- Similarity search, work, and lighting are all dot products.