The Law of Cosines: Pythagoras Generalized for Any Triangle

The Law of Cosines: Pythagoras Generalized for Any Triangle
The Law of Cosines: Pythagoras Generalized for Any Triangle | Ideasthesia

The Pythagorean theorem only works for right triangles. The Law of Cosines works for all of them.

c² = a² + b² - 2ab cos C

Here's the unlock: the term - 2ab cos C is the correction factor. It tells you how much to add or subtract from the Pythagorean result because your triangle isn't a right triangle.

When C = 90°, cos C = 0, and the correction vanishes. You get c² = a² + b². Pythagoras.

When C < 90° (acute), cos C is positive, and you subtract. The triangle is "more closed," so the opposite side is shorter than Pythagoras predicts.

When C > 90° (obtuse), cos C is negative, so -2ab cos C is actually added. The triangle is "more open," and the opposite side is longer.

The Law of Cosines is Pythagoras with an angle adjustment.


The Formula

For a triangle with sides a, b, c and opposite angles A, B, C:

c² = a² + b² - 2ab cos C

Equivalently:

  • a² = b² + c² - 2bc cos A
  • b² = a² + c² - 2ac cos B

The formula relates any side to the other two sides and the included angle.


Finding a Side

Problem: Two sides of a triangle are 8 and 11, and the angle between them is 40°. Find the third side.

Let a = 8, b = 11, C = 40°.

c² = 8² + 11² - 2(8)(11)cos 40° c² = 64 + 121 - 176(0.766) c² = 185 - 134.8 c² = 50.2 c ≈ 7.1


Finding an Angle

Rearrange to solve for the cosine:

cos C = (a² + b² - c²) / 2ab

Problem: A triangle has sides 5, 7, and 9. Find the largest angle.

The largest angle is opposite the largest side (9). Call it C.

cos C = (5² + 7² - 9²) / (2 × 5 × 7) cos C = (25 + 49 - 81) / 70 cos C = -7/70 = -0.1 C = arccos(-0.1) ≈ 95.7°

Negative cosine means obtuse angle. ✓


Why It Works

Place the triangle on a coordinate plane with:

  • Vertex C at the origin
  • Side a along the positive x-axis
  • Vertex B at coordinates (a, 0)

Vertex A is at angle C from the x-axis, at distance b from the origin: A = (b cos C, b sin C)

The distance from A to B (which is side c) is: c² = (b cos C - a)² + (b sin C)² c² = b²cos²C - 2ab cos C + a² + b²sin²C c² = a² + b²(cos²C + sin²C) - 2ab cos C c² = a² + b² - 2ab cos C

The cos²C + sin²C = 1 identity does the heavy lifting.


The Three Cases

Acute triangle (all angles < 90°):

  • All cosines are positive
  • All corrections are subtractive
  • Each side is shorter than √(sum of other two sides squared)

Right triangle (one 90° angle):

  • cos 90° = 0
  • No correction needed for that angle
  • Law of Cosines = Pythagorean theorem

Obtuse triangle (one angle > 90°):

  • One cosine is negative
  • That correction adds instead of subtracting
  • The side opposite the obtuse angle is longer than Pythagoras predicts

When to Use It

Law of Cosines is the right tool when you have:

  • Side-Angle-Side (SAS): Two sides and the included angle
  • Side-Side-Side (SSS): All three sides (to find angles)

Law of Sines is better when you have:

  • Angle-Angle-Side (AAS) or Angle-Side-Angle (ASA)
  • Two sides and a non-included angle (with ambiguity caution)

Checking Triangle Validity

The Law of Cosines can verify if three lengths form a valid triangle.

For sides a, b, c: cos C = (a² + b² - c²) / 2ab

If this gives a value between -1 and 1, C is a valid angle. If |result| > 1, no such triangle exists.

Example: Can 3, 4, 10 form a triangle? cos C = (9 + 16 - 100) / 24 = -75/24 = -3.125

Since -3.125 < -1, no. (The third side is too long — violates triangle inequality.)


Connection to Dot Products

In linear algebra, the law of cosines appears naturally.

For vectors a and b: |a - b|² = |a|² + |b|² - 2|a||b|cos θ

where θ is the angle between them.

The dot product formula a · b = |a||b|cos θ makes this: |a - b|² = |a|² + |b|² - 2(a · b)

The Law of Cosines is the magnitude formula for vector subtraction.


The General Distance Formula

In coordinate geometry, the distance formula is: d = √[(x₂-x₁)² + (y₂-y₁)²]

This is the Law of Cosines with cos C = 0 (right angle at the origin).

The Law of Cosines generalizes distance measurement to triangles that aren't aligned with coordinate axes.


Example: Navigation

A ship sails 15 km east, then 20 km at a bearing of 35° north of east. How far is it from the starting point?

This forms a triangle. The angle at the turn is 180° - 35° = 145° (supplementary).

c² = 15² + 20² - 2(15)(20)cos 145° c² = 225 + 400 - 600(-0.819) c² = 625 + 491.4 c² = 1116.4 c ≈ 33.4 km


The Core Insight

The Law of Cosines extends Pythagoras to all triangles by adding an angle correction.

When the included angle is 90°, no correction is needed — you get pure Pythagoras. When the angle is less than 90°, the opposite side is shorter than Pythagoras predicts, so you subtract. When greater than 90°, the opposite side is longer, so you add.

This isn't a separate formula to memorize alongside Pythagoras. It's the same insight — relating sides through squared distances — with the generalization that lets it work when there's no right angle.

Pythagoras is the special case. The Law of Cosines is the general truth.


Part 7 of the Trigonometry series.

Previous: The Law of Sines: Every Triangle Is a Circle Trying to Express Itself Next: SOH CAH TOA: The Mnemonic That Hides the Meaning