Mathematics

How the Dot Product and Angle Between Two Vectors Are Calculated

The dot product multiplies each pair of matching components and adds the results, and rearranging that same formula gives the angle between the two vectors — a single calculation that tells you both how aligned two vectors are and by how much.

A worked example: (1,2,3) · (4,5,6)

The dot product of (1,2,3) and (4,5,6) is (1×4) + (2×5) + (3×6) = 4 + 10 + 18 = 32, and the angle between them works out to 12.9332°.

The dot product formula

For two vectors of equal length, the dot product a·b is the sum of each pair of matching components multiplied together: a₁b₁ + a₂b₂ + a₃b₃ + ... It collapses two vectors into a single number, unlike vector addition, which produces another vector.

From dot product to angle: cos θ = (a·b) ÷ (|a||b|)

Rearranging the dot product's geometric definition (a·b = |a||b|cos θ) gives the angle directly: θ = arccos((a·b) ÷ (|a||b|)). For (1,2,3) and (4,5,6), the magnitudes are √14 ≈ 3.7417 and √77 ≈ 8.775, so cos θ = 32 ÷ (3.7417 × 8.775) ≈ 0.9746, and arccos(0.9746) ≈ 12.9332°.

What a zero, positive, or negative dot product means

The sign and size of the dot product read directly as a relationship between the vectors. Two perpendicular vectors like (1,0,0) and (0,1,0) have a dot product of exactly 0 and an angle of exactly 90° — the dot product is zero precisely when vectors are perpendicular. Two opposite-pointing vectors like (2,0,0) and (−3,0,0) give a dot product of −6 and an angle of 180° — a negative dot product means the vectors point in broadly opposite directions.

When to reach for the cross product instead

The dot product works in any dimension and answers "how aligned are these two vectors," as a single scalar number. When the question is instead "what vector is perpendicular to both of these" (only meaningful in 3D), that's the cross product's job — a genuinely different calculation, not just a variant of this one.