Dot Product — Measuring Alignment

How to multiply two vectors and get a single number that tells you how aligned they are

Mathematics Linear Algebra beginner 8 min

This concept builds on Vectors — Direction and Magnitude, Cosine — The Other Side. Consider exploring them first for the best experience.

Step 1 of 6

Two Arrows, One Number

Vector A (red) and vector B (blue) both start at the origin. Drag either arrowhead, or move the 'A Magnitude' and 'A Angle' sliders, and watch the A · B card. Two arrows go in, but a single number comes out — a scalar. The green arc between the arrows marks the angle θ.

Multiply Matching Components

A · B = Ax·Bx + Ay·By. Multiply the two x-parts, multiply the two y-parts, then add the results. The first line of the formula box under the canvas fills in every component live, so you can check the arithmetic yourself while you drag either arrow around the grid.

The Cosine Form

The same number equals |A| × |B| × cos θ: length times length times alignment. Set the 'B Angle' slider to match the A angle — or click 'Same direction' — and θ becomes 0°, cos θ = 1, so A · B is simply |A| × |B|. The two formula lines always agree.

Worked Example: A = (3, 4), B = (4, 0)

Click 'Worked example'. Components: 3 × 4 + 4 × 0 = 12. Lengths: |A| = √(3² + 4²) = 5 and |B| = 4, so cos θ = 12 ÷ (5 × 4) = 0.6 and θ ≈ 53.1°. The green shadow of A on B has length 12 ÷ 4 = 3 — exactly the x-part of A.

The Sign Tells the Direction

Click 'Perpendicular': θ = 90°, cos θ = 0, and A · B = 0 however long the arrows are. Click 'Opposite' and the dot product turns negative. The badge in the corner of the canvas and the Alignment card read aligned, perpendicular or opposed, so the sign always has a meaning.

The Shadow: Projection

Dividing A · B by |B| gives the green segment along B — the length of the shadow A casts on B. Press 'Animate' to sweep A around and watch the shadow shrink to zero at 90° and point backwards beyond it. Work W = F · d uses this: only force along the motion counts.

How It Works — Step by Step

Step 1 of 6
  1. 1

    Two Arrows, One Number

    Vector A (red) and vector B (blue) both start at the origin. Drag either arrowhead, or move the 'A Magnitude' and 'A Angle' sliders, and watch the A · B card. Two arrows go in, but a single number comes out — a scalar. The green arc between the arrows marks the angle θ.

  2. 2

    Multiply Matching Components

    A · B = Ax·Bx + Ay·By. Multiply the two x-parts, multiply the two y-parts, then add the results. The first line of the formula box under the canvas fills in every component live, so you can check the arithmetic yourself while you drag either arrow around the grid.

  3. 3

    The Cosine Form

    The same number equals |A| × |B| × cos θ: length times length times alignment. Set the 'B Angle' slider to match the A angle — or click 'Same direction' — and θ becomes 0°, cos θ = 1, so A · B is simply |A| × |B|. The two formula lines always agree.

  4. 4

    Worked Example: A = (3, 4), B = (4, 0)

    Click 'Worked example'. Components: 3 × 4 + 4 × 0 = 12. Lengths: |A| = √(3² + 4²) = 5 and |B| = 4, so cos θ = 12 ÷ (5 × 4) = 0.6 and θ ≈ 53.1°. The green shadow of A on B has length 12 ÷ 4 = 3 — exactly the x-part of A.

  5. 5

    The Sign Tells the Direction

    Click 'Perpendicular': θ = 90°, cos θ = 0, and A · B = 0 however long the arrows are. Click 'Opposite' and the dot product turns negative. The badge in the corner of the canvas and the Alignment card read aligned, perpendicular or opposed, so the sign always has a meaning.

  6. 6

    The Shadow: Projection

    Dividing A · B by |B| gives the green segment along B — the length of the shadow A casts on B. Press 'Animate' to sweep A around and watch the shadow shrink to zero at 90° and point backwards beyond it. Work W = F · d uses this: only force along the motion counts.

Key Takeaways

Scalar Result

Unlike addition or cross product, the dot product of two vectors is just a number, not a vector.

Cosine = Alignment

A · B = |A||B|cos(θ) — the dot product is maximized when vectors point the same way (θ=0°) and zero when perpendicular.

Component Form

A · B = Ax·Bx + Ay·By. You can compute it without knowing the angle — very useful in code.

Projection

The dot product divided by |B| gives the length of A's shadow on B. This is how physics engines compute work and lighting.

Added
Updated
  • — Added what-if case buttons, a live alignment readout, four challenges, a worked example and two new quiz questions.