Law of Cosines
The law of cosines generalizes the Pythagorean theorem to any triangle, relating all three sides to the cosine of one of its angles.
Formula
c^2 = a^2 + b^2 - 2ab\cos(C)
Definition
The law of cosines is a formula for finding a missing side or angle in any triangle, not just right triangles: $c^2 = a^2 + b^2 - 2ab\cos(C)$, where $C$ is the angle between sides $a$ and $b$. Use it for SAS (two sides and included angle) to find the third side, or SSS (all three sides) to find angles via $\cos(C) = (a^2 + b^2 - c^2)/(2ab)$. It follows from the dot product formula, $c^2 = |a - b|^2 = |a|^2 - 2a \cdot b + |b|^2$ with $a \cdot b = |a||b|\cos(C)$, and in spherical trigonometry the analogue is $\cos(c) = \cos(a)\cos(b) + \sin(a)\sin(b)\cos(C)$.
Example
A triangle has sides $a = 7$, $b = 10$ with angle $C = 60^\circ$ between them: $c^2 = 49 + 100 - 140 \times 0.5 = 79$, so $c \approx 8.89$. For SSS with $a = 6$, $b = 8$, $c = 9$: $\cos(C) = (36 + 64 - 81)/96 \approx 0.198$, so $C \approx 78.6^\circ$. The law also gives the distance formula in $\mathbb{R}^2$ by applying it to the triangle formed by the origin and two points, with $C$ the angle at the origin.
Key Insight
When angle $C = 90^\circ$, $\cos(90^\circ) = 0$ and the formula becomes $c^2 = a^2 + b^2$, the Pythagorean theorem, its generalization for non-right angles; when $C$ is obtuse, $\cos(C) < 0$, making $c^2$ larger than $a^2 + b^2$, matching the intuition that obtuse triangles have a longer third side. The law of cosines is the metric identity in Euclidean geometry, and in a general inner product space it becomes $||u - v||^2 = ||u||^2 - 2\langle u,v \rangle + ||v||^2$, the foundation for Hilbert space geometry.