📘 CodingMarble Learn

Law of Cosines (Cosine Rule)

In any triangle, c² = a² + b² − 2ab cos C, where C is the angle between sides a and b. When C = 90°, cos C = 0 and it becomes Pythagoras. Use it to find the third side when you know two sides and the angle between them (SAS), or to find any angle when you know all three sides (SSS): cos C = (a² + b² − c²) ÷ 2ab.

🎬 Step-by-step story

  1. Angle C is 90°. Squares sit on each side. The red square plus the blue square fill the purple square: Pythagoras.
  2. Open angle C to 120°. Side c gets longer. The purple square is now bigger than a² + b². The extra is −2ab cos C.
  3. Close angle C to 60°. Side c gets shorter. The purple square is now smaller than a² + b², because 2ab cos C is taken away.
  4. Worked example (SAS): a = 5, b = 8, C = 60°. Find side c, one line at a time.
  5. Worked example (SSS): the sides are 5, 7 and 8. Find the angle facing the longest side.
  6. Free play: change a, b and angle C. The rule c² = a² + b² − 2ab cos C is always true.

Tip: drag the 3D scene to turn it. Use two fingers to zoom.

🤔 Common doubts, cleared

How is this linked to Pythagoras?

At C = 90° the squares on a and b exactly fill the square on c, and the correction term is zero.

Why does c get longer when the angle opens?

The ends of a and b move apart. cos C turns negative past 90°, so −2ab cos C adds area.

Why is there a minus sign?

For acute angles side c is shorter than in a right triangle, so we take 2ab cos C away.

Do I square-root before subtracting?

No. Work out a² + b² − 2ab cos C completely, then take the square root at the very end.

Which angle should I find first from three sides?

The largest angle, facing the longest side. Then the other two must be acute.

Does it work for any a, b and C?

Yes. In free play every setting of the sliders keeps c² = a² + b² − 2ab cos C.

What is the law of cosines?

In triangle ABC, side a faces angle A, side b faces B and side c faces C. Angle C sits between sides a and b.

The law of cosines (also called the cosine rule) says:

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

The same pattern works for every side:

Pattern: the side on the left faces the angle on the right.

Pythagoras is a special case

When C = 90°, cos C = 0, so the last term vanishes and c² = a² + b². That is Pythagoras.

This gives a quick test for the type of triangle from its sides: compare c² with a² + b² for the longest side c.

Why it is true: the proof

Put C at the origin and side b along the x-axis, so A = (b, 0). Point B is a distance a from C at angle C, so B = (a cos C, a sin C).

Side c is the distance from A to B:

c² = (a cos C − b)² + (a sin C)²
= a² cos² C − 2ab cos C + b² + a² sin² C
= a²(cos² C + sin² C) + b² − 2ab cos C
= a² + b² − 2ab cos C, because cos² C + sin² C = 1.

The proof works for any angle C, acute or obtuse.

Solving triangles: SAS and SSS

Two sides and the angle between them (SAS)

Put the numbers straight in: a = 5, b = 8, C = 60° gives c² = 25 + 64 − 80 × 0.5 = 49, so c = 7.

Three sides (SSS)

Rearrange to find an angle: cos C = (a² + b² − c²) ÷ 2ab. Find the largest angle first (facing the longest side); then the others are acute and you can safely use the sine rule.

Sides 5, 7, 8: cos C = (25 + 49 − 64) ÷ 70 ≈ 0.143, so C ≈ 81.8°.

Sine rule or cosine rule?

Exam tips and uses

Key formulas and definitions

Worked examples

1. a = 5, b = 8, C = 60°. Find c.

c² = 25 + 64 − 2 × 5 × 8 × cos 60° = 89 − 80 × 0.5 = 49. c = 7.

2. a = 4, b = 6, C = 120°. Find c.

cos 120° = −0.5. c² = 16 + 36 − 2 × 4 × 6 × (−0.5) = 52 + 24 = 76. c = √76 ≈ 8.72.

3. Sides are 5, 7 and 8. Find the largest angle.

Largest angle faces 8. cos C = (25 + 49 − 64) ÷ (2 × 5 × 7) = 10 ÷ 70 ≈ 0.1429. C ≈ 81.8°.

4. Sides are 3, 5 and 7. Is the triangle acute, right or obtuse? Find the largest angle.

7² = 49 and 3² + 5² = 34. 49 > 34, so obtuse. cos C = (9 + 25 − 49) ÷ 30 = −0.5, so C = 120°.

5. Two ships leave a port. One sails 30 km and the other 40 km, on courses 70° apart. How far apart are they?

d² = 30² + 40² − 2 × 30 × 40 × cos 70° = 900 + 1600 − 2400 × 0.3420 = 2500 − 820.8 = 1679.2. d ≈ 41.0 km.

6. A parallelogram has sides 6 cm and 10 cm with an angle of 60° between them. Find both diagonals.

Short diagonal: d² = 36 + 100 − 120 × cos 60° = 76, d ≈ 8.72 cm. Long diagonal uses the angle 120°: d² = 136 − 120 × (−0.5) = 196, d = 14 cm.

7. Sides 2, 3 and 6. Is this a triangle?

cos C = (4 + 9 − 36) ÷ 12 = −1.92, which is less than −1. Impossible, so no triangle (also 2 + 3 < 6).

Common mistakes

Practice quiz

1. The law of cosines is:
2. If C = 90°, the cosine rule becomes:
3. You know all three sides. Which rule finds an angle first?
4. If c² > a² + b², angle C is:
5. a = 3, b = 4, C = 90°. c = ?

Practice: answer these yourself

Type or choose your answer, then press Check. Use a hint if you are stuck; the full solution appears after you answer.

Frequently asked questions

When should I use the cosine rule?

When you know two sides and the angle between them (SAS), or all three sides (SSS).

How do you find an angle with the cosine rule?

Use cos C = (a² + b² − c²) ÷ 2ab, then take inverse cosine.

Is the cosine rule the same as Pythagoras' theorem?

It is a general form. When the angle is 90°, cos C = 0 and it becomes Pythagoras.

Where this is taught

RomaniaClasa a IX-aTrigonometry and applications in geometry
Ukraine9 класSolving triangles
Russia9 классSolving triangles

Learn first

Learn next

Related lessons

All Maths lessons