The dot product, explained visually
The dot product of vectors a and b is a number: multiply matching components and add, so (1, 4) · (4, 3) = 1 × 4 + 4 × 3 = 16. It also equals |a||b| cos θ, the length of a's shadow on b times the length of b. It is positive when the angle θ between them is acute, zero when it is 90° and negative when it is obtuse.
a dot b equals a1 b1 plus a2 b2 plus a3 b3, which is also the length of a times the length of b times the cosine of the angle θ between them.
Updated
Concept map
8 ideas, in the order to learn them. Click one and Zidna draws and narrates an animated lesson on it.
The Dot Product
What the dot product measures and how to use it: the shadow of one vector on another, the component formula and why the two agree, what its sign says, the angle between vectors, projection, work, and how it differs from the cross product.
Scalar Projection
The signed length of one vector's shadow on the line of another: |a| cos θ.Generate lesson2Dot Product of Two Vectors
A number from two vectors: multiply matching components and add, which equals |a||b| cos θ.Builds on Scalar ProjectionGenerate lesson3Vector Projection
The shadow of a on b as a vector along b: (a · b / |b|²) b.Builds on Dot Product of Two Vectors, Scalar ProjectionGenerate lesson4The Sign of the Dot Product
Positive for an acute angle, zero for a right angle, negative for an obtuse angle.Builds on Dot Product of Two VectorsGenerate lesson5Proof by the Law of Cosines
Why multiplying components and adding always gives |a||b| cos θ.Builds on Dot Product of Two VectorsGenerate lesson6The Cross Product
A vector perpendicular to two 3D vectors, as long as the area of the parallelogram they span.Builds on Dot Product of Two VectorsGenerate lesson7The Angle Between Two Vectors
Found by dividing the dot product by both vectors' lengths and taking the inverse cosine.Builds on Dot Product of Two Vectors, The Sign of the Dot ProductGenerate lesson8Work Done by a Force
The energy a force transfers along a displacement: W = F · d.Builds on Dot Product of Two Vectors, The Sign of the Dot ProductGenerate lessonKey ideas
- 01
The dot product of two vectors is a number: multiply matching components and add. For (1, 4) and (4, 3), that is 1 × 4 + 4 × 3 = 16.
- 02
Geometrically, a · b = |a||b| cos θ: the length of a's shadow on b times the length of b. The component formula and this one always give the same number.
- 03
The sign of the dot product tells the angle: positive when it is acute, zero when the vectors are perpendicular, negative when it is obtuse.
- 04
The angle between two nonzero vectors is θ = cos⁻¹(a · b / (|a||b|)), and the formula works in any number of dimensions.
- 05
The scalar projection of a onto b is a · b / |b|, the shadow's signed length. The vector projection is (a · b / |b|²) b, the shadow as a vector along b.
- 06
The dot product returns a number and uses cos θ; the cross product returns a vector perpendicular to both and uses sin θ.
What is the dot product?
The dot product is a way to multiply two vectors that gives a single number. Multiply the matching components, then add the products. For a = (1, 4) and b = (4, 3), a · b = 1 × 4 + 4 × 3 = 4 + 12 = 16.
a dot b equals a1 times b1, plus a2 times b2, and so on up to an times bn: the sum of the products of matching components.
| Component | From a | From b | Product |
|---|---|---|---|
| x | 1 | 4 | 1 × 4 = 4 |
| y | 4 | 3 | 4 × 3 = 12 |
| Sum of the products | a · b = 16 |
In three dimensions there is a third product to add: (2, −1, 3) · (4, 5, 1) = 8 − 5 + 3 = 6. The two vectors must have the same number of components, and the formula works the same way for any number of them.
The answer is a number, a scalar, never a vector. That is why the dot product is also called the scalar product. Its name comes from the raised dot in a · b.
What does the dot product represent geometrically?
Geometrically, the dot product a · b is the length of a's shadow on b, times the length of b. Draw both vectors from the origin and drop a perpendicular from the tip of a onto the line through b. The piece of that line from the origin to the foot of the perpendicular is the shadow, and its length is |a| cos θ, where θ is the angle between the vectors. That length is signed: when θ is more than 90°, the shadow points backward and counts as negative. Multiplying by |b| gives the dot product.
a dot b equals the length of a times the length of b times the cosine of the angle θ between them.
For a = (1, 4) and b = (4, 3), the shadow of a on b is 3.2 units long and b is 5 units long, so a · b = 3.2 × 5 = 16. The components give the same 16: 1 × 4 + 4 × 3. The two formulas are two views of one number.
It works in either direction. The shadow of b on a, times the length of a, is the same number, because |a||b| cos θ does not change when a and b swap places.
The dot product measures how much two vectors point the same way: all the way gives |a||b|, perpendicular gives 0, and exactly opposite gives −|a||b|.
Why does the dot product equal |a||b| cos θ?
The dot product's component formula equals |a||b| cos θ because of the law of cosines. Put a and b tail to tail. The arrow from the tip of b to the tip of a is the vector a − b, and the three vectors form a triangle with the angle θ between a and b.
Write the square of the third side's length two ways. The law of cosines gives one. Expanding with the component formula, which distributes like ordinary multiplication and gives a · a = |a|², gives the other.
By the law of cosines, the length of a minus b, squared, is the length of a squared plus the length of b squared minus 2 times the length of a times the length of b times cos θ. Expanding with the dot product, the same quantity is the length of a squared minus 2 a dot b plus the length of b squared.
The two right sides are equal, so −2 a · b = −2|a||b| cos θ, and a · b = |a||b| cos θ. Nothing in the argument depends on how many components the vectors have, so the formula holds in two, three or any number of dimensions.
In two dimensions there is a second way to see it. Write a = |a|(cos α, sin α) and b = |b|(cos β, sin β), using the angles each vector makes with the x-axis, as on the unit circle. Then a · b = |a||b|(cos α cos β + sin α sin β) = |a||b| cos(α − β). The difference α − β is the turn from b to a, and it has the same cosine as the angle θ between them.
When is the dot product positive, negative or zero?
The dot product is positive when the angle between two vectors is less than 90°, zero when it is exactly 90°, and negative when it is more than 90°. The lengths of nonzero vectors are positive, so a · b = |a||b| cos θ always has the sign of cos θ.
| Angle θ | cos θ | a · b | Shadow of a on b |
|---|---|---|---|
| 0°, same direction | 1 | |a||b|, its largest value | all of a, along b |
| between 0° and 90°, acute | positive | positive | points along b |
| 90°, perpendicular | 0 | 0 | shrinks to a point |
| between 90° and 180°, obtuse | negative | negative | points backward |
| 180°, opposite direction | −1 | −|a||b|, its smallest value | all of a, against b |
That makes the dot product the quickest test for a right angle: two nonzero vectors are perpendicular, also called orthogonal, exactly when their dot product is 0. For example, (2, −1, 3) · (4, 5, −1) = 8 − 5 − 3 = 0, so these two vectors meet at 90°.
The same test is behind the rule for perpendicular slopes. Lines with slopes m₁ and m₂ point along (1, m₁) and (1, m₂), whose dot product is 1 + m₁m₂. It is 0 exactly when m₁m₂ = −1.
How do you find the angle between two vectors?
To find the angle between two vectors, divide their dot product by the product of their lengths, then take the inverse cosine. The angle always comes out between 0° and 180°.
θ equals the inverse cosine of a dot b divided by the length of a times the length of b.
- 1Find the dot product. For a = (1, 2, 2) and b = (2, −1, 2): 1 × 2 + 2 × (−1) + 2 × 2 = 2 − 2 + 4 = 4.
- 2Find both lengths: |a| = √(1 + 4 + 4) = 3 and |b| = √(4 + 1 + 4) = 3.
- 3Divide the dot product by the product of the lengths: cos θ = 4 / (3 × 3) = 4/9 ≈ 0.444.
- 4Take the inverse cosine, with the calculator in degree mode: θ = cos⁻¹(4/9) ≈ 63.6°.
The fraction a · b / (|a||b|) always lands between −1 and 1. A value outside that range means an arithmetic slip, usually in one of the lengths.
What is the projection of a onto b?
The projection of a onto b is the shadow of a on the line through b. As a number, the scalar projection, it is the shadow's signed length, a · b / |b|. As a vector, the vector projection, it is that length pointed along b: (a · b / |b|²) b.
The scalar projection of a onto b is a dot b divided by the length of b. The vector projection of a onto b is a dot b divided by the length of b squared, times the vector b.
| Projection | Formula | For a = (1, 4) onto b = (4, 3) | What it is |
|---|---|---|---|
| Scalar | a · b / |b| | 16 / 5 = 3.2 | a number: the shadow's signed length |
| Vector | (a · b / |b|²) b | (16 / 25)(4, 3) = (2.56, 1.92) | a vector along b: the shadow itself |
What is left of a after the projection is perpendicular to b. For a = (1, 4) and b = (4, 3), a minus its projection is (1, 4) − (2.56, 1.92) = (−1.56, 2.08), and (−1.56, 2.08) · (4, 3) = −6.24 + 6.24 = 0. So projection splits any vector into a part along b and a part across it, the way a force on a ramp splits into a pull along the slope and a push into it.
Divide by the length of the vector you project onto. The scalar projection of a onto b is a · b / |b|, while the scalar projection of b onto a is a · b / |a|.
What are the properties of the dot product?
The dot product is commutative and distributive, numbers factor out of it, and a vector dotted with itself gives its length squared. It is not associative: a · b is a number, and a number cannot be dotted with a vector, so (a · b) · c is not a dot product at all.
| Property | Rule | Check |
|---|---|---|
| Commutative | a · b = b · a | (1, 4) · (4, 3) = (4, 3) · (1, 4) = 16 |
| Distributive | a · (b + c) = a · b + a · c | (1, 4) · (5, 3) = 17 = 16 + 1 |
| Numbers factor out | (ka) · b = k(a · b) | (2, 8) · (4, 3) = 32 = 2 × 16 |
| With itself | a · a = |a|² | (4, 3) · (4, 3) = 25 = 5² |
| Unit vectors | i · i = j · j = k · k = 1, i · j = j · k = k · i = 0 | (1, 0) · (0, 1) = 0 |
| Bounded by the lengths | |a · b| ≤ |a||b| | 16 ≤ √17 × 5 ≈ 20.6 |
The rule a · a = |a|² is the Pythagorean theorem in vector form: (4, 3) · (4, 3) = 4² + 3² = 25, the square of the length 5. The last rule, the Cauchy–Schwarz inequality, is why a · b / (|a||b|) always lies between −1 and 1, so it can be the cosine of an angle.
What is the difference between the dot product and the cross product?
The dot product gives a number that measures how much two vectors point the same way, using cos θ. The cross product gives a vector perpendicular to both, and its length, |a||b| sin θ, measures how much they point across each other: it is the area of the parallelogram the two vectors span.
| Feature | Dot product a · b | Cross product a × b |
|---|---|---|
| Result | a number (scalar) | a vector |
| With the angle | |a||b| cos θ | length |a||b| sin θ |
| Picture | shadow of a on b, times |b| | area of the parallelogram on a and b |
| Zero when | the vectors are perpendicular | the vectors are parallel |
| Order | a · b = b · a | a × b = −(b × a) |
| Dimensions | any number | three |
| For (1, 4, 0) and (4, 3, 0) | 16 | (0, 0, −13), length 13 |
Together they account for all of |a||b|: (a · b)² + |a × b|² = |a|²|b|², because cos²θ + sin²θ = 1. For a = (1, 4, 0) and b = (4, 3, 0), 16² + 13² = 256 + 169 = 425 = 17 × 25.
What is the dot product used for?
The dot product is used wherever the question is how much of one thing points along another: work in physics, angles and right angles in geometry, lighting in computer graphics and similarity in data.
- Work: a constant force F that moves an object along a displacement d does work W = F · d. Only the part of the force along the motion counts, so a force at 90° to the motion does no work.
- Angles and right angles: a · b = 0 means two vectors are perpendicular, and cos θ = a · b / (|a||b|) gives the angle between any two vectors, even in dimensions no one can draw.
- Lighting in computer graphics: the brightness of a matte surface follows Lambert's cosine law, computed as the dot product of the surface's unit normal with the unit vector pointing to the light.
- Comparing data: cosine similarity, a · b / (|a||b|), compares documents or other items stored as long lists of numbers by the angle between them.
- Matrices: each entry of a matrix times a vector, Av, is a row of A dotted with v. Eigenvectors are the nonzero vectors v for which Av, built from those dot products, comes out as a multiple of v.
Worked examples
Dot product of two vectors in 2D
Find a · b for a = (5, −2) and b = (3, 4).
- 1Multiply the x-components: 5 × 3 = 15.
- 2Multiply the y-components: −2 × 4 = −8.
- 3Add the products: 15 + (−8) = 7.
- 4The result is positive, so the angle between a and b is less than 90°.
Answer: a · b = 7.
Dot product in 3D, with i, j and k
Find a · b for a = 3i − 2j + k and b = 4i + j − 5k.
- 1Read off the components: a = (3, −2, 1) and b = (4, 1, −5).
- 2Multiply matching components: 3 × 4 = 12, −2 × 1 = −2 and 1 × (−5) = −5.
- 3Add the products: 12 − 2 − 5 = 5.
Answer: a · b = 5.
Dot product from the lengths and the angle
|a| = 6, |b| = 5 and the angle between a and b is 120°. Find a · b.
- 1Use the geometric formula: a · b = |a||b| cos θ.
- 2cos 120° = −½.
- 3Multiply: a · b = 6 × 5 × (−½) = −15.
- 4The answer is negative because 120° is an obtuse angle.
Answer: a · b = −15.
The angle between two vectors
Find the angle between a = (2, 1) and b = (−3, 1).
- 1Dot product: 2 × (−3) + 1 × 1 = −6 + 1 = −5.
- 2Lengths: |a| = √(4 + 1) = √5 and |b| = √(9 + 1) = √10.
- 3Divide: cos θ = −5 / (√5 × √10) = −5 / √50 = −5 / (5√2) = −1/√2 ≈ −0.7071.
- 4Inverse cosine: θ = cos⁻¹(−1/√2) = 135°.
Answer: θ = 135°, an obtuse angle, as the negative dot product said it would be.
Making two vectors perpendicular
For what value of k are (k, 3) and (2, −4) perpendicular?
- 1Perpendicular vectors have a dot product of 0.
- 2Find the dot product: (k, 3) · (2, −4) = 2k + 3 × (−4) = 2k − 12.
- 3Solve 2k − 12 = 0: k = 6.
- 4Check: (6, 3) · (2, −4) = 12 − 12 = 0.
Answer: k = 6.
Projection of one vector onto another
Find the scalar and vector projections of a = (1, 3) onto b = (4, 2).
- 1Dot product: a · b = 1 × 4 + 3 × 2 = 10.
- 2Length of b: |b| = √(16 + 4) = √20 = 2√5, so |b|² = 20.
- 3Scalar projection: a · b / |b| = 10 / (2√5) = √5 ≈ 2.24.
- 4Vector projection: (a · b / |b|²) b = (10/20)(4, 2) = (2, 1).
- 5Check: a − (2, 1) = (−1, 2), and (−1, 2) · (4, 2) = −4 + 4 = 0, so the leftover part is perpendicular to b.
Answer: The scalar projection is √5 ≈ 2.24, and the vector projection is (2, 1).
Work done by a force at an angle
A rope pulls a sled 20 m across flat ground with a force of 50 N, at 30° above the ground. How much work does the rope do?
- 1Work is the dot product of force and displacement: W = F · d = |F||d| cos θ.
- 2The angle between the pull and the motion is 30°, and cos 30° = √3/2 ≈ 0.866.
- 3Multiply: W = 50 × 20 × √3/2 = 500√3.
- 4Round at the end: 500√3 ≈ 866.
Answer: W = 500√3 ≈ 866 J (joules).
Check yourself
1.What is (2, 5) · (3, −1)?Show answer
1, because 2 × 3 + 5 × (−1) = 6 − 5 = 1.
2.What is (1, −2, 4) · (3, 0, 2)?Show answer
11, because 3 + 0 + 8 = 11.
3.|a| = 4, |b| = 3 and the angle between them is 60°. What is a · b?Show answer
6, because 4 × 3 × cos 60° = 12 × ½ = 6.
4.The dot product of two nonzero vectors is 0. What is the angle between them?Show answer
90°. The vectors are perpendicular.
5.The dot product of two vectors is negative. Is the angle between them acute or obtuse?Show answer
Obtuse: more than 90°.
6.What is (3, 4) · (3, 4)?Show answer
25, the square of the vector's length, 5.
7.What is the angle between (1, 1) and (1, 0)?Show answer
45°, because cos θ = 1 / (√2 × 1) = 1/√2.
8.For what value of k are (k, 2) and (3, −6) perpendicular?Show answer
k = 4, because 3k − 12 = 0.
9.What is the scalar projection of (2, 7) onto (3, 4)?Show answer
6.8, because (6 + 28) / 5 = 34/5.
10.What is i · k?Show answer
0, because i and k are perpendicular unit vectors.
Common mistakes
- Giving a vector as the answer: (1, 4) · (4, 3) = (4, 12).Add the products: 4 + 12 = 16. The dot product is always a single number.
- Writing a · b = |a||b| sin θ.The dot product uses cos θ. Two vectors pointing the same way must give the largest value, |a||b|, and only cos 0° = 1 does that. sin θ belongs to the cross product.
- Reading a · b = 0 as meaning one of the vectors is zero.For nonzero vectors, a dot product of 0 means they are perpendicular: (2, −1, 3) · (4, 5, −1) = 0, and neither vector is zero.
- Dividing by only one length when finding the angle, or stopping at cos θ.Divide by both lengths, cos θ = a · b / (|a||b|), then take the inverse cosine. For (2, 1) and (−3, 1), cos θ = −5/√50 ≈ −0.707, so θ = 135°.
- Getting 0.785 for an angle that should be 45°.0.785 is 45° in radians, π/4. Set the calculator to degree mode, or multiply a radian answer by 180/π.
- Using |b| instead of |b|² in the vector projection: (a · b / |b|) b.That vector is |b| times too long. Use (a · b / |b|²) b, or multiply the scalar projection a · b / |b| by the unit vector b / |b|.
- Dividing by |a| for the scalar projection of a onto b.Divide by the length of the vector you project onto: the shadow of a on b is a · b / |b|.
Questions students ask
Is the dot product a scalar or a vector?
A scalar. Adding the products of matching components leaves one number with no direction, and in the picture it is a length times a length: the shadow of a on b times the length of b. The cross product is the product of two vectors that returns a vector.
Can the dot product be greater than 1?
Yes. Since a · b = |a||b| cos θ, it can be as large as the product of the two lengths: (3, 4) · (6, 8) = 18 + 32 = 50. Only for two unit vectors, each of length 1, does the dot product stay between −1 and 1, and then it equals cos θ exactly.
Why does the dot product use cosine and not sine?
Because it measures the part of one vector that lies along the other, and in a right triangle the side next to the angle is the hypotenuse times cos θ. The part that lies across the other vector is |a| sin θ, and that is what the cross product uses.
What is the dot product of two parallel vectors?
The product of their lengths, with a sign: |a||b| when they point the same way, since cos 0° = 1, and −|a||b| when they point in opposite directions, since cos 180° = −1. For example, (1, 2) and (3, 6) point the same way, and (1, 2) · (3, 6) = 3 + 12 = 15, which equals √5 × √45 = 15.
What is the dot product of i, j and k?
The unit vectors i, j and k each have length 1 and are perpendicular to one another, so i · i = j · j = k · k = 1 and i · j = j · k = k · i = 0. That is why the component formula works: expanding (a₁i + a₂j + a₃k) · (b₁i + b₂j + b₃k) leaves only a₁b₁ + a₂b₂ + a₃b₃, because every mixed term is 0.
Is the dot product the same as matrix multiplication?
No, but the two are closely related. Written as columns, a · b is the matrix product aᵀb, a row of n numbers times a column of n numbers. And every entry of a matrix product AB is the dot product of a row of A with a column of B.
What is the difference between the dot product and an inner product?
An inner product is any product of two vectors that is symmetric, linear in each vector and positive when a nonzero vector is paired with itself. The dot product is the standard inner product for vectors of real numbers. Other inner products exist, such as the integral of f(x)g(x) for functions, and vectors of complex numbers use a version with complex conjugates.
How is the dot product related to cosine similarity?
Cosine similarity is the dot product divided by the product of the lengths, a · b / (|a||b|), which is cos θ. Dividing by the lengths removes size and keeps only direction: (3, 4) · (6, 8) = 50, but their cosine similarity is 50 / (5 × 10) = 1, because they point the same way. Scores run from 1 for the same direction through 0 for perpendicular to −1 for opposite.
Is the dot product a projection?
Not quite: a · b is the scalar projection of a onto b times the length of b. When b is a unit vector, of length 1, the two are the same number. That is why dotting a vector with a unit vector reads off its component in that direction, as a · i gives the x-component of a.
Sources
Keep going
All math topicsLinear Algebra
Eigenvalues and eigenvectors, explained visually
An eigenvector of a square matrix A is a nonzero vector that A only stretches, shrinks or flips, never turning it off its own line: Av = λv. The number λ is its eigenvalue, the factor it is scaled by. To find them, solve det(A − λI) = 0 for λ, then solve (A − λI)v = 0 for v.
Trigonometry
The unit circle, explained visually
The unit circle is the circle of radius 1 centered at the origin. For any angle θ, measured counterclockwise from the positive x-axis, the point where the angle meets the circle is (cos θ, sin θ): cosine is the x-coordinate and sine is the y-coordinate. At 30°, the point is (√3/2, 1/2).
Geometry
The Pythagorean theorem, explained visually
The Pythagorean theorem says that in a right triangle, the square of the hypotenuse (the side across from the right angle) equals the sum of the squares of the other two sides: a² + b² = c². For legs 3 and 4, the hypotenuse is 5, because 9 + 16 = 25.