The Dot Product

Every way of combining two vectors you've met so far — adding them, scaling one by a number — hands back another vector: still an arrow, still pointing somewhere. The dot product is a different kind of combination entirely. Feed it two vectors and it hands back a single plain number (a scalar) — no arrow, no direction, just a value.

That number turns out to be surprisingly useful. Pull a sled with a rope held at an angle, and the dot product tells you exactly how much of your pull actually drags the sled forward (that's the physics idea of work). Point a robot's sensor one way and a target another, and the dot product's sign alone tells you whether the two directions roughly agree, roughly disagree, or sit at right angles — without measuring a single angle. Two short lists of numbers, multiplied and added, turn out to carry a surprising amount of geometry.

It shows up everywhere two directions need comparing. Two hikers set off from the same camp with different compass bearings — are they roughly headed the same way, or wandering off in opposite directions? Two spreadsheets of customer ratings — are two shoppers' tastes alike, or opposite? Behind the scenes, all of these get turned into vectors, and the very same one-line calculation answers every one of them.

Component form: multiply and add

The everyday recipe: multiply the matching components of the two vectors, then add the results.

\vec{u} \cdot \vec{v} = u_x v_x + u_y v_y.

For example, with \vec{u} = \begin{bmatrix} 3 \\ 2 \end{bmatrix} and \vec{v} = \begin{bmatrix} 4 \\ 1 \end{bmatrix}:

\vec{u} \cdot \vec{v} = (3)(4) + (2)(1) = 12 + 2 = 14.

That's the whole recipe — no arrows drawn, no protractor, just arithmetic. It doesn't look obviously connected to geometry at all yet. That connection is the surprise in the next section.

The other formula: lengths and the angle between them

Remarkably, there is a second way to compute the exact same number — using the two vectors' lengths (magnitudes) and the angle \theta between them:

\vec{u} \cdot \vec{v} = \lVert \vec{u} \rVert\, \lVert \vec{v} \rVert \cos\theta.

Multiply component-by-component, or multiply the two lengths by the cosine of the angle between the arrows — both routes land on the same number. The component form is the one you'll actually compute with day to day; the geometric form is the one that tells you what the number means. The next page rearranges this very formula to hand you the angle itself, for free.

Here \theta always means the angle between the two vectors themselves, measured once they share a starting point — never some angle either one happens to make with a coordinate axis. Keep that straight; it's a classic slip (more on that in the vignette below).

There's a third way to picture the same idea: the dot product is closely tied to the length of the "shadow" one vector casts along the other — its projection. That's a story for its own page; for now, just notice that a bigger shadow (a more direct hit) goes with a bigger dot product.

Watch the sign as you turn the arrows

Set the two vectors below with the sliders. The panel multiplies matching components and adds them — computing the dot product live. Watch the number as you swing the arrows around: it's positive while they roughly agree, crosses exactly zero the instant they're perpendicular, and turns negative once they broadly oppose. That sign is doing real work, as the next two worked examples show.

Worked example: work done by a force

In physics, the work done by a constant force \vec F moving something through a displacement \vec d is defined as their dot product, W = \vec F \cdot \vec d. Suppose you pull a sled with a rope, applying a force of 40 newtons at an angle of 60^\circ above the direction the sled actually slides, while the sled moves 5 metres.

Plugging straight into the geometric form:

W = \lVert \vec F \rVert\, \lVert \vec d \rVert \cos\theta = (40)(5)\cos 60^\circ = 200 \times 0.5 = 100\ \text{J}.

Only the part of the force pointing along the direction of travel does any work — the dot product extracts exactly that part automatically, without you ever splitting the force into components by hand.

Worked example: the sign alone, no angle required

Three quick checks, each done with nothing but the component formula:

Notice what didn't happen: no lengths were computed, no cosine was taken, no protractor came out. The bare sign of the dot product — positive, negative, or zero — already tells you whether two directions agree, disagree, or sit at right angles.

Worked example: are two hikers heading the same way?

Two hikers leave the same campsite. Measuring east as the first component and north as the second, hiker A's direction is \vec a = (4, 1) and hiker B's is \vec b = (-1, -3). Are they roughly walking together, or drifting apart? Nobody needs a compass rose or a protractor — just the dot product:

\vec a \cdot \vec b = (4)(-1) + (1)(-3) = -4 - 3 = -7.

Negative — so however far apart their exact bearings are, they are broadly heading in opposite directions, and will drift further apart the longer they walk. If a park ranger only needed a quick yes/no answer to "are these two search parties covering the same ground?", the sign of one small sum already gave it.

Worked example: headwind or tailwind?

A delivery drone flies with velocity vector \vec f = (6, 2) (mostly east, a little north), while the wind is blowing with vector \vec w = (-3, 1). Will the wind help push the drone along, or fight it?

\vec f \cdot \vec w = (6)(-3) + (2)(1) = -18 + 2 = -16.

Negative — so the wind is broadly a headwind, working against the drone's flight, even though it isn't blowing exactly opposite the drone's path. The flight computer doesn't need the precise angle to make that call; the sign of one small sum already settles it, which is exactly why real autopilot software leans on this calculation instead of trigonometry tables.

The rules it obeys

The dot product is commutative (\vec{u}\cdot\vec{v} = \vec{v}\cdot\vec{u}) and distributes over addition (\vec{u}\cdot(\vec{v}+\vec{w}) = \vec{u}\cdot\vec{v} + \vec{u}\cdot\vec{w}). One special case is worth memorizing: a vector dotted with itself gives its length squared,

\vec{v} \cdot \vec{v} = v_x^2 + v_y^2 = \lVert \vec{v} \rVert^2.

That isn't a coincidence — it's just the definition plus an old friend. Dot the vector with itself and the recipe gives v_x v_x + v_y v_y = v_x^2 + v_y^2. Draw \vec v on a grid and its length is exactly the hypotenuse of a right triangle with legs v_x and v_y, so Pythagoras says \lVert v \rVert^2 = v_x^2 + v_y^2 too. Two completely different routes — algebra and geometry — arrive at the same expression, which is exactly why the dot product is able to "know about" length at all.

So the dot product already knows about length — and the next page pulls the angle back out of the very same formula. Distributivity is what makes the dot product genuinely powerful rather than just a curiosity: it means you can expand a dot product of sums exactly the way you'd expand (a+b)(c+d) in ordinary algebra, term by term, even though \vec u and \vec v are arrows, not plain numbers.

Quick recap

Two classic slips with the dot product:

When a recommendation system decides two songs, films, or products are "similar," it usually isn't reading descriptions — it's turning each item into a long list of numbers (a vector) and computing a cosine similarity, which is exactly the geometric dot-product formula rearranged: \cos\theta = \dfrac{\vec u \cdot \vec v}{\lVert u\rVert\,\lVert v\rVert}. Two items whose vectors point almost the same way in that huge space of numbers get a similarity close to 1; unrelated items land near 0. Every "customers who liked this also liked…" shelf, every search engine ranking, and every face-matching app leans on this same one-line idea from vectors.

Physics got there first, though: work, and later energy and power throughout mechanics and electromagnetism, are built out of dot products, because so much of nature cares about "how much of this points along that."

The notation itself is barely older than a hundred and fifty years. Physicist Josiah Willard Gibbs, working out the vector algebra used in electromagnetism in the 1880s, popularized writing the raised dot between two vectors — deliberately choosing it to contrast with the "cross" he used for the other kind of vector product. Long before computers, recommendation engines, or robots, that dot was already quietly measuring "how much do these two arrows agree?"

See it explained