Skip to main content

MATH · LAW OF COSINES

Law of Cosines Calculator

Solve any triangle using the law of cosines. Enter three sides (SSS) or two sides and the included angle (SAS) to find all angles, area, and perimeter.

Known values
Side lengths
01 Sides
Side a3
Side b4
Side c5
02 Angles
Angle A36.8699°
Angle B53.1301°
Angle C90°
03 Area & Perimeter
Area6
Perimeter12

About This Calculator

The law of cosines relates the three sides of a triangle to one of its angles: c² = a² + b² − 2ab·cos C. This calculator handles both SSS (all three sides known) and SAS (two sides and their included angle known) cases, computing all remaining sides, angles, perimeter, and area.

How It Works

Select SSS to enter three side lengths; the calculator finds all three angles using the law of cosines applied at each vertex. Select SAS to enter two sides and the included angle; the third side is computed first, then all angles. Triangle inequality is checked first (a+b > c for all combinations), and the arccos function is clamped to prevent NaN from floating-point rounding near degenerate triangles.

The Formula

cos A = (b² + c² − a²) / (2bc) c = √(a² + b² − 2ab·cos C) [SAS]

a, b, c
side lengths
A, B, C
angles opposite the corresponding sides

Frequently Asked Questions

What is the law of cosines?
The law of cosines is a generalization of the Pythagorean theorem to any triangle. For a right triangle (C = 90°), cos C = 0 and the formula reduces to c² = a² + b² (Pythagorean theorem).
When should I use law of cosines vs law of sines?
Use law of cosines when you know SSS (three sides) or SAS (two sides and the included angle). Use law of sines when you know ASA (two angles and the included side) or AAS (two angles and a non-included side), or SSA (which can be ambiguous).
What is the triangle inequality?
For any valid triangle, the sum of any two sides must be strictly greater than the third side (a+b > c, a+c > b, b+c > a). If this is violated, no real triangle exists with those measurements.
Can I solve an obtuse triangle?
Yes. The law of cosines works for all triangles including obtuse ones. For obtuse angles the cosine is negative, so the formula naturally handles them; the angle will appear greater than 90° in the result.