Law of Cosines Calculator

Solve triangles using the law of cosines. Find a missing side from two sides and an included angle, or find angles from three sides. Shows working.

Ad
Ad

About Law of Cosines Calculator

Solve triangles using the law of cosines: c² = a² + b² - 2ab cos(C). Find a missing side from two sides and the included angle (SAS), or find all three angles from three known sides (SSS). Step-by-step working with area and perimeter included.

The Law of Cosines Formula

The law of cosines relates the sides and angles of any triangle:

c² = a² + b² - 2ab cos(C)

There are three forms, one for each side:

To FindFormula
Side cc² = a² + b² - 2ab cos(C)
Side bb² = a² + c² - 2ac cos(B)
Side aa² = b² + c² - 2bc cos(A)

To find an angle when all three sides are known, rearrange:

cos(C) = (a² + b² - c²) / (2ab)

Worked Example: SAS (Find Missing Side)

Given: a = 7, b = 10, C = 55°

  1. c² = 7² + 10² - 2(7)(10)cos(55°)
  2. c² = 49 + 100 - 140 × 0.5736
  3. c² = 149 - 80.30 = 68.70
  4. c = √68.70 = 8.289

Now find the remaining angles using the rearranged formula:

  1. cos(A) = (b² + c² - a²) / (2bc) = (100 + 68.70 - 49) / (2 × 10 × 8.289) = 119.70/165.78 = 0.7222
  2. A = arccos(0.7222) = 43.73°
  3. B = 180° - 55° - 43.73° = 81.27°

Area: (1/2) × 7 × 10 × sin(55°) = 35 × 0.8192 = 28.67 square units

Worked Example: SSS (Find All Angles)

Given: a = 5, b = 7, c = 9

  1. First check triangle inequality: 5+7=12 > 9, 5+9=14 > 7, 7+9=16 > 5 ✓
  2. Find largest angle first (opposite longest side c):
  3. cos(C) = (5² + 7² - 9²) / (2 × 5 × 7) = (25 + 49 - 81) / 70 = -7/70 = -0.1
  4. C = arccos(-0.1) = 95.74° (obtuse - as expected for the longest side)
  5. cos(A) = (7² + 9² - 5²) / (2 × 7 × 9) = (49 + 81 - 25) / 126 = 105/126 = 0.8333
  6. A = arccos(0.8333) = 33.56°
  7. B = 180° - 95.74° - 33.56° = 50.70°

Verify: 33.56° + 50.70° + 95.74° = 180.00° ✓

Connection to the Pythagorean Theorem

When angle C = 90°, cos(90°) = 0, so the law of cosines becomes:

c² = a² + b² - 2ab(0) = a² + b²

This is exactly the Pythagorean theorem. The law of cosines is the general version that works for all triangles, not just right triangles.

Angle Ccos(C)Effect on c²Triangle Type
Less than 90°Positivec² < a² + b²Acute
Exactly 90°0c² = a² + b²Right
Greater than 90°Negativec² > a² + b²Obtuse

When to Use Law of Cosines vs Law of Sines

Given InformationBest MethodWhy
SAS (two sides + included angle)Law of CosinesDirectly finds the third side
SSS (three sides)Law of CosinesDirectly finds any angle
AAS (two angles + any side)Law of SinesSimpler calculation
ASA (two angles + included side)Law of SinesFind third angle first, then use ratios
SSA (two sides + non-included angle)Law of SinesBut watch for ambiguous case

Triangle Area from Three Sides (Heron's Formula)

When you know all three sides, you can find the area without computing any angles:

s = (a + b + c) / 2 (semi-perimeter)

Area = √(s(s-a)(s-b)(s-c))

Example: a = 5, b = 7, c = 9

  • s = (5 + 7 + 9) / 2 = 10.5
  • Area = √(10.5 × 5.5 × 3.5 × 1.5) = √303.1875 = 17.41 square units

The Triangle Inequality

Before solving, the calculator checks that a valid triangle can exist. The triangle inequality states that the sum of any two sides must be greater than the third side:

  • a + b > c
  • a + c > b
  • b + c > a

If any of these fail, no triangle exists and the calculator shows an error.

For SSA problems with possible ambiguous solutions, the law of sines calculator checks for multiple triangles. For right triangle problems specifically, the Pythagorean theorem calculator provides a simpler interface.

All calculations run in your browser. No data is sent to any server.

Frequently Asked Questions

What is the law of cosines?

The law of cosines states c squared = a squared + b squared minus 2ab times cos(C), where C is the angle between sides a and b. It generalises the Pythagorean theorem to non-right triangles.

When should I use the law of cosines instead of the law of sines?

Use the law of cosines when you have SSS (three sides) or SAS (two sides and the included angle). The law of sines is better for AAS, ASA, or SSA cases.

How is this related to the Pythagorean theorem?

When angle C is exactly 90 degrees, cos(90) equals 0, so the formula simplifies to c squared = a squared + b squared, which is the Pythagorean theorem. The calculator flags this special case.

Can I find all three angles from three sides?

Yes. Use the rearranged formula cos(C) = (a squared + b squared - c squared) / (2ab) to find each angle. Enter all three sides in the Find Missing Angle mode.

What if my triangle does not satisfy the triangle inequality?

If any one side is longer than the sum of the other two, no valid triangle exists. The calculator validates this and will not return a result for invalid side combinations.

Link to this tool

Copy this HTML to link to this tool from your website or blog.

<a href="https://toolboxkit.io/tools/law-of-cosines-calculator/" title="Law of Cosines Calculator - Free Online Tool">Try Law of Cosines Calculator on ToolboxKit.io</a>