- cos θ = a·b / (|a| · |b|)
Holds when both vectors have a length greater than 0. A zero vector points nowhere and makes no angle with
anything.
The working takes three steps. With a = (6, 8) and b = (−3, 4):
- The dot product. a · b = 6 · (−3) + 8 · 4 = −18 + 32 = 14, with the
dot product.
- The lengths. |a| = √(36 + 64) = 10 and |b| = √(9 + 16) = 5, with the
magnitude of a vector.
- The angle. cos θ = 14 / (10 · 5) = 0.28, so θ = cos⁻¹ 0.28 ≈ 73.7°.
The card above takes over at step 3: type in the dot product and the two lengths.
A negative dot product means an obtuse angle
With a = (8, 15) and b = (3, −4) the dot product is 24 − 60 = −36. The lengths are 17 and 5, so
cos θ = −36 / 85 ≈ −0.424
| Working |
θ |
| cos⁻¹(−0.424) |
115.1° |
| cos⁻¹(0.424), minus sign dropped |
64.9° |
Both answers look like angles. But a negative dot product means the vectors point more away from each
other than towards each other, and the angle between them is then more than 90°. Keep the sign all the way
into the inverse cosine. The angle between two vectors lies between 0° and 180°, and cos⁻¹ returns an
answer in exactly that range.
When the dot product is 0
a = (3, 4) and b = (−4, 3) give a · b = −12 + 12 = 0, so cos θ = 0 and θ = 90°. The vectors are
perpendicular, however long they are. To check only whether two vectors are perpendicular, the dot product
on its own is enough.
Place a and b so they start at the same point. The segment between their tips is a − b, and the three form
a triangle with the angle θ between a and b. The
law of cosines gives
|a − b|² = |a|² + |b|² − 2 · |a| · |b| · cos θ
Written out in components, the left side is |a|² + |b|² − 2(a₁b₁ + a₂b₂). The two expressions are equal,
so |a| · |b| · cos θ = a₁b₁ + a₂b₂, which is the formula.
Common mistakes
- Dropping the minus sign. A negative dot product gives an angle over 90°.
- Forgetting the root in the lengths. |a| is √(a₁² + a₂²), not a₁² + a₂².
- A calculator in radians. cos⁻¹ 0.28 is 1.287 in radians and 73.7 in degrees.
- Dividing by the sum of the lengths. The denominator is the product |a| · |b|.
Common questions
Does it work for vectors in three dimensions?
Yes. The dot product gains a third term, a₃b₃, and each length a third square under the root. The
formula for cos θ is the same.
Which angle do I get, the acute or the obtuse one?
The one between the vectors as they point, between 0° and 180°. For the angle between two lines, which
have no direction, take the acute one: 180° minus an obtuse angle.
Can cos θ come out larger than 1?
Not for real vectors: the size of the dot product is at most |a| · |b|. A number outside −1 to 1 means
something went wrong, for example a length without its root.