The law of cosines is the rule that solves a triangle when the angle you know is not one you can use with the law of sines. It links the three sides to one angle:
It works in two classic situations, and this calculator handles both:
- SAS — two sides and the included angle. You know , and the angle between them; the calculator returns the third side , then the angles and .
- SSS — three sides. You know , and ; it returns all three angles, starting with , the angle opposite .
Each result also lists the angles in radians, the type of triangle (acute, right or obtuse; scalene, isosceles or equilateral), the perimeter, and the area from Heron’s formula. Lengths accept any unit, angles can be typed in degrees or radians, and the step-by-step section shows every substitution with your numbers.
When one of the known angles faces a known side — two angles and a side, or the ambiguous side–side–angle case — the law of sines calculator is the right tool. To check first whether three lengths can close into a triangle at all, use the triangle inequality calculator.
How to use this calculator
- Choose SAS if you know two sides and the angle between them, or SSS if you know all three sides.
- Type the side lengths in any unit (all in the same one, or switch each field’s unit). Side faces angle , side faces , side faces .
- In SAS mode, enter the included angle in degrees or radians.
- Read the headline: the third side (SAS) or the angle (SSS). The other angles, the area, the perimeter and the type of triangle follow, then the full working.
If the three sides break the triangle inequality, the calculator says which sum is too short instead of returning a meaningless angle.
The formula
With side opposite angle , side opposite and side opposite :
Solved for an angle, the same rule reads
When , and the formula collapses to Pythagoras’ theorem, : the law of cosines is its generalization to every triangle. The term is the correction — negative for an acute angle (the side is shorter than the Pythagorean value), positive for an obtuse angle (longer).
The area comes from Heron’s formula, with . Internally, the calculator evaluates the angles in a numerically stable form () so that very flat or very small triangles keep full precision; the result is the same angle as the arccosine above.
Worked example
SAS — distance across a pond. From a stake on the shore you measure 120 m to one end of a pond and 85 m to the other, with an angle of 64° between the two tapes. The width of the pond is the third side:
so m. The angles at the two ends are (facing the 120 m side) and , and the triangle covers about 4,583.8 m².
SSS — the 13-14-15 triangle. With , , : , so . In the same way and . Heron’s formula gives and an area of exactly 84 square units.
Which rule should you use?
| You know | Use | Number of solutions |
|---|---|---|
| Three sides (SSS) | Law of cosines | One, if the triangle inequality holds |
| Two sides and the angle between them (SAS) | Law of cosines | Always one |
| Two angles and any side (ASA, AAS) | Law of sines | One |
| Two sides and an angle not between them (SSA) | Law of sines | Zero, one or two |
| A right angle | Right triangle calculator | One |
After the law of cosines has given the third side, it is tempting to finish with the law of sines. That works, but only returns angles up to 90°, so an obtuse angle can be missed. Using the law of cosines again for the second angle avoids the trap, which is what the steps above do.
Precision tips
- Keep full precision in intermediate values: rounding to one decimal before computing can move the angle by several hundredths of a degree.
- A pocket calculator must be in degree mode for ; in radian mode it computes , a different number.
- For a very small included angle, and are almost equal and digits cancel. The calculator uses the equivalent form , which keeps every digit.
Frequently asked questions
What is the law of cosines used for?
To solve a triangle when you know three sides, or two sides and the angle between them. Surveyors use it to measure distances that cannot be walked, navigators to combine two legs of a route, and engineers to find the length of a brace between two members at a known angle.
How do I find an angle from three sides?
Rearrange the formula: cos C = (a² + b² − c²) / (2ab), then take the inverse cosine. Repeat with the other sides for A and B, or use A + B + C = 180° for the last angle.
How is the law of cosines related to Pythagoras’ theorem?
Pythagoras is the special case C = 90°: cos 90° = 0, so the extra term vanishes and c² = a² + b². For any other angle the term −2ab·cos C corrects the result.
Can the law of cosines give two answers?
No. Given SAS or SSS, the triangle is unique, and the inverse cosine returns exactly one angle between 0° and 180°. The ambiguous case belongs to the law of sines with two sides and a non-included angle.
Why does the calculator reject my three sides?
The longest side must be strictly shorter than the sum of the other two. With 3, 4 and 8, for instance, 3 + 4 = 7 is less than 8, so the sides cannot meet. If the sum is exactly equal, the “triangle” is flat and has no angles to compute.
Sources
- OpenStax, Precalculus 2e, §8.2 Non-right Triangles: Law of Cosines
- Euclid, Elements, Book II, Propositions 12–13 (D. E. Joyce, Clark University)
- Weisstein, E. W., “Law of Cosines”, MathWorld (Wolfram Research)
Last updated: