Skip to content

Law of Cosines Calculator

Solve any triangle from two sides and the included angle (SAS) or from three sides (SSS) with c² = a² + b² − 2ab·cos C.

Your details

Unit system
I know
Angle unit
°

Results update as you type

Third side c

6.0128 in

Angle A (opposite a)
56.2591 °
Angle B (opposite b)
93.7409 °
Angles in radians
A = 0.981906, B = 1.636088, C = 0.523599
Type of triangle
Obtuse scalene triangle
Area (Heron)
30 in²
Perimeter
28.0128 in

Step-by-step solution
  1. c² = a² + b² − 2ab·cos C = 10² + 12² − 2 × 10 × 12 × cos 30° = 36.1539
  2. c = √36.1539 = 6.0128 in
  3. cos A = (b² + c² − a²) / (2bc) = 0.555438 → A = 56.2591°
  4. B = 180° − A − C = 180° − 56.2591° − 30° = 93.7409°
  5. s = (a + b + c) / 2 = 14.0064 in; K = √(s(s − a)(s − b)(s − c)) = 30 in²
  6. Check: A + B + C = 180°

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:

c2=a2+b2−2abcos⁡Cc^2 = a^2 + b^2 - 2ab\cos C

It works in two classic situations, and this calculator handles both:

  • SAS — two sides and the included angle. You know aa, bb and the angle CC between them; the calculator returns the third side cc, then the angles AA and BB.
  • SSS — three sides. You know aa, bb and cc; it returns all three angles, starting with CC, the angle opposite cc.

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

  1. Choose SAS if you know two sides and the angle between them, or SSS if you know all three sides.
  2. Type the side lengths in any unit (all in the same one, or switch each field’s unit). Side aa faces angle AA, side bb faces BB, side cc faces CC.
  3. In SAS mode, enter the included angle CC in degrees or radians.
  4. Read the headline: the third side cc (SAS) or the angle CC (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 aa opposite angle AA, side bb opposite BB and side cc opposite CC:

c2=a2+b2−2abcos⁡Ca2=b2+c2−2bccos⁡Ab2=a2+c2−2accos⁡Bc^2 = a^2 + b^2 - 2ab\cos C \qquad a^2 = b^2 + c^2 - 2bc\cos A \qquad b^2 = a^2 + c^2 - 2ac\cos B

Solved for an angle, the same rule reads

cos⁡C=a2+b2−c22ab\cos C = \frac{a^2 + b^2 - c^2}{2ab}

When C=90∘C = 90^\circ, cos⁡C=0\cos C = 0 and the formula collapses to Pythagoras’ theorem, c2=a2+b2c^2 = a^2 + b^2: the law of cosines is its generalization to every triangle. The term −2abcos⁡C-2ab\cos C 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, K=s(s−a)(s−b)(s−c)K = \sqrt{s(s-a)(s-b)(s-c)} with s=a+b+c2s = \tfrac{a+b+c}{2}. Internally, the calculator evaluates the angles in a numerically stable form (tan⁡A=4K/(b2+c2−a2)\tan A = 4K / (b^2 + c^2 - a^2)) 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:

c2=1202+852−2×120×85×cos⁡64∘≈12,682.2c^2 = 120^2 + 85^2 - 2 \times 120 \times 85 \times \cos 64^\circ \approx 12,682.2

so c≈112.62c \approx 112.62 m. The angles at the two ends are A≈73.28°A \approx 73.28° (facing the 120 m side) and B≈42.72°B \approx 42.72°, and the triangle covers about 4,583.8 m².

SSS — the 13-14-15 triangle. With a=13a = 13, b=14b = 14, c=15c = 15: cos⁡C=(169+196−225)/(2×13×14)=140/364≈0.3846\cos C = (169 + 196 - 225)/(2 \times 13 \times 14) = 140/364 \approx 0.3846, so C≈67.38°C \approx 67.38°. In the same way A≈53.13°A \approx 53.13° and B≈59.49°B \approx 59.49°. Heron’s formula gives s=21s = 21 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 arcsin⁡\arcsin 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 cc to one decimal before computing AA can move the angle by several hundredths of a degree.
  • A pocket calculator must be in degree mode for cos⁡64∘\cos 64^\circ; in radian mode it computes cos⁡(64 rad)\cos(64\text{ rad}), a different number.
  • For a very small included angle, a2+b2a^2 + b^2 and 2abcos⁡C2ab\cos C are almost equal and digits cancel. The calculator uses the equivalent form c2=(a−b)2+4absin⁡2(C/2)c^2 = (a-b)^2 + 4ab\sin^2(C/2), 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

Last updated:

More Math calculators

People also use