My Calculator

Law of Cosines Calculator

Solve any triangle's missing side or angles using the Law of Cosines — from three sides (SSS) or two sides and the included angle (SAS) — with a to-scale diagram and full step-by-step solution.

Side a7
Side b9
Side c12
Angle A (opposite a)35.43°
Angle B (opposite b)48.19°
Angle C (opposite c)96.38°
Area31.305
Perimeter28

Triangle Diagram (to scale, with values)

A35.4°B48.2°C96.4°a = 7b = 9c = 12

Step-by-Step Solution

Here's exactly how this answer was calculated, one step at a time.

  1. 1

    Check the triangle inequality

    7 + 9 > 12, and the other two combinations also hold

    Before solving, the calculator confirms the sum of any two sides exceeds the third side — otherwise these three lengths could never form a real triangle.

  2. 2

    Find Angle A with the Law of Cosines

    cos(A) = (b² + c² − a²) / (2bc) = (9² + 12² − 7²) / (2 × 9 × 12) → A = 35.43°

    The Law of Cosines, rearranged and solved with the inverse cosine, gives the angle opposite side a directly from all three side lengths.

  3. 3

    Find Angle B with the Law of Cosines

    cos(B) = (a² + c² − b²) / (2ac) = (7² + 12² − 9²) / (2 × 7 × 12) → B = 48.19°

    The same formula is reused, this time rearranged to isolate the angle opposite side b.

  4. 4

    Find Angle C using the angle sum property

    C = 180° − A − B = 180° − 35.43° − 48.19° = 96.38°

    Since a triangle's three angles always total 180°, the last angle is found by simple subtraction instead of another Law of Cosines calculation.

  5. 5

    Calculate the area (Heron's Formula) and perimeter

    Area = √(s(s−a)(s−b)(s−c)) = 31.305 | Perimeter = a + b + c = 28

    With all three sides known, Heron's Formula gives the area directly, and the perimeter is simply the sum of the three sides.

a = 7, b = 9, c = 12, A = 35.43°, B = 48.19°, C = 96.38°

Free Online Law of Cosines Calculator — Solve Any Triangle

This Law of Cosines calculator solves a triangle's missing side or angles from either three known sides (SSS) or two known sides plus the angle between them (SAS) — the two classic cases the Law of Cosines was built to handle. Enter your known values and instantly get every side, every angle, the area, and the perimeter, backed by a labeled, to-scale diagram and a complete step-by-step solution showing exactly how each number was calculated.

Whether you're solving a triangle equation for geometry or trigonometry class, checking a surveying or navigation calculation, working out a structural angle in engineering, or just need a reliable law of cosines solver for any oblique (non-right) triangle, this tool covers the full SSS and SAS workflow in one place.

What Is the Law of Cosines?

The Law of Cosines is a formula that relates the three sides of any triangle to the cosine of one of its angles. It's a generalization of the Pythagorean theorem — in fact, when the angle in the formula is exactly 90°, cos(90°) = 0 and the Law of Cosines collapses exactly into a² + b² = c². This makes it the go-to formula for solving oblique triangles — triangles that don't contain a right angle — where the simpler right-triangle trig ratios (SOH-CAH-TOA) don't directly apply.

Unlike the Law of Sines, which needs at least one known angle-side pair to get started, the Law of Cosines can solve a triangle from three side lengths alone, with no angle information required at all. That flexibility is exactly why it's the standard tool for the SSS and SAS triangle-solving cases.

The Law of Cosines Formula

The Law of Cosines can be written in three equivalent forms, one for each side of the triangle — this calculator applies whichever rearranged form fits your known values:

  • a² = b² + c² − 2bc·cos(A)
  • b² = a² + c² − 2ac·cos(B)
  • c² = a² + b² − 2ab·cos(C)
  • Rearranged to solve for an angle: cos(A) = (b² + c² − a²) / (2bc), and similarly for B and C

The Two Cases the Law of Cosines Solves

There are exactly two situations where the Law of Cosines is the correct — and often the only — tool for solving a triangle:

  • SSS (Side-Side-Side): All three side lengths are known, but no angles are known. The Law of Cosines finds each angle in turn by rearranging the formula to isolate cos(A), cos(B), or cos(C), then taking the inverse cosine.
  • SAS (Side-Angle-Side): Two sides and the angle directly between them (the included angle) are known. The Law of Cosines finds the third side directly, after which the remaining two angles can be found using the Law of Cosines again (or the Law of Sines).

How to Use This Law of Cosines Calculator — Step by Step

Pick the mode that matches the information you already have, enter your numbers, and read the fully solved triangle below.

  • SSS mode: enter all three side lengths a, b, and c. The calculator checks the triangle inequality, then finds Angle A, Angle B, and Angle C using the Law of Cosines and the angle sum property.
  • SAS mode: choose which angle you know (A, B, or C), enter that angle in degrees, and enter the two side lengths adjacent to it (the sides that form the angle). The calculator computes the third side directly with the Law of Cosines, then solves for both remaining angles.
  • In both modes, the diagram above the solution is drawn to scale with every side length and every angle value printed directly on the triangle, so you can visually confirm the shape without cross-referencing the results table.

Worked Example — SSS (Three Sides Known)

Suppose a triangle has sides a = 7, b = 9, and c = 12. Applying the Law of Cosines for angle A: cos(A) = (b² + c² − a²) ÷ (2bc) = (81 + 144 − 49) ÷ (2 × 9 × 12) = 176 ÷ 216 ≈ 0.8148, so A = cos⁻¹(0.8148) ≈ 35.44°. Similarly, cos(B) = (a² + c² − b²) ÷ (2ac) = (49 + 144 − 81) ÷ (2 × 7 × 12) = 112 ÷ 168 ≈ 0.6667, giving B ≈ 48.19°. Finally, C = 180° − 35.44° − 48.19° ≈ 96.37°. Because one angle exceeds 90°, this is an obtuse triangle.

Worked Example — SAS (Two Sides & Included Angle Known)

Now suppose sides a = 8 and b = 10 are known, along with the included angle C = 60° (the angle between them). Applying the Law of Cosines directly for side c: c² = a² + b² − 2ab·cos(C) = 64 + 100 − 2(8)(10)cos(60°) = 164 − 160(0.5) = 164 − 80 = 84, so c = √84 ≈ 9.17. With all three sides now known, the remaining angles follow the same process as the SSS case: cos(A) = (b² + c² − a²) ÷ (2bc) ≈ 0.5595, giving A ≈ 55.98°, and B = 180° − 60° − 55.98° ≈ 64.02°.

Law of Cosines vs. Law of Sines — Which One to Use

It's easy to confuse the Law of Cosines with the Law of Sines, but each is suited to different known information. Use the Law of Cosines when you know three sides (SSS) or two sides and their included angle (SAS) — situations where the Law of Sines can't get started because it needs at least one complete angle-side pair. Use the Law of Sines instead for AAS, ASA, or the sometimes-ambiguous SSA case. A helpful rule of thumb: if the angle you know sits between two known sides, or if you know no angles at all, reach for the Law of Cosines first.

Understanding the Diagram: Reading the Values Directly

The triangle diagram above is drawn precisely to scale from your entered or calculated side lengths, so its proportions match your real triangle — a long, narrow triangle will visibly look long and narrow. Every side is labeled with its length directly along the edge, and every vertex is labeled with both its letter (A, B, or C) and its calculated angle in degrees. This means you can read the complete solved triangle — every side and every angle — straight off the picture, without needing to scroll back up to the results panel.

Area and Perimeter from the Law of Cosines

Once the Law of Cosines has produced all three side lengths, the area and perimeter follow easily. The perimeter is simply a + b + c. The area is calculated using Heron's Formula: Area = √(s(s−a)(s−b)(s−c)), where s is the semi-perimeter, s = (a + b + c) ÷ 2. In SAS mode, the area can alternatively be found even faster with Area = ½ × side1 × side2 × sin(included angle) — this calculator uses Heron's Formula throughout for consistency once the third side has been solved for.

Real-World Applications of the Law of Cosines

The Law of Cosines is one of the most widely used formulas in applied trigonometry, appearing anywhere a triangle needs to be solved without a right angle:

  • Navigation and aviation: calculating distances and bearings between three points using known distances and a turning angle.
  • Surveying and land measurement: finding an unknown property boundary length or plot angle from two measured distances and the angle between them.
  • Physics and engineering: resolving resultant forces or vectors that don't meet at a right angle.
  • Astronomy: calculating distances between celestial bodies using angular separation measurements.
  • Construction: determining diagonal brace lengths or roof truss angles that don't form a right triangle.

Tips for Getting Accurate Results

In SSS mode, always double-check the triangle inequality mentally before entering your values — if one side is longer than the sum of the other two, no triangle can exist, and the calculator will flag this immediately rather than returning a misleading answer. In SAS mode, make sure the angle you enter is genuinely the included angle — the one physically between the two sides you're providing — since using a non-included angle here (which would actually be an SSA situation) requires the Law of Sines instead and can produce an ambiguous or incorrect result if forced through the Law of Cosines. Finally, remember that angles must always be entered in degrees for this calculator, and all three sides should use the same unit of measurement.

Frequently Asked Questions

What is the Law of Cosines formula?

c² = a² + b² − 2ab·cos(C), and its two rotations for the other sides. It relates all three sides of a triangle to the cosine of one angle, and reduces to the Pythagorean theorem when that angle is 90°.

When should I use the Law of Cosines instead of the Law of Sines?

Use the Law of Cosines for the SSS case (three known sides, no angles) or the SAS case (two known sides with the angle between them). The Law of Sines is better suited to AAS, ASA, or SSA situations, where at least one full angle-side pair is already known.

Can the Law of Cosines solve a triangle with no angles given?

Yes — that's the SSS case. Given only the three side lengths, the Law of Cosines can find all three angles by rearranging the formula and applying the inverse cosine function to each one in turn.

What does 'included angle' mean in the SAS case?

The included angle is the angle that sits directly between the two known sides — the angle formed where those two sides meet. The Law of Cosines specifically requires this included angle; a non-included angle would instead be an SSA problem, solved differently with the Law of Sines.

Why does the calculator say my three sides can't form a triangle?

This happens when the triangle inequality fails — when one side is longer than or equal to the sum of the other two sides. No triangle can physically exist with those measurements, so the calculator reports an error instead of a false result.

How is the area found once the Law of Cosines has solved the triangle?

Once all three sides are known, Heron's Formula gives the area: Area = √(s(s−a)(s−b)(s−c)), where s is the semi-perimeter (half the total perimeter).

Is the Law of Cosines the same as the Pythagorean theorem?

The Law of Cosines is a generalization of it. When the included angle is exactly 90°, cos(90°) = 0, and the formula c² = a² + b² − 2ab·cos(C) simplifies exactly to the Pythagorean theorem, c² = a² + b².