The law of cosines generalises the Pythagorean theorem to every triangle: the −2ab·cos γ term corrects for the angle not being 90°. Surveyors, navigators and engineers use it whenever two sides and the angle between them (or all three sides) are known.
How to use the Law of Cosines Calculator
- What do you know?
- Side a
- Side b
- Angle γ (between a and b)
- Side c
Results update as you type, and everything is calculated in your browser.
How it works
For SAS, the third side comes straight from the formula, and the other angles follow from the rearranged formula. For SSS, each angle is found with arccos. The three sides must satisfy the triangle inequality.
Inputs explained
| Field | What to enter |
|---|---|
| What do you know? | Choose one: Two sides and the angle between them (SAS), Three sides (SSS) |
| Side a | Units: cm, m, mm, in, ft, yd … |
| Side b | Units: cm, m, mm, in, ft, yd … |
| Angle γ (between a and b) | Units: °, rad, π rad, grad, turn |
| Side c | Units: cm, m, mm, in, ft, yd … |
What each result means
- Angle α (opposite a) = deg(acos(([Side b]^2 + [Side c]^2 – [Side a]^2)÷(2×[Side b]×[Side c])))
- Angle β (opposite b) = deg(acos(([Side a]^2 + [Side c]^2 – [Side b]^2)÷(2×[Side a]×[Side c])))
- Angle γ (opposite c) = 180 – [Angle α (opposite a)] – [Angle β (opposite b)]
- Area = [Side a]×[Side b]×sin(rad([Angle γ (opposite c)]))÷2
- Perimeter = [Side a] + [Side b] + [Side c]
Example values
How the main result changes when Side a changes and everything else stays at the example values above:
| Side a (cm) | Side c (cm) |
|---|---|
| 3.5 | 8.2009 |
| 5.25 | 7.7505 |
| 7 | 7.6818 |
| 8.75 | 8.0047 |
| 10.5 | 8.6755 |
| 14 | 10.7712 |
Formula
c² = a² + b² − 2ab·cos γ
γ = arccos((a² + b² − c²)/(2ab))
Worked example
Inputs: What do you know?: Two sides and the angle between them (SAS); Side a: 7 cm; Side b: 10 cm; Angle γ (between a and b): 50 °.
Results: Side c = 7.681779 cm; Angle α (opposite a) = 44.2712 °; Angle β (opposite b) = 85.7288 °; Angle γ (opposite c) = 50 °; Area = 26.811556 cm²; Perimeter = 24.681779 cm.
Key terms
- SAS
- Two sides and the included angle.
- SSS
- Three sides.
Frequently asked questions
When do I use the law of cosines?
When you know SAS or SSS; for other cases use the law of sines.
What if γ = 90°?
cos 90° = 0 and the formula becomes Pythagoras: c² = a² + b².
Can the law of cosines give an obtuse angle?
Yes. Arccos returns angles up to 180°, so there is no ambiguity.
What if the sides do not form a triangle?
The arccos argument leaves [−1, 1] and no angles can be found.