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.
Key takeaways
- The Law of Cosines states that for any triangle, c squared equals a squared plus b squared minus 2ab times cos(C), where C is the angle opposite side c.
- The Pythagorean theorem is just the special case of the Law of Cosines where the angle is 90 degrees, because cos(90 degrees) equals 0 and the correction term vanishes.
- The Law of Cosines falls straight out of the vector dot product: c squared equals the squared length of the difference of two vectors, and the dot product formula turns that into side-length form.
- The Law of Cosines cleanly handles the SSS and SAS triangle cases, while the Law of Sines handles ASA and AAS, and SSA is the ambiguous case that can have zero, one, or two solutions.
- GPS triangulation, robotics inverse kinematics, navigation, and computer graphics lighting all lean on the Law of Cosines to get distances and angles out of imperfect geometry.
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, compare a² + b² against c². If they're equal, the angle opposite c is exactly 90°. If a² + b² is larger than c², that angle is acute. If it's smaller, the angle is obtuse. That's just the sign of the cosine term doing its job: cos(C) is positive for acute angles and negative for obtuse ones.
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.
Frequently asked questions
- What is the Law of Cosines formula?
- For any triangle with sides a, b, and c, and the angle C opposite side c, c squared equals a squared plus b squared minus 2ab times cos(C). It is the Pythagorean theorem with one correction term that accounts for the angle between the two known sides. The bigger the angle, the longer the third side.
- When should I use the Law of Cosines instead of the Law of Sines?
- Use the Law of Cosines for SSS (all three sides known) and SAS (two sides plus the angle between them). Use the Law of Sines for ASA (two angles plus the side between them) and AAS (two angles plus a non-included side). SSA is the ambiguous case and needs careful treatment because it can produce zero, one, or two valid triangles.
- How do you find an angle when you know all three sides?
- Rearrange the Law of Cosines to cos(C) = (a squared + b squared minus c squared) divided by 2ab, then take the inverse cosine. For a triangle with sides 5, 6, and 7, the angle opposite the 7-side is cos(C) = (25 + 36 - 49) / 60 = 0.2, so C = arccos(0.2), roughly 78.46 degrees.
- Can the Law of Cosines tell you if a triangle has a right angle?
- Yes. Compare a squared plus b squared against c squared. If they are equal, the angle opposite c is exactly 90 degrees. If a squared plus b squared is greater than c squared, that angle is acute. If it is less than c squared, the angle is obtuse. This falls straight out of the sign of the cos(C) term.
Written by
Tech Talk News Editorial
Computer engineering background. Writes about software, AI, markets, and real estate, and the places where the three meet.
More about the author