Law of Cosines Calculator - Find c²=a²+b²-2abcosC

Law of Cosines Calculator

Solve triangles using c² = a² + b² - 2ab·cos(C)

Sides:

Angles (degrees):

Angle unit:

Try Examples:

About the Law of Cosines

Law of Cosines: For any triangle with sides a, b, c and opposite angles A, B, C:

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

b² = a² + c² - 2ac·cos(B)

a² = b² + c² - 2bc·cos(A)

When to Use:

  • SAS: Two sides and included angle
  • SSS: All three sides known
  • When Law of Sines doesn't apply

Special Cases:

  • When C = 90°: c² = a² + b² (Pythagorean theorem)
  • When C > 90°: cos(C) < 0
  • When C < 90°: cos(C) > 0

Share this calculator

Help others solve their calculations

Found this calculator helpful? Share it with your friends, students, or colleagues who might need it!

Law of Cosines Calculator: Solve SAS and SSS Step by Step

📅 Published:
Law of Cosines Calculator solving SSS or SAS triangles with c² = a² + b² − 2abcosC and a labeled triangle diagram.

The law of cosines calculator solves any triangle where you know three sides (SSS) or two sides and the included angle (SAS). It applies the formula c² = a² + b² − 2ab·cos(C) — essentially the Pythagorean theorem with a correction term that accounts for non-right angles. Plug in your values above and it returns all missing sides, angles, area, and perimeter with step-by-step work.

The Formula and Why It Works

For any triangle with sides a, b, c opposite angles A, B, C:

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

b² = a² + c² − 2ac·cos(B)

a² = b² + c² − 2bc·cos(A)

When C = 90°, cos(C) = 0 and the formula collapses to c² = a² + b² — the Pythagorean theorem. When C is acute, cos(C) is positive, so the −2ab·cos(C) term subtracts from a² + b², making c shorter than the hypotenuse would be. When C is obtuse, cos(C) is negative, so the term adds, and c ends up longer. That's the entire geometric intuition in one formula.

Worked Example: SAS Case (Two Sides + Included Angle)

Given a = 8, b = 11, and the included angle C = 37°. Find side c and the remaining angles.

Step 1: c² = 8² + 11² − 2(8)(11)·cos(37°)

Step 2: c² = 64 + 121 − 176 × 0.7986 = 185 − 140.55 = 44.45

Step 3: c = √44.45 = 6.667

Step 4: Find angle A using the law of cosines rearranged:

cos(A) = (b² + c² − a²) / (2bc) = (121 + 44.45 − 64) / (2 × 11 × 6.667) = 101.45 / 146.67 = 0.6921

A = arccos(0.6921) = 46.27°

Step 5: B = 180° − 37° − 46.27° = 96.73°

Since B > 90°, this is an obtuse triangle. The calculator above also computes the area (using Heron's formula once all sides are known: ≈ 26.43 square units) and altitudes automatically.

Worked Example: SSS Case (Three Sides Known)

Given a = 5, b = 7, c = 9. Find all three angles.

Step 1: Find the largest angle first (opposite the longest side, c = 9):

cos(C) = (a² + b² − c²) / (2ab) = (25 + 49 − 81) / (2 × 5 × 7) = −7/70 = −0.1

C = arccos(−0.1) = 95.74°

Step 2: cos(A) = (b² + c² − a²) / (2bc) = (49 + 81 − 25) / (126) = 105/126 = 0.8333

A = arccos(0.8333) = 33.56°

Step 3: B = 180° − 95.74° − 33.56° = 50.70°

Tip: always solve for the largest angle first in SSS problems. If it turns out obtuse, you know immediately — and you avoid the ambiguity issues that can crop up with the law of sines in the SSA case.

Law of Cosines vs. Law of Sines — Which Do You Need?

You knowUseWhy
SSS (3 sides)Law of CosinesOnly option — Law of Sines needs at least one angle
SAS (2 sides + included angle)Law of CosinesDirectly solves for the missing side
ASA (2 angles + included side)Law of SinesThird angle = 180° − A − B, then sines give both sides
AAS (2 angles + non-included side)Law of SinesSame as ASA — find third angle first
SSA (2 sides + non-included angle)Law of Sines (carefully)Ambiguous case — may have 0, 1, or 2 solutions

The law of cosines never produces ambiguous results. Every valid set of SSS or SAS inputs maps to exactly one triangle. That's why many textbooks recommend it as the default method and only switching to the law of sines when you have angle-side pairs. For basic cosine calculations outside of triangle problems, we have a dedicated tool.

Common Mistakes That Produce Wrong Answers

Three errors account for most wrong answers with the law of cosines:

  • Using the wrong angle. In c² = a² + b² − 2ab·cos(C), angle C must be the angle between sides a and b (the included angle). If you accidentally use the angle opposite side a, every result cascades into nonsense.
  • Degrees vs. radians mismatch. cos(60°) = 0.5, but cos(60 radians) = −0.952. Most scientific calculators default to degrees, but programming languages (JavaScript, Python) use radians. Multiply degrees by π/180 before calling cos().
  • Rounding too early. If you round intermediate results to 2 decimal places, errors compound through subsequent steps. Keep at least 6 significant figures through the calculation and only round the final answer. The calculator above maintains full floating-point precision internally.

Real-World Applications Beyond the Classroom

Surveyors use the law of cosines constantly. Measure two distances from a baseline to a point, record the angle between them with a theodolite, and you've got an SAS triangle that gives the unknown distance. GPS receivers use the same math — each satellite defines a sphere, and the intersections form triangles solved by the cosine rule.

In construction, roof framing relies heavily on triangle math. A hip roof where two slopes meet at a 120° angle with rafter lengths of 4m and 5m needs a ridge board of c = √(16 + 25 − 2(4)(5)cos(120°)) = √(41 + 20) = √61 ≈ 7.81m. Getting that wrong means wasted lumber and a roof that doesn't fit. For computing the area once you have all three sides, the triangle area calculator uses Heron's formula and handles the arithmetic cleanly.

Navigation, robotics, game physics, molecular geometry — anywhere you need to resolve a triangle without a right angle, the law of cosines is the tool. As the Wikipedia article on the law of cosines notes, the formula has been known since Euclid's Elements (circa 300 BC), making it one of the oldest computational tools still in daily use.

About the Author

Marko Šinko - Co-Founder & Lead Developer

Marko Šinko

Co-Founder & Lead Developer, AI Math Calculator

Lepoglava, Croatia
Advanced Algorithm Expert

Croatian developer with a Computer Science degree from University of Zagreb and expertise in advanced algorithms. Co-founder of award-winning projects, ensuring precise mathematical computations and reliable calculator tools.

Frequently Asked Questions

Still Have Questions?

The detailed content on this page provides comprehensive explanations and examples to help you understand better.