Dot Product and Angle Between Vectors
The dot product of two vectors is a · b = a1b1 + a2b2 (+ a3b3 in space), and it equals |a||b| cos θ, where θ is the angle between the vectors. In brief: for a = (1, 2) and b = (3, 4), a · b = 3 + 8 = 11, |a| = √5, |b| = 5, so cos θ = 11/(5√5) ≈ 0.984 and θ ≈ 10.3°. Two nonzero vectors are perpendicular exactly when a · b = 0.
The dot product (scalar product) turns questions about angles, lengths and projections into simple arithmetic. This guide gives the two equivalent formulas, the angle between vectors, the test for perpendicularity, projections, and applications such as work and distances, with worked examples and a table.
What is the dot product?
The coordinate formula: a · b = a1b1 + a2b2 in the plane and a1b1 + a2b2 + a3b3 in space. The geometric formula: a · b = |a||b| cos θ, with 0° ≤ θ ≤ 180°. The result is a number, not a vector. The properties: a · b = b · a, (ka) · b = k(a · b), a · (b + c) = a · b + a · c, and a · a = |a|2.
The two formulas agree because of the law of cosines applied to the triangle with sides a, b and a − b.
Example 1: computing the dot product
(2, −3) · (4, 5) = 8 − 15 = −7. In space: (1, 2, 3) · (4, −5, 6) = 4 − 10 + 18 = 12.
Example 2: from lengths and angle
If |a| = 3, |b| = 4 and the angle between them is 60°, then a · b = 12 · 1/2 = 6.
How do you find the angle between vectors?
Solve the geometric formula: cos θ = (a · b)/(|a||b|), so θ = arccos(…). The sign of the dot product tells the type of the angle: positive means acute, zero means right, negative means obtuse.
Example 3: the angle in the plane
a = (1, √3), b = (√3, 1). a · b = 2√3, |a| = |b| = 2, so cos θ = 2√3/4 = √3/2 and θ = 30°.
Example 4: the angle in space
a = (1, 2, 2) and b = (2, 3, 6): a · b = 2 + 6 + 12 = 20, |a| = 3, |b| = 7, cos θ = 20/21 ≈ 0.952, θ ≈ 17.75°.
Example 5: the angles of a triangle
Triangle A(0, 0), B(4, 0), C(1, 3). At A: AB = (4, 0), AC = (1, 3): cos A = 4/(4 · √10) = 1/√10, so A ≈ 71.57°. At B: BA = (−4, 0), BC = (−3, 3): cos B = 12/(4 · 3√2) = 1/√2, so B = 45°. Then C = 180° − 71.57° − 45° ≈ 63.43°.
How do you test perpendicular vectors?
Nonzero vectors a and b are perpendicular (orthogonal) if and only if a · b = 0, because cos 90° = 0. In the plane, a vector perpendicular to (p, q) is (−q, p) or (q, −p).
Example 6: finding a missing coordinate
For which k is (k, 3) perpendicular to (4, −2)? 4k − 6 = 0, so k = 3/2.
Example 7: a right angle in a triangle
Is the triangle A(1, 1), B(4, 2), C(2, 5) right-angled? At A: AB · AC = (3, 1) · (1, 4) = 7. At B: BA · BC = (−3, −1) · (−2, 3) = 3. At C: CA · CB = (−1, −4) · (2, −3) = 10. No dot product is zero, so there is no right angle. By contrast, A(0, 0), B(4, 0), C(0, 3) has AB · AC = 0, a right angle at A.
What is the projection of one vector onto another?
The scalar projection of a onto b is (a · b)/|b|, the signed length of the shadow of a on the line of b. The vector projection is ((a · b)/(b · b)) b. The component of a perpendicular to b is a minus the projection.
Example 8: a projection
a = (3, 4), b = (1, 0): the projection is (3/1)(1, 0) = (3, 0), and the perpendicular part is (0, 4).
Example 9: a general projection
a = (2, 5), b = (3, 1): a · b = 11, b · b = 10, so the projection is 1.1 · (3, 1) = (3.3, 1.1). The perpendicular part (−1.3, 3.9) has the dot product with b: −3.9 + 3.9 = 0 ✓.
Example 10: work
A force F = (5, 2) N moves an object by d = (4, 3) m. The work is F · d = 20 + 6 = 26 J.
Table of examples
| a | b | a · b | cos θ | θ |
|---|---|---|---|---|
| (1, 0) | (0, 1) | 0 | 0 | 90° |
| (1, 1) | (1, 0) | 1 | √2/2 ≈ 0.707 | 45° |
| (2, 3) | (−3, 2) | 0 | 0 | 90° |
| (1, 2) | (3, 4) | 11 | ≈ 0.984 | ≈ 10.3° |
| (1, √3) | (√3, 1) | 2√3 | √3/2 ≈ 0.866 | 30° |
| (1, 0) | (−1, 0) | −1 | −1 | 180° |
Where does the dot product come from?
The concept grew out of work on quaternions by William Rowan Hamilton (the scalar part of a product of two vectors, up to sign) and of the geometric calculus of Hermann Grassmann in the 1840s. The notation a · b and the name “scalar product” are due to Josiah Willard Gibbs and Oliver Heaviside, who separated vector analysis from quaternions in the 1880s.
Where is it used?
In physics, the dot product gives work and power. In computer graphics, it measures the angle between a surface normal and a light direction, which determines shading. In machine learning, the cosine similarity of two vectors, (a · b)/(|a||b|), compares documents. The cross-checking partner of this tool is the cross product, which gives areas and normals.
Which mistakes are common?
Treating the result as a vector
The dot product is a number. Writing a · b = (a1b1, a2b2) is wrong.
Forgetting to divide by lengths
cos θ = (a · b)/(|a||b|), not just a · b.
Ignoring the zero vector
The angle with the zero vector is undefined, and a · 0 = 0 does not mean perpendicular.
Confusing the sign with the direction
A negative dot product means the angle exceeds 90°, not that the vectors are “negative”.