From Triangle Geometry to a Vector Formula
Two vectors based at the same point determine two sides of a triangle. The third side is the difference of the vectors. This simple geometric setup connects the law of cosines to the dot product: both describe the squared length of that third side, but in different ways.
The result is useful because it lets us find the angle between vectors from their components. The derivation also explains why the dot product contains information about angle, not only about coordinates.
Vectors, Lengths, and the Angle Between Them
For vectors \(\mathbf{a}\) and \(\mathbf{b}\) in three-dimensional space, their dot product is computed from components by multiplying corresponding components and adding the products. Their lengths, also called norms, are denoted by \(\|\mathbf{a}\|\) and \(\|\mathbf{b}\|\). For example, if \(\mathbf{a}=(a_1,a_2,a_3)\), then \(\|\mathbf{a}\|=\sqrt{a_1^2+a_2^2+a_3^2}\).
The angle between two nonzero vectors is the smaller angle formed when they are placed with their tails at the same point. When measured in radians, it satisfies \(0\leq\theta\leq\pi\). When measured in degrees, it satisfies \(0^\circ\leq\theta\leq180^\circ\). The vectors must be nonzero because a zero vector has no direction and therefore no angle with another vector.
Imagine placing the tails of \(\mathbf{a}\) and \(\mathbf{b}\) at a point \(O\). Let their endpoints be \(A\) and \(B\). Then \(OA=\|\mathbf{a}\|\), \(OB=\|\mathbf{b}\|\), and the vector from \(A\) to \(B\) is \(\mathbf{b}-\mathbf{a}\), so \(AB=\|\mathbf{b}-\mathbf{a}\|\). The angle at \(O\) is \(\theta\).
The Angle Formula
The law of cosines applied to triangle \(OAB\) says that the square of the side opposite \(\theta\) is the sum of the squares of the other two sides, minus twice their product times \(\cos\theta\). Thus, when the triangle is nondegenerate, it gives an expression for \(\|\mathbf{b}-\mathbf{a}\|^2\).
There is another way to calculate the same quantity. Using the dot product and its distributive properties, expand the squared norm of \(\mathbf{b}-\mathbf{a}\). Comparing these two expressions yields the central relationship.
Deriving the Relationship
We now justify the formula by calculating the same squared distance in two ways. First suppose \(\mathbf{a}\) and \(\mathbf{b}\) are not parallel. Then the points \(O,A,B\) form a nondegenerate triangle, so the ordinary law of cosines applies.
The side opposite the angle \(\theta\) has length \(\|\mathbf{b}-\mathbf{a}\|\). Therefore
A vector's squared norm is its dot product with itself. Using distributivity and symmetry of the dot product gives
Both expressions equal \(\|\mathbf{b}-\mathbf{a}\|^2\), so
This proves the formula when the vectors are not parallel. The parallel cases can be checked directly, so no degenerate triangle is needed in the argument. If \(\mathbf{b}=\lambda\mathbf{a}\) for a nonzero real number \(\lambda\), then \(\mathbf{a}\cdot\mathbf{b}=\lambda\|\mathbf{a}\|^2\), and \(\|\mathbf{b}\|=|\lambda|\|\mathbf{a}\|\). If \(\lambda>0\), the angle is \(0\), and the formula's right side is \(|\lambda|\|\mathbf{a}\|^2=\lambda\|\mathbf{a}\|^2\). If \(\lambda<0\), the angle is \(\pi\), and the right side is \(-|\lambda|\|\mathbf{a}\|^2=\lambda\|\mathbf{a}\|^2\). Thus the formula holds for all nonzero vectors.
Worked Examples
Worked Example: Find the Angle Between Two Vectors in the Plane
Let \(\mathbf{a}=(1,2)\) and \(\mathbf{b}=(3,1)\). First calculate their dot product and lengths:
Check the geometry directly. The difference is \(\mathbf{b}-\mathbf{a}=(2,-1)\), so \(\|\mathbf{b}-\mathbf{a}\|^2=2^2+(-1)^2=5\). The law of cosines gives
Worked Example: Obtain an Obtuse Angle in Three Dimensions
Let \(\mathbf{a}=(1,0,0)\) and \(\mathbf{b}=(-1,\sqrt{3},0)\). The dot product is
Worked Example: Use the Formula Without Simplifying the Angle
Let \(\mathbf{a}=(2,-1,2)\) and \(\mathbf{b}=(1,2,2)\). Compute the dot product:
A Common Expansion Mistake
A frequent error is to treat the squared length of a difference as the sum of the squared lengths, leaving out the cross terms. In general, \(\|\mathbf{b}-\mathbf{a}\|^2\) is not \(\|\mathbf{a}\|^2+\|\mathbf{b}\|^2\). The dot-product expansion shows exactly what is missing.
For a concrete example, take \(\mathbf{a}=(1,0)\) and \(\mathbf{b}=(1,1)\). The incorrect calculation would say \(\|\mathbf{b}-\mathbf{a}\|^2=1+2=3\). But \(\mathbf{b}-\mathbf{a}=(0,1)\), so the actual squared length is \(0^2+1^2=1\). The mistaken value would also give an incorrect angle: substituting \(3\) into the law of cosines would yield \(\cos\theta=(1+2-3)/(2\sqrt{2})=0\), despite the dot product being \(1\).
The correction is to retain the cross terms:
Why the Formula Matters
The formula converts geometric information into a component calculation. Once the dot product and lengths are known, the cosine of the angle follows by division. Conversely, if the angle and lengths are known, the formula gives the dot product. This is why the dot product is central to both coordinate calculations and geometric reasoning.
The nonzero condition matters in the angle formula: if either vector is zero, the denominator \(\|\mathbf{a}\|\|\mathbf{b}\|\) is zero, and the zero vector has no direction whose angle could be measured. For nonzero vectors, the earlier Cauchy-Schwarz inequality ensures that the ratio \((\mathbf{a}\cdot\mathbf{b})/(\|\mathbf{a}\|\|\mathbf{b}\|)\) lies between \(-1\) and \(1\), as required for the inverse cosine. The formula therefore produces an angle in the stated range.
Keep the geometric setup in mind: the two vectors are sides meeting at the angle, while their difference gives the opposite side. The law of cosines and the dot-product expansion are two descriptions of that same triangle, and equating them is the entire reason the angle formula works.
Check Your Understanding
Use the relationship between the law of cosines and the dot product to answer these questions.
- Why is \(\|\mathbf{b}-\mathbf{a}\|\) the length of the side opposite the angle between \(\mathbf{a}\) and \(\mathbf{b}\)?
- Expand \(\|\mathbf{b}-\mathbf{a}\|^2\) using dot products and identify the cross term.
- What is the angle range in radians, and what is the corresponding range in degrees?
- Why must both vectors be nonzero to use the angle formula?
- For \(\mathbf{a}=(1,1,0)\) and \(\mathbf{b}=(1,0,1)\), calculate the dot product, both norms, and \(\cos\theta\).