Law of Cosines Calculator
Type two sides and the angle between them to get the third side…
Type two sides and the angle between them to get the third side, or three sides to get the angles. The law of cosines works for every triangle.
Two sides and the angle between them (SAS). Each angle sits opposite the side with its letter.
More optionsNo length unit
Length unit
A label for the answers; the maths is the same in any unit.
ExampleSide c
7
The triangle is obtuse and scalene, with one angle over 90°.
Type your own values, or drag a corner.
Drag the round handles on the corners.
| Side | Opposite angle |
|---|---|
| a = 3given | A = 21.787° |
| b = 5given | B = 38.213° |
| c = 7 | C = 120°given |
Area 15√3/4 ≈ 6.4952Perimeter 15
Area, perimeter, heights and circlesEvery other measurement of this triangle
| Area | 15√3/4 ≈ 6.4952 square units |
|---|---|
| Perimeter | 15 |
| Height to side a | 4.3301 |
| Height to side b | 2.5981 |
| Height to side c | 1.8558 |
| Inradius (inscribed circle) | 0.866 |
| Circumradius (circle through the corners) | 4.0415 |
| Angles in radians | A 0.3803, B 0.6669, C 2.0944 |
How this works: 6 sources,
How this works
Method
The law of cosines extends Pythagoras to every triangle: c² = a² + b² − 2ab·cos C. When C is 90°, cos C is 0 and it is the Pythagorean theorem; when C is wider, cos C is negative and the third side comes out longer than Pythagoras would say, and when it is narrower, shorter. Full method
Sources
How it’s tested
4 worked examples for this page are checked by automated tests before every release: given the inputs, the tool must show the expected answer.
Privacy
On your device. Nothing you enter or open leaves this browser. About privacy labels
Changes
- First published: any three values, both triangles in the ambiguous case, exact answers, worked steps, a drawing you can drag and seven focused pages.
How the law of cosines works
The law of cosines extends Pythagoras to every triangle: c² = a² + b² − 2ab·cos C. When C is 90°, cos C is 0 and it is the Pythagorean theorem; when C is wider, cos C is negative and the third side comes out longer than Pythagoras would say, and when it is narrower, shorter.
With two sides and the angle between them (SAS), it gives the third side at once. For b = 8, c = 11 and A = 37°: a² = 64 + 121 − 2 × 8 × 11 × cos 37° ≈ 44.4402, so a ≈ 6.6663. Then either law finds the other angles; using the law of cosines again for the smaller one avoids the ambiguity of the sine.
With all three sides (SSS) it runs the other way: cos C = (a² + b² − c²) ÷ 2ab. Every cosine between −1 and 1 belongs to exactly one angle between 0° and 180°, so, unlike the law of sines, there is never a second answer to check. The example triangle above, with sides 3 and 5 at 120°, has a third side of exactly 7, because cos 120° = −1/2.
c² = a² + b² − 2ab·cos C
- Euclid proved the law of cosines in geometric form about 300 BC, without the word cosine, in two propositions: one for obtuse triangles and one for acute ones. Source: Euclid’s Elements, Book II, Propositions 12 and 13 (D. E. Joyce’s edition).
- Solving a triangle from two sides and the included angle (SAS) or three sides (SSS) always has one solution when a triangle exists. Source: Wikipedia, Solution of triangles.
Third side for sides 5 and 8 at different angles
The side opposite angle A when b = 5 and c = 8, for A from 15° to 165°, exact where cos A is a known surd.
| Angle A | cos A | a² | Side a | Exact |
|---|---|---|---|---|
| 15° | (√2 + √6)/4 | 11.7259 | 3.4243 | √(89 − 20√2 − 20√6) |
| 30° | √3/2 | 19.718 | 4.4405 | √(89 − 40√3) |
| 45° | √2/2 | 32.4315 | 5.6949 | √(89 − 40√2) |
| 60° | 1/2 | 49 | 7 | — |
| 75° | (√6 − √2)/4 | 68.2945 | 8.264 | √(89 + 20√2 − 20√6) |
| 90° | 0 | 89 | 9.434 | √89 |
| 105° | (√2 − √6)/4 | 109.7055 | 10.474 | √(89 − 20√2 + 20√6) |
| 120° | −1/2 | 129 | 11.3578 | √129 |
| 135° | −√2/2 | 145.5685 | 12.0652 | √(89 + 40√2) |
| 150° | −√3/2 | 158.282 | 12.581 | √(89 + 40√3) |
Show all 11 rowsShow fewer
| 165° | (−√2 − √6)/4 | 166.2741 | 12.8947 | √(89 + 20√2 + 20√6) |
Common questions
What is the law of cosines used for in real life?
Anywhere two distances and the angle between them are known: the straight-line distance between two places from a surveyor’s readings, the third side of a roof truss, or how far apart two ships are after sailing on different headings from the same port.
Is the law of cosines the same as the cosine rule?
Yes. British schools call it the cosine rule, American ones the law of cosines. It is written for any side: a² = b² + c² − 2bc·cos A, and the same pattern for b and c.
Why do I get no triangle from three sides?
Because the longest side is at least as long as the other two together, so they can’t meet. The cosine would come out below −1. Sides 2, 3 and 6 fail: 2 + 3 = 5 is less than 6.