§1The law of cosines
For any triangle with sides a, b, c and opposite angles A, B, C:
c² = a² + b² − 2ab · cos C
a² = b² + c² − 2bc · cos A · b² = a² + c² − 2ac · cos B
It works for every triangle, acute or obtuse, and it is the tool to use when the law of sines can’t start because no side is paired with its opposite angle.
§2Solving SAS
With two sides and the angle between them, the formula gives the third side right away. Then solve one more angle with the law of cosines and get the last one from the angle sum.
a = 5, b = 7, C = 60°. c² = 25 + 49 − 2 · 5 · 7 · cos 60° = 74 − 35 = 39 → c = √39 ≈ 6.245
cos A = (b² + c² − a²) / (2bc) = (49 + 39 − 25) / (2 · 7 · 6.245) ≈ 0.7206 → A ≈ 43.90°
B = 180° − 43.90° − 60° ≈ 76.10°
§3Solving SSS
With three sides, rearrange the formula for the cosine of each angle, then take arccos:
cos C = (a² + b² − c²) / (2ab)
a = 7, b = 9, c = 12. cos C = (49 + 81 − 144) / 126 = −14/126 ≈ −0.1111 → C ≈ 96.38°
A negative cosine means an obtuse angle, and arccos handles that correctly because its range is 0° to 180°. The inverse cosine calculator shows why. The three sides must also pass the triangle inequality: each side has to be shorter than the other two combined. Sides 1, 2 and 3 fail, since 1 + 2 is not greater than 3, and the calculator says so.
§4Pythagoras as a special case
If C = 90°, then cos C = 0 and the formula becomes c² = a² + b², the Pythagorean theorem. The extra term −2ab · cos C is a correction for angles that are not right. It makes c shorter than the Pythagorean value when C is acute and longer when C is obtuse.
That gives a quick test with three sides: if c² > a² + b² for the longest side c, the triangle is obtuse; if c² = a² + b², it is right; and if c² < a² + b², it is acute.
§5Area with Heron’s formula
The calculator gives the area as ½ · a · b · sin C. With three sides you can also use Heron’s formula: with s = (a + b + c)/2, the area is √(s(s − a)(s − b)(s − c)). For 7, 9 and 12, s = 14 and the area is √(14 · 7 · 5 · 2) = √980 ≈ 31.305, the same value the panel shows.
§6Common mistakes
- Order of operations: compute 2ab · cos C first and subtract it from a² + b². Don’t multiply (a² + b² − 2ab) by cos C.
- Pairing the angle with the wrong side: C must be the angle between a and b, opposite c.
- Forgetting the square root at the end of SAS.
- Rounding cos C before taking arccos, which can shift the angle by a full degree in flat triangles.
§7FAQ
When should I use the law of cosines instead of the law of sines?
Use it for SSS and SAS, where no side is paired with its opposite angle. After one angle is known, either law can finish the triangle.
Can the law of cosines give two triangles?
No. SSS and SAS always determine a single triangle (or none, if the sides fail the triangle inequality).
Does it work with obtuse angles?
Yes. cos C is negative for obtuse C, so −2ab · cos C becomes positive and c comes out longer, exactly as it should.
What units should I use?
Any length unit, as long as all three sides use the same one. Angles are in degrees.