Linear Algebra
Intermediate

Angle Between Vectors

Angle from the dot product and magnitudes.

Formula

cos⁡θ=a⋅b∥a∥∥b∥\cos\theta = \frac{\mathbf{a}\cdot\mathbf{b}}{\|a\|\|b\|}

Variables

a,bVectors

Example

Orthogonal vectors give 90°

How it works

The dot product measures how much two vectors point in the same direction, while the magnitudes measure their lengths. Rearranging the dot-product identity a·b = ||a|| ||b|| cosθ gives the angle between the vectors, so this formula is really the geometric meaning of the dot product. It works because the same dot product can be viewed either algebraically from components or geometrically through a side-by-side projection idea.

When to use it

Use this when you need the direction relationship between two vectors, such as in geometry, physics, machine learning, or computer graphics. It is especially useful for checking whether vectors are acute, obtuse, or perpendicular, or for finding the actual angle between them.

Worked example, step by step

Let a = (3, 4) and b = (4, 1). Step 1: Compute the dot product: a·b = 3·4 + 4·1 = 12 + 4 = 16. Step 2: Compute the magnitudes: ||a|| = sqrt(3^2 + 4^2) = sqrt(9 + 16) = 5, and ||b|| = sqrt(4^2 + 1^2) = sqrt(17). Step 3: Substitute into the formula: cosθ = 16 / (5√17). Step 4: Approximate: 5√17 ≈ 20.62, so cosθ ≈ 16 / 20.62 ≈ 0.776. Step 5: Take arccos: θ ≈ arccos(0.776) ≈ 39.0°. Final answer: the angle between a and b is about 39°.

Common mistakes to avoid

  • Forgetting to use magnitudes in the denominator and using raw vector components instead
  • Taking arccos of a value outside [-1, 1] because of arithmetic or rounding errors
  • Mixing up the order of operations when computing the dot product or magnitude

Did You Know?

The cosine of the angle between two vectors is their dot product over their lengths — used to compare documents in search engines.

Share this formula

Reviewed & maintained by the FormulaWon editorial teamLast reviewed September 2026