Law of Cosines Calculator

Solve SAS and SSS triangles with validity checks, full side-and-angle results, area, perimeter, semiperimeter, inradius, circumradius, altitudes and a scaled triangle diagram.

Law of Cosines result

Area0
Perimeter0
Circumradius0
Primary result0

For SAS, enter two sides and their included angle. For SSS, all three sides must satisfy the triangle inequality.

Calculation breakdown

Angle A0
Angle B0
Angle C0
Side a0
Side b0
Side c0
Semiperimeter0
Inradius0
Altitudes hₐ / hᵦ / h𝚌0
Triangle type0

Transparent formula

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

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

A + B + C = 180°

area = √[s(s−a)(s−b)(s−c)]

0

Triangle diagram

Diagram is scaled for clarity. Side a is opposite A, b opposite B and c opposite C.

What is the Law of Cosines?

The Law of Cosines relates the three sides of a triangle to the cosine of one angle. It generalizes the Pythagorean theorem from right triangles to any valid triangle.

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

The same relationship can be written for the other two sides:

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

When should you use the Law of Cosines?

The Law of Cosines is the natural first tool in two important configurations:

When ASA, AAS or SSA data are given, the Law of Sines is usually more direct. SSA can also produce an ambiguous case with zero, one or two solutions.

SAS: finding a missing side

Suppose sides a and b and the included angle C are known. Solve:

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

Example: a = 7, b = 10 and C = 60°.

c² = 7² + 10² − 2(7)(10)cos(60°) c² = 49 + 100 − 140(0.5) = 79 c = √79 ≈ 8.888

Why the angle must be included in SAS

If you know sides a and b, the included angle is C because C lies between those two sides and is opposite c. Using a non-included angle in the same formula does not represent the stated SAS geometry.

This is one of the most common setup mistakes in oblique-triangle problems.

SSS: finding an angle

When all three sides are known, rearrange the Law of Cosines. To find angle C:

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

For a=7, b=8 and c=9:

cos(C) = (49 + 64 − 81)/(112) = 32/112 ≈ 0.285714 C ≈ 73.398°

Why arccos is convenient for SSS

For a valid triangle, the cosine-form expression for an angle lies between −1 and 1. Taking arccos returns the unique interior triangle angle between 0° and 180°.

This is different from the inverse-sine ambiguity that can occur in SSA problems. SSS determines a unique triangle up to reflection.

Triangle inequality matters

Three positive lengths form a nondegenerate triangle only if every pair sums to more than the remaining side:

a+b>c,   a+c>b,   b+c>a

If 2, 3 and 6 are entered, 2+3 is not greater than 6, so no ordinary triangle exists. A high-quality SSS calculator should reject those inputs before attempting inverse cosine.

Degenerate triangles

If two side lengths add exactly to the third, the three points lie on a straight line. The area is zero and the shape is degenerate rather than an ordinary triangle.

SonoCalculator requires strict triangle inequality for SSS so degenerate cases are not presented as valid solved triangles.

Law of Cosines and the Pythagorean theorem

If C = 90°, then cos(90°)=0. The cosine term disappears:

c² = a² + b²

So the Pythagorean theorem is a special case of the Law of Cosines.

Acute and obtuse angles in the formula

The sign of cos(C) explains how the side opposite C behaves.

For an acute angle, cos(C) is positive, so the subtraction term reduces c². For an obtuse angle, cos(C) is negative, so subtracting a negative value increases c². The side opposite an obtuse angle is therefore relatively long.

Largest side and largest angle

In every triangle, the largest side is opposite the largest angle. This provides a quick reasonableness check after solving SSS.

If c is clearly the longest side but the computed C is not the largest angle, something is wrong with the side-angle pairing or arithmetic.

Solving the whole triangle from SAS

A robust SAS workflow is:

This calculator computes all three angles from the solved side lengths, which avoids accidentally choosing a supplementary sine angle.

Solving the whole triangle from SSS

With three valid sides, compute angles with:

A = arccos((b²+c²−a²)/(2bc)) B = arccos((a²+c²−b²)/(2ac)) C = arccos((a²+b²−c²)/(2ab))

The sum should be 180° within numerical rounding.

Why calculators clamp arccos inputs

Floating-point arithmetic can occasionally produce a value like 1.0000000000000002 when the exact mathematical value should be 1. Passing that directly to arccos would fail.

A numerically careful calculator clamps tiny rounding excursions back into the valid interval [−1,1] before evaluating arccos. This protects against machine-rounding noise without turning genuinely impossible triangles into valid ones.

Area from three sides: Heron's formula

After a full triangle is solved, its area can be found from side lengths using the semiperimeter:

s = (a+b+c)/2 Area = √[s(s−a)(s−b)(s−c)]

Heron's formula is convenient because it works directly from SSS data and also works after SAS has produced the missing side.

Area from two sides and included angle

For SAS, the same area can be found before the third side is known:

Area = ½ab sin(C)

The two area formulas should agree, apart from rounding, once the whole triangle is solved.

Perimeter and semiperimeter

The perimeter is:

P = a+b+c

The semiperimeter is half of it:

s = P/2

Semiperimeter is useful in Heron's formula and several other triangle identities.

Circumradius

The circumradius R is the radius of the circle through the three vertices. Once area K is known:

R = abc/(4K)

It also follows from the extended Law of Sines:

a/sin(A) = b/sin(B) = c/sin(C) = 2R

Inradius

The inradius r is the radius of the inscribed circle tangent to all three sides:

r = K/s

where K is the area and s is the semiperimeter.

Altitudes

Each altitude is the perpendicular height to its corresponding side:

hₐ = 2K/a,   hᵦ = 2K/b,   h𝚌 = 2K/c

These follow directly from the area formula K = ½(base)(height).

Triangle classification by sides

A triangle is equilateral when all three sides are equal, isosceles when at least two sides are equal, and scalene when all three are different.

Because computed values can differ by tiny floating-point amounts, a calculator should use a small numerical tolerance rather than exact string equality.

Triangle classification by angles

A triangle is acute if all angles are less than 90°, right if one angle is 90°, and obtuse if one angle exceeds 90°.

The Law of Cosines gives a useful side-only classification too. For the largest side c:

c² < a²+b² → acute c² = a²+b² → right c² > a²+b² → obtuse

Degrees versus radians

The formulas are valid in either angle unit, provided the trigonometric function uses the same convention. This calculator uses degrees because most school geometry and triangle-solving problems are presented that way.

Law of Cosines versus Law of Sines

Given informationBest first methodWhy
SSSLaw of CosinesNo known opposite side-angle pair
SASLaw of CosinesFinds the third side directly
ASA / AASLaw of SinesKnown angle data and side-angle pair
SSALaw of SinesMay involve the ambiguous case

Worked example: 5, 8 and included 110°

Given a=5, b=8 and C=110°:

c² = 25 + 64 − 80cos(110°)

Since cos(110°) is negative, the final subtraction adds to c². This is consistent with C being obtuse and c being the longest side.

After c is found, all three side lengths are available and the remaining angles can be computed from the cosine formulas.

Worked example: a 3-4-5 triangle

For a=3, b=4 and c=5, angle C is:

C = arccos((3²+4²−5²)/(2·3·4)) C = arccos(0) = 90°

This directly recovers the familiar right triangle.

Near-degenerate triangles and sensitivity

When one side is almost equal to the sum of the other two, the triangle becomes extremely thin. The area approaches zero and one angle approaches 180°.

In such cases, small measurement errors can create relatively large changes in angles or area. Numerical output may be mathematically valid while still being sensitive to input precision.

Measurement error in real-world triangles

Surveying, construction and physical measurement data are rarely exact. If side lengths are rounded, computed angles inherit that uncertainty.

For practical work, retain realistic precision and avoid reporting many decimal places that the original measurements cannot support.

Law of Cosines in vectors

The cosine rule is closely related to the dot product. If vectors u and v form angle θ, then:

|u−v|² = |u|² + |v|² − 2|u||v|cos(θ)

This has the same structure as the Law of Cosines and connects triangle geometry with vector algebra.

Law of Cosines in surveying and navigation

If two distances from a known point and the included angle are known, the Law of Cosines can calculate the distance between the two remote points in a planar model.

For large geographic distances, Earth curvature and map projection effects matter, so spherical or geodesic methods may be required instead of ordinary Euclidean triangle geometry.

Common Law of Cosines mistakes

How to verify a solved triangle

Check the angle sum:

A+B+C = 180°

Check the triangle inequality, then substitute the solved values back into at least one Law of Cosines equation. You can also verify the area independently using both Heron's formula and ½ab sin(C).

For a right triangle, the cosine rule should reduce to the Pythagorean theorem.

Frequently asked questions

What is the Law of Cosines formula?

For side c opposite angle C: c² = a² + b² − 2ab cos(C).

When should I use the Law of Cosines?

Use it especially for SAS and SSS triangles.

Can the Law of Cosines solve SSS?

Yes. Rearrange the formula and use arccos to find each angle.

Can it solve SAS?

Yes. Two sides and their included angle determine the third side uniquely.

Can it solve SSA?

SSA is generally a Law of Sines situation and can have zero, one or two solutions.

Why does the triangle inequality matter?

Without it, three side lengths may not be able to close into a nondegenerate triangle.

How is the Pythagorean theorem related?

It is the special case when the included angle is 90° and cos(90°)=0.

Why use arccos instead of arcsin for SSS?

The cosine form directly returns the unique interior angle associated with the three sides and avoids the supplementary ambiguity of inverse sine.

Does this calculator find area too?

Yes. It reports area, perimeter, semiperimeter, circumradius, inradius and altitudes after solving the triangle.

Why might my real-world result need fewer decimals?

Computed precision should not exceed the meaningful precision of the measurements you entered.

Final note: use the Law of Cosines when SSS or SAS gives you no immediate opposite side-angle pair. Match each side to its opposite angle, verify triangle inequality for SSS, and keep the included angle straight in SAS. This calculator solves the full triangle and exposes area and circle-radius checks so the result can be validated from several independent relationships.