Law of Cosines Calculator

Solve any triangle from three sides or two sides and an angle.

Free law of cosines calculator. Solve a triangle from three sides (SSS) or two sides and the included angle (SAS) to get every side, every angle, the area and perimeter — all computed privately in your browser. It runs free in your browser on Gera Tools, with nothing uploaded.

Last updated Source: Gera Tools

What is the law of cosines?

It generalises the Pythagorean theorem to any triangle: c² = a² + b² − 2ab·cos(C). It lets you find a side from two sides and the included angle, or an angle from three known sides.

The law of cosines is the rule that lets you solve oblique (non-right) triangles where the simple Pythagorean theorem and SOH-CAH-TOA do not apply. Students, engineers, surveyors and anyone working with triangles can use it to find a missing side from two sides and the angle between them, or to recover all three angles from three known sides.

How it works

The core identity is a² = b² + c² − 2bc·cos(A), where each lowercase side sits opposite the matching uppercase angle.

  • SSS mode (three sides known): the tool rearranges the rule to cos(A) = (b² + c² − a²) / (2bc) and takes the inverse cosine for angles A and B, then finds C as 180° − A − B.
  • SAS mode (two sides and the included angle): it first computes the missing side a = √(b² + c² − 2bc·cos(A)), then solves for the remaining angles the same way.

In both modes it also returns the area via ½·b·c·sin(A) and the perimeter as a + b + c. The cosine inputs are clamped to the range −1 to 1 to avoid rounding errors at the extremes.

Example

Take a triangle with sides a = 7, b = 8, c = 9 (SSS mode):

ResultValue
Angle A48.19°
Angle B58.41°
Angle C73.40°
Area26.83
Perimeter24

Angle A comes from cos(A) = (8² + 9² − 7²) / (2·8·9) = 96/144 = 0.6667, giving A ≈ 48.19°.

When to use the law of cosines vs other tools

What you knowWhat you needRule to use
All 3 sides (SSS)All 3 anglesLaw of cosines
2 sides + included angle (SAS)3rd side, other anglesLaw of cosines
2 angles + 1 side (AAS or ASA)Remaining sidesLaw of sines
Right angle + 2 other knownsRemaining sides/anglesPythagorean theorem / SOH-CAH-TOA
2 sides + non-included angle (SSA)TrianglesLaw of sines (watch for ambiguous case)

The law of cosines handles SSS and SAS cleanly; the law of sines is simpler for AAS/ASA but requires care with SSA (the ambiguous case can yield 0, 1, or 2 triangles).

Real-world applications

  • Surveying: Given three measured distances between points on a boundary, find all interior angles.
  • Navigation: Given the distance to two landmarks and the angle between them, find the distance between the landmarks.
  • Structural engineering: Check the geometry of a triangulated truss frame from member lengths alone.
  • Physics problems: Find the resultant magnitude of two force vectors given their magnitudes and the angle between them (SAS case).
  • Computer graphics: Compute the angle at each vertex of a triangle polygon from the edge lengths.

Edge cases and validity

The triangle inequality must hold: every side must be shorter than the sum of the other two. If you enter sides 3, 4, 10, there is no valid triangle — no angle’s cosine can be outside −1 to 1, and the inverse cosine will have no real solution. The calculator checks this and reports it rather than silently returning NaN.

For a right triangle, the included angle is 90°. In SAS mode, cos(90°) = 0 so the law of cosines reduces to c² = a² + b² — the Pythagorean theorem as a special case.

All math happens locally in your browser — nothing is uploaded.