Law of Cosines Calculator: solve SAS and SSS triangles
Solve a triangle with the law of cosines: find the third side from two sides and the included angle (SAS), or all three angles from three sides (SSS), with area, perimeter, heights, medians, inradius, circumradius, triangle type and the worked steps.
How it works
SAS: a = √(b² + c² − 2bc·cos A) · SSS: cos A = (b² + c² − a²) ÷ 2bc, cos B = (a² + c² − b²) ÷ 2ac, C = 180° − A − B · Area = ½·b·c·sin A · Circumradius R = a ÷ (2 sin A) · Inradius r = Area ÷ s, s = (a + b + c) ÷ 2 · Height hₐ = 2·Area ÷ a · Median mₐ = ½√(2b² + 2c² − a²)
The law of cosines links the three sides of any triangle to one of its angles: a² = b² + c² − 2bc·cos A, where A is the angle between sides b and c and a is the side opposite it. When A is 90° the cosine is zero and the formula becomes the Pythagorean theorem; an acute angle makes a shorter than the right-angle case and an obtuse angle makes it longer. The calculator handles the two cases the law solves directly. With two sides and the included angle (SAS) it finds the third side, then uses the same law rearranged to get angle B and subtracts from 180° for angle C. With three sides (SSS) it rearranges the law to cos A = (b² + c² − a²) ÷ 2bc and does the same for B. Arccosine returns a single angle between 0° and 180°, so there is no ambiguity, unlike the law of sines. The three sides must satisfy the triangle inequality: the two shorter sides must add up to more than the longest. Once the triangle is solved you also get the area (½·b·c·sin A), perimeter, circumradius, inradius, the height and median to each side, and whether the triangle is acute, right or obtuse. You can enter the angle in degrees or radians.
Worked example
With b = 8, c = 6 and included angle A = 60°: a² = 8² + 6² − 2 × 8 × 6 × cos 60° = 64 + 36 − 96 × 0.5 = 52, so a = √52 = 7.2111. Then cos B = (52 + 36 − 64) ÷ (2 × 7.2111 × 6) = 0.27735, so B = 73.90° and C = 180° − 60° − 73.90° = 46.10°. The area is ½ × 8 × 6 × sin 60° = 20.7846, the perimeter is 21.2111, and since every angle is below 90° and all sides differ it is an acute scalene triangle. Its circumradius is 7.2111 ÷ (2 sin 60°) = 4.1633 and its inradius is 20.7846 ÷ 10.6056 = 1.9598.
Sources: Wikipedia: Law of cosines · Math is Fun: The Law of Cosines (worked examples) · Omni Calculator: Law of cosines (SAS and SSS examples) · Calculator.net: Triangle calculator (medians, inradius, circumradius)
Frequently asked questions
When do you use the law of cosines?
Use it when you know two sides and the angle between them (SAS) and need the third side, or when you know all three sides (SSS) and need the angles. If you know two angles and a side, or a side, its opposite angle and another side, the law of sines is the usual tool.
How is this related to the Pythagorean theorem?
It is the Pythagorean theorem plus a correction term. When A = 90°, cos A = 0, so a² = b² + c². For an acute angle the term −2bc·cos A is negative and shortens the side; for an obtuse angle cos A is negative and the side gets longer.
How do I find an angle from three sides?
Rearrange the law: cos A = (b² + c² − a²) ÷ (2bc), then take the arccosine. For sides 4, 5 and 6 the angles are 41.41°, 55.77° and 82.82°.
Why solve for angles with cosine, not sine?
Arccosine returns a unique angle between 0° and 180°, which is exactly the range a triangle’s angle can have. Arcsine cannot tell an acute angle from its obtuse partner (30° and 150° have the same sine), so the cosine avoids that ambiguity.
What is the included angle?
It is the angle formed where the two known sides meet. In this calculator angle A sits between sides b and c, and side a is opposite it. If your known angle is not between the two sides, use the law of sines instead.
Related calculators
This calculator is for educational purposes. Double-check important results before acting on them.