Law of Cosines Calculator
Use the law of cosines to calculate the missing side (SAS) or all three angles (SSS) for any triangle. Step-by-step derivations included.
Inputs
Results
What is the law of cosines?
The law of cosines relates the lengths of all three sides of a triangle to the cosine of one of its angles. For a triangle with sides a, b, c and the angle C opposite side c, the formula is:
c² = a² + b² − 2ab cos(C)
This single equation covers two classic triangle-solving scenarios:
-
SAS (Side-Angle-Side): two sides and the angle between them are known. The law of cosines gives the third side.
-
SSS (Side-Side-Side): all three sides are known. Rearranging the formula three times yields all three angles:
A = arccos((b² + c² − a²) / (2bc))
B = arccos((a² + c² − b²) / (2ac))
C = arccos((a² + b² − c²) / (2ab))
How to use this calculator
SAS mode — select "SAS — Find Side c", enter sides a and b and the angle C between them (in degrees). The calculator returns side c.
SSS mode — select "SSS — Find Angles", enter all three side lengths a, b, c. The calculator returns all three angles A, B, C in degrees.
Worked example: SAS
A surveyor knows two boundary lengths of a triangular plot — 83 m and 112 m — and the angle between them is 54°. What is the third boundary length?
- a = 83, b = 112, C = 54°
- c² = 83² + 112² − 2 × 83 × 112 × cos(54°)
- c² = 6 889 + 12 544 − 18 592 × 0.5878
- c² = 19 433 − 10 931 ≈ 8 502
- c ≈ 92.2 m
Worked example: SSS
A triangular garden has sides 5 m, 7 m, and 6 m. What are the corner angles?
- A = arccos((49 + 36 − 25) / (2 × 7 × 6)) = arccos(60/84) ≈ 44.4°
- B = arccos((25 + 36 − 49) / (2 × 5 × 6)) = arccos(12/60) ≈ 78.5°
- C = arccos((25 + 49 − 36) / (2 × 5 × 7)) = arccos(38/70) ≈ 57.1°
Check: 44.4° + 78.5° + 57.1° = 180°, confirming the three angles are consistent.
Why the formula works: connection to the Pythagorean theorem
The Pythagorean Theorem Calculator (c² = a² + b²) is a special case of the law of cosines. When angle C is exactly 90°, cos(90°) = 0 and the 2ab cos(C) term vanishes, leaving c² = a² + b².
For any other angle:
- If C < 90° (acute), cos(C) > 0, so the subtracted term makes c shorter — the triangle "closes up".
- If C > 90° (obtuse), cos(C) < 0, so the term becomes an addition, and c is longer than the hypotenuse would be.
This geometric intuition comes directly from the dot product definition of cosine, which measures how much one vector projects onto another.
Law of cosines vs. law of sines
| Situation | Use |
|---|---|
| Two sides + included angle (SAS) | Law of cosines |
| All three sides (SSS) | Law of cosines |
| Two angles + any side (AAS / ASA) | Law of sines |
| Two sides + non-included angle (SSA) | Law of sines (watch for ambiguous case) |
The law of sines is algebraically simpler when you already have an angle–opposite-side pair. The law of cosines has no ambiguous case and is preferred when the initial data is purely sides-and-included-angle.
Triangle inequality
For three lengths to form a valid triangle, every side must be less than the sum of the other two. If a side is ≥ the sum of the remaining two (for example, sides 1, 2, and 10), the arccos argument falls outside [−1, 1] and is undefined. The calculator shows a validation error in this case. Arrange sides in increasing order and verify that the two smaller ones sum to more than the largest.
Frequently Asked Questions (FAQ)
How is the law of cosines related to the Pythagorean theorem?
The law of cosines — c² = a² + b² − 2ab cos(C) — generalizes the Pythagorean theorem. When C = 90°, cos(C) = 0 and the formula collapses to c² = a² + b², the familiar Pythagorean theorem. For acute triangles (C < 90°) the term 2ab cos(C) is positive, so c is shorter than the hypotenuse would be; for obtuse triangles (C > 90°) it is negative, making c longer.
When should I use the law of cosines instead of the law of sines?
Use the law of cosines when you know two sides and the included angle (SAS) or all three sides (SSS). The law of sines is simpler once you already have one angle–opposite-side pair, but it suffers from an ambiguous case (two solutions) when given two sides and a non-included angle (SSA). The law of cosines has no ambiguous case: it always returns a unique answer.
What can I find with the SAS mode?
With two sides and the angle between them, the third side follows from c = √(a² + b² − 2ab cos C). For example, with a = 5, b = 7, C = 60°: c = √(25 + 49 − 70 × 0.5) = √39 ≈ 6.245. Once all three sides are known, SSS mode recovers the remaining two angles.
What if my three sides don't form a valid triangle?
For three lengths to form a triangle each must be less than the sum of the other two — the triangle inequality. If any side is ≥ the sum of the other two (e.g., sides 1, 2, 10) the cosine formula would require arccos of a value outside [−1, 1], which is undefined. The calculator shows an error in this case. A quick check: sort the sides and verify that the two shorter ones add up to more than the longest.
Recommended Next
Pythagorean Theorem Calculator
Calculate any side of a right triangle using the Pythagorean theorem (a² + b² = c²). Enter any two sides to find the third.