Law of Cosines Solver

Solve any triangle from any three pieces — all five congruence cases with full step-by-step working.

Ad placeholder (leaderboard)
Enjoying the tools? Go Pro for £4.99 (one-time) and remove all ads — forever, on this device. Remove ads — £4.99

The law of cosines solver finds every unknown side, angle, area, and perimeter of any triangle — right-angled or oblique — given just three pieces of information. It covers all five standard congruence cases (SSS, SAS, ASA, AAS, SSA) and, uniquely, handles the SSA ambiguous case by detecting whether zero, one, or two valid triangles exist and showing the full algebraic reasoning for each.

The formula

The law of cosines states:

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

Here side a is opposite angle A, side b opposite B, and side c opposite C. Rearranging to find an angle:

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

When angle C is 90° the cosine term vanishes and the formula collapses to the Pythagorean theorem, confirming that the cosine rule is the general form. The companion law of sines (a / sin A = b / sin B = c / sin C) is used internally for the ASA and AAS cases and to resolve the ambiguous SSA scenario.

How it works

SSS (three sides known): The solver applies the rearranged cosine rule to find angle A from sides a, b, c, then B from the same formula, and finally sets C = 180° − A − B. Area follows from ½ · a · b · sin C.

SAS (two sides + included angle): With sides a, b and included angle C, the cosine rule gives c directly (c² = a² + b² − 2ab · cos C). The remaining angles A and B then come from the cosine rule applied to the completed side set.

ASA / AAS (two angles + one side): The third angle is C = 180° − A − B, then the sine rule propagates to find the remaining sides.

SSA (ambiguous): The solver computes sin B = b · sin A / a. If sin B > 1 there is no triangle. If sin B = 1 there is exactly one right triangle. Otherwise both B = arcsin(sin B) and B = 180° − arcsin(sin B) are tested; any candidate that yields a negative C is discarded. One or two valid triangles are displayed side by side.

Worked example

Suppose you know all three sides of a surveyor’s triangle: a = 7 m, b = 8 m, c = 9 m (SSS).

  1. cos A = (8² + 9² − 7²) / (2 × 8 × 9) = (64 + 81 − 49) / 144 = 96 / 144 = 0.6667 → A ≈ 48.19°
  2. cos B = (7² + 9² − 8²) / (2 × 7 × 9) = (49 + 81 − 64) / 126 = 66 / 126 = 0.5238 → B ≈ 58.41°
  3. C = 180° − 48.19° − 58.41° = 73.40°
  4. Area = ½ × 7 × 8 × sin(73.40°) = ½ × 7 × 8 × 0.9583 ≈ 26.83 m²
  5. Perimeter = 7 + 8 + 9 = 24 m

All five of these values appear instantly when you type 7, 8, 9 into the SSS inputs above.

Formula reference

CaseGivenPrimary formula
SSSa, b, ccos A = (b² + c² − a²) / (2bc)
SASa, b, Cc² = a² + b² − 2ab·cos C
ASAA, B, cC = 180−A−B; sides via sine rule
AASA, C, aB = 180−A−C; sides via sine rule
SSAa, b, Asin B = b·sin A / a (0, 1, or 2 triangles)

Every calculation runs locally in your browser — no data is transmitted to any server.

Ad placeholder (rectangle)