The law of cosines is the rule that lets you solve oblique (non-right) triangles where the simple Pythagorean theorem and SOH-CAH-TOA do not apply. Students, engineers, surveyors and anyone working with triangles can use it to find a missing side from two sides and the angle between them, or to recover all three angles from three known sides.
How it works
The core identity is a² = b² + c² − 2bc·cos(A), where each lowercase side sits opposite the matching uppercase angle.
- SSS mode (three sides known): the tool rearranges the rule to
cos(A) = (b² + c² − a²) / (2bc)and takes the inverse cosine for angles A and B, then finds C as180° − A − B. - SAS mode (two sides and the included angle): it first computes the missing side
a = √(b² + c² − 2bc·cos(A)), then solves for the remaining angles the same way.
In both modes it also returns the area via ½·b·c·sin(A) and the perimeter as a + b + c. The cosine inputs are clamped to the range −1 to 1 to avoid rounding errors at the extremes.
Example
Take a triangle with sides a = 7, b = 8, c = 9 (SSS mode):
| Result | Value |
|---|---|
| Angle A | 48.19° |
| Angle B | 58.41° |
| Angle C | 73.40° |
| Area | 26.83 |
| Perimeter | 24 |
Angle A comes from cos(A) = (8² + 9² − 7²) / (2·8·9) = 96/144 = 0.6667, giving A ≈ 48.19°.
When to use the law of cosines vs other tools
| What you know | What you need | Rule to use |
|---|---|---|
| All 3 sides (SSS) | All 3 angles | Law of cosines |
| 2 sides + included angle (SAS) | 3rd side, other angles | Law of cosines |
| 2 angles + 1 side (AAS or ASA) | Remaining sides | Law of sines |
| Right angle + 2 other knowns | Remaining sides/angles | Pythagorean theorem / SOH-CAH-TOA |
| 2 sides + non-included angle (SSA) | Triangles | Law of sines (watch for ambiguous case) |
The law of cosines handles SSS and SAS cleanly; the law of sines is simpler for AAS/ASA but requires care with SSA (the ambiguous case can yield 0, 1, or 2 triangles).
Real-world applications
- Surveying: Given three measured distances between points on a boundary, find all interior angles.
- Navigation: Given the distance to two landmarks and the angle between them, find the distance between the landmarks.
- Structural engineering: Check the geometry of a triangulated truss frame from member lengths alone.
- Physics problems: Find the resultant magnitude of two force vectors given their magnitudes and the angle between them (SAS case).
- Computer graphics: Compute the angle at each vertex of a triangle polygon from the edge lengths.
Edge cases and validity
The triangle inequality must hold: every side must be shorter than the sum of the other two. If you enter sides 3, 4, 10, there is no valid triangle — no angle’s cosine can be outside −1 to 1, and the inverse cosine will have no real solution. The calculator checks this and reports it rather than silently returning NaN.
For a right triangle, the included angle is 90°. In SAS mode, cos(90°) = 0 so the law of cosines reduces to c² = a² + b² — the Pythagorean theorem as a special case.
All math happens locally in your browser — nothing is uploaded.