← CS Lab Math & Theory / Vectors · Dot Product Open standalone ↗

The dot product turns two vectors into a single number that measures how much they point the same way. Drag the arrows above and watch one value, a · b, carry both the angle between them and their lengths at once.

Where you meet it

What it does

It takes two vectors and returns one scalar (not another vector). That scalar is large and positive when the vectors point the same way, zero when they are at right angles, and negative when they point apart. So the dot product is a compact answer to the question "how aligned are these two?"

One number secretly stores the angle: the sign of a · b alone tells you if two vectors agree, oppose, or stand at a right angle.

How it works

There are two formulas, and the deep fact is that they are always equal:

a · b  =  Σ aᵢ bᵢ  =  a₁b₁ + a₂b₂ + … + aₙbₙ      (algebraic)
a · b  =  |a| |b| cos θ                           (geometric)

The algebraic form multiplies matching components and sums them — cheap to compute, works in any dimension. The geometric form reads the same number as two lengths times the cosine of the angle θ between the vectors.

Why they are the same. Take unit vectors along the axes. x̂ · x̂ = 1 (a vector is fully aligned with itself) and x̂ · ŷ = 0 (perpendicular axes contribute nothing). The dot product is linear in each argument, so when you expand (a₁x̂ + a₂ŷ) · (b₁x̂ + b₂ŷ) the cross terms vanish and only a₁b₁ + a₂b₂ survives. Separately, the law of cosines on the triangle formed by a, b, and a − b yields |a||b|cos θ. Both routes land on one number — that is why the dot product secretly stores the angle. (3Blue1Brown frames this equality as duality: a vector and the projection-and-scale operation it represents are two views of the same thing.)

The sign is the whole story. Since |a| and |b| are never negative, the sign of a · b is just the sign of cos θ:

Watch out

  • Dot product = 0 means orthogonal, not "zero vector". Two non-zero vectors at a right angle have a dot product of exactly zero — this is the definition of perpendicularity in any dimension.
  • Don't confuse it with the cross product. The dot product returns a scalar and exists in every dimension; the cross product returns a vector perpendicular to both and only really lives in 3D.
  • Magnitude depends on length, not just angle. A big a · b can mean "aligned" or just "long vectors". For a pure similarity score, normalise: cos θ = a·b / (|a||b|), which stays in [-1, 1].
  • The dot product needs equal-length vectors. a · b is only defined when a and b have the same number of components.

Go deeper

Das Skalarprodukt verwandelt zwei Vektoren in eine einzige Zahl, die misst, wie stark sie in dieselbe Richtung zeigen. Zieh oben an den Pfeilen — ein Wert, a · b, trägt zugleich den Winkel zwischen ihnen und ihre Längen.

Wo es vorkommt

Was es tut

Es nimmt zwei Vektoren und liefert einen Skalar (keinen Vektor). Dieser Skalar ist groß und positiv, wenn die Vektoren gleich zeigen, null, wenn sie senkrecht stehen, und negativ, wenn sie auseinanderzeigen. Das Skalarprodukt ist also eine kompakte Antwort auf die Frage "wie ausgerichtet sind diese beiden?"

Eine Zahl speichert heimlich den Winkel: Schon das Vorzeichen von a · b sagt, ob zwei Vektoren gleich zeigen, entgegen oder senkrecht stehen.

Wie es funktioniert

Es gibt zwei Formeln, und die zentrale Tatsache ist, dass sie immer gleich sind:

a · b  =  Σ aᵢ bᵢ  =  a₁b₁ + a₂b₂ + … + aₙbₙ      (algebraisch)
a · b  =  |a| |b| cos θ                           (geometrisch)

Die algebraische Form multipliziert passende Komponenten und summiert sie — günstig zu rechnen, gilt in jeder Dimension. Die geometrische Form liest dieselbe Zahl als zwei Längen mal dem Kosinus des Winkels θ zwischen den Vektoren.

Warum sie gleich sind. Nimm die Einheitsvektoren entlang der Achsen. x̂ · x̂ = 1 (ein Vektor ist voll mit sich selbst ausgerichtet) und x̂ · ŷ = 0 (senkrechte Achsen tragen nichts bei). Das Skalarprodukt ist in jedem Argument linear; entwickelt man (a₁x̂ + a₂ŷ) · (b₁x̂ + b₂ŷ), fallen die Kreuzterme weg und es bleibt nur a₁b₁ + a₂b₂. Getrennt davon liefert der Kosinussatz am Dreieck aus a, b und a − b den Ausdruck |a||b|cos θ. Beide Wege münden in dieselbe Zahl — darum steckt im Skalarprodukt heimlich der Winkel. (3Blue1Brown nennt diese Gleichheit Dualität: ein Vektor und die Projektions-und-Skalier-Operation, die er darstellt, sind zwei Sichten auf dasselbe.)

Das Vorzeichen erzählt alles. Da |a| und |b| nie negativ sind, ist das Vorzeichen von a · b genau das Vorzeichen von cos θ:

Worauf achten

  • Skalarprodukt = 0 heißt orthogonal, nicht "Nullvektor". Zwei vom Null verschiedene Vektoren im rechten Winkel haben ein Skalarprodukt von exakt null — das ist die Definition von Senkrechtstehen in jeder Dimension.
  • Nicht mit dem Kreuzprodukt verwechseln. Das Skalarprodukt liefert einen Skalar und existiert in jeder Dimension; das Kreuzprodukt liefert einen Vektor senkrecht zu beiden und lebt eigentlich nur im 3D.
  • Die Größenordnung hängt von der Länge ab, nicht nur vom Winkel. Ein großes a · b kann "ausgerichtet" oder einfach "lange Vektoren" bedeuten. Für ein reines Ähnlichkeitsmaß normalisieren: cos θ = a·b / (|a||b|) — das bleibt in [-1, 1].
  • Das Skalarprodukt braucht gleich lange Vektoren. a · b ist nur definiert, wenn a und b gleich viele Komponenten haben.

Mehr dazu

Next up
Math & TheoryMatrix Multiplication Math & TheoryNormal Distribution All concepts →