The Law of Cosines, Explained
The Pythagorean theorem only works on right triangles. The Law of Cosines is the generalization that works on any triangle, with one extra term that captures the angle.
The Law of Cosines says that for any triangle with sides a, b, and c, and the angle C opposite side c:
c² = a² + b² − 2ab·cos(C)
That's the formula. It's the Pythagorean theorem with a correction term that handles non-right triangles. When the angle C is exactly 90 degrees, cos(C) equals 0, the correction term vanishes, and you get back the regular Pythagorean theorem. The Law of Cosines is the more general form, and the Pythagorean theorem is the special case where the triangle happens to have a right angle.
The way I think about the Law of Cosines is that it's a sentence about how the angle between two sides distorts the third side. If the angle is small (sides nearly parallel), the third side is small. If the angle is large (close to 180 degrees), the third side is large. The cosine term encodes that relationship.
Plain English
Why the Formula Has That Shape
Imagine two vectors of lengths a and b with angle C between them. The third side c is the vector from the tip of one to the tip of the other.
From basic vector algebra, the squared length of the difference of two vectors is:
c² = |a − b|² = a·a − 2(a·b) + b·b
And from the dot product formula:
a·b = |a| · |b| · cos(C) = a·b·cos(C)
Plugging in:
c² = a² + b² − 2ab·cos(C)
So the Law of Cosines is just the dot-product formula written in side-length form. If you've seen vector dot products, the law is one substitution away.
The Three Cases the Law Solves
Most uses fall into three categories:
Case 1: SAS (Side-Angle-Side)
You know two sides and the angle between them. The Law of Cosines gives you the third side directly. Example: a triangle with sides 7 and 9 and an angle of 60° between them. The third side is:
c² = 49 + 81 − 2(7)(9)(0.5) = 49 + 81 − 63 = 67
So c = √67 ≈ 8.19.
Case 2: SSS (Side-Side-Side)
You know all three sides and want any angle. Solve the formula for the cosine:
cos(C) = (a² + b² − c²) / (2ab)
Then take the inverse cosine. Example: triangle with sides 5, 6, 7. The angle opposite the 7-side:
cos(C) = (25 + 36 − 49) / (60) = 12 / 60 = 0.2
So C = arccos(0.2) ≈ 78.46°.
Case 3: Confirming a Right Angle
If you know all three sides and want to verify a right angle exists, check whether a² + b² = c². If equal, the angle opposite c is exactly 90°. If smaller, that angle is acute. If larger, obtuse.
The Sister: Law of Sines
The Law of Cosines doesn't solve every triangle. For some configurations (ASA: two angles and the side between them; AAS: two angles and a non-included side), the Law of Sines is the right tool:
a / sin(A) = b / sin(B) = c / sin(C)
Together, the Law of Sines and Law of Cosines solve any triangle where you have enough information. They're the workhorses of triangle trigonometry.
What “Solving a Triangle” Means
Six pieces of information describe a triangle: three sides and three angles. Knowing some lets you compute the others. The cases where you have enough are:
- SSS (three sides): unique solution.
- SAS (two sides and included angle): unique solution.
- ASA (two angles and included side): unique solution.
- AAS (two angles and a non-included side): unique solution.
- SSA (two sides and a non-included angle): can have zero, one, or two solutions. The “ambiguous case.”
The Law of Cosines handles SSS and SAS cleanly. The Law of Sines handles ASA and AAS. SSA needs careful treatment because of the ambiguity.
Where the Law Shows Up
Beyond classroom math, the Law of Cosines appears whenever you're computing distances or angles between objects in 2D or 3D space:
- GPS triangulation. Computing position from distances to multiple satellites.
- Robotics and inverse kinematics. Computing joint angles from desired end-effector positions.
- Navigation. Calculating the third side of a triangle when only two sides and the angle between them are known (sailing, surveying).
- Computer graphics. Lighting calculations often use cosines of angles between surface normals and light directions.
Anywhere you'd use the Pythagorean theorem if the geometry were perfect, you use the Law of Cosines if it isn't.
Takeaway
The Law of Cosines extends the Pythagorean theorem to any triangle. The extra term, −2ab·cos(C), corrects for the angle between two sides. When the angle is 90°, the term vanishes. Combined with the Law of Sines, it solves any triangle given enough information.
The Take
The Law of Cosines is the generalization most students see right after the Pythagorean theorem and immediately forget. It deserves more attention. The fact that one extra term lets you handle every triangle, not just right triangles, is the kind of mathematical economy that's genuinely beautiful. The next time you see a triangle that's not a right triangle, you have a formula. The next time you see a right triangle, the formula simplifies to the one you already know. That's the math working as intended.
Written by
Tech Talk News Editorial
Tech Talk News covers engineering, AI, and tech investing for people who build and invest in technology.