How do I use the law of cosines?
Free online law of cosines calculator. Fast, accurate, and easy to use math tool.
- Side c
- 6.244998
A triangle with sides 5 and 7 and the angle 60° between them has a third side of 6.244998.
- Angle A
- 43.897886°
- Angle B
- 76.102114°
- Perimeter
- 18.244998
- Area
- 15.155445
- Inradius
- 1.661326
- Circumradius
- 3.605551
Side c: 6.244998. A triangle with sides 5 and 7 and the angle 60° between them has a third side of 6.244998.
What does the triangle look like?
How to calculate
Finds the third side of a triangle from two sides and the angle between them, an angle from three sides, or a side from two sides and an angle.
Example with the default inputs (Side a 5, Side b 7, Angle C 60 °): A triangle with sides 5 and 7 and the angle 60° between them has a third side of 6.244998.
Formula: c² = a² + b² − 2ab cos C, where C is the angle between sides a and b.
- Angles are between 0° and 180°; sides are more than 0, in any one unit.
- Two sides and the angle opposite one of them can fit two triangles (the ambiguous case): both answers are shown.
- Three sides must satisfy the triangle inequality: each side shorter than the other two together.
- Angles A and B, the area, and the radii come from the three typed values in stable forms (Kahan), so needle-like triangles keep their accuracy; the circumradius c ÷ (2 sin C) shows once in the ambiguous case.
Worked examples
Each example is checked against the calculator on every build.
- Side a 5, Side b 7, Angle C 60° gives Side c 6.244998, Perimeter 18.244998, Area 15.155445.
- Side a 3, Side b 4, Angle C 90° gives Side c 5, Angle A 36.869898°, Area 6, Inradius 1, Circumradius 2.5.
- Side a 5, Side b 7, Side c 8 gives Angle C 81.79°, Angle B 60°, Area 17.320508.
- Side b 8, Side c 7, Angle C 60° gives Side a 5.
- Side a 5, Side b 7, Angle C 114.6° gives Side c 10.155308.
- Side b 0.023707, Side c 8,286.471048, Angle C 2.269° gives Angle B 0.00000648831°, Circumradius 104,672.850328.Source: Needle triangle (SSA) from docs/progress/WP-60-24.md, finding 1
- Side a 0.001, Side b 1,000, Angle C 0.0573° gives Angle A 0.0000000572958°, Area 0.0005, Circumradius 499,999.583334.
How it works
For a triangle with sides a, b, c and the angle C between sides a and b (opposite side c), the law of cosines says:
c² = a² + b² − 2ab cos C
Fill in any three of a, b, c and C, and the calculator finds the fourth.
- Side c (SAS): c = √(a² + b² − 2ab cos C). The calculator uses the equal form √((a − b)² + 4ab sin²(C/2)), which keeps its accuracy for small angles.
- Angle C (SSS): C = arccos((a² + b² − c²) ÷ 2ab). The three sides must form a triangle: each side shorter than the other two together.
- Side a or b (SSA): a is a root of a² − 2b cos C · a + (b² − c²) = 0, so a = b cos C ± √(c² − b² sin² C). Only positive roots count. There can be no triangle (the square root of a negative number), one, or two (the ambiguous case), and the calculator shows every one.
Once the triangle is known, the calculator works out the rest from the three values you typed, in forms that stay accurate for needle-like triangles (one very short side or one very small angle; W. Kahan, "Miscalculating Area and Angles of a Needle-like Triangle", 2014):
- Angles A and B, with angle C and two sides typed (SAS, or SSA with side a or b solved). From the law of sines and a projection, c sin A = a sin C and c cos A = b − a cos C, so A = atan2(a sin C, b − a cos C), and likewise B = atan2(b sin C, a − b cos C). When side a was solved from b, c and C, a − b cos C = ±√(c² − b² sin² C) (+ for the larger root, − for the smaller), and b − a cos C = b sin² C − cos C × (a − b cos C); the same holds with a and b swapped. Both angles are computed on their own, not as 180° minus the other two, because a small angle loses its digits in that subtraction.
- Angles with three sides typed (SSS). Each angle from Kahan's formula: for the angle X opposite side x, with the other sides p ≥ q, X = 2 arctan √(((p − q) + x) × μ ÷ ((p + (q + x)) × ((p − x) + q))), where μ = x − (p − q) when q ≥ x, and μ = q − (p − x) otherwise. Angle C itself is found the same way.
- Perimeter P = a + b + c, and the semi-perimeter s = P ÷ 2.
- Area: ½ab sin C when angle C was typed; Heron's formula √(s(s − a)(s − b)(s − c)) in Kahan's rearranged form when the three sides were typed.
- Inradius r = area ÷ s, and circumradius R = c ÷ (2 sin C). In the ambiguous case both triangles share c and C, so the circumradius is shown once.
Assumptions
- Sides are positive numbers, all in the same unit. Angle C is more than 0° and less than 180°.
- Angle C can be typed in degrees or radians. Angles A and B are shown in degrees.
- A circumradius or other value too large for a 64-bit float (for an angle C very close to 0) is left out instead of shown as infinity.
- An old link with
goal=angleleaves angle C empty, so it is solved from the three sides. An old link withuseRadians=truereads angle C in radians. - When three sides are given that make no triangle (one side is as long as the other two together, or longer), the page gives no answer and says: "These sides do not make a triangle: each side must be shorter than the other two together."
Worked examples by hand
a = 5, b = 7, C = 60° (SAS). c² = 25 + 49 − 2 × 5 × 7 × cos 60° = 74 − 70 × 0.5 = 39, so c = √39 = 6.244998. The perimeter is 5 + 7 + 6.244998 = 18.244998, and the area is ½ × 5 × 7 × sin 60° = 15.155445.
a = 3, b = 4, C = 90°. c² = 9 + 16 − 0 = 25, so c = 5. Angle A = arcsin(3/5) = 36.87° (0.6435 rad). The area is ½ × 3 × 4 = 6, the inradius 6 ÷ 6 = 1, and the circumradius 3 × 4 × 5 ÷ 24 = 2.5.
a = 5, b = 7, c = 8 (SSS). cos C = (25 + 49 − 64) ÷ 70 = 1/7, so C = arccos(1/7) = 81.79° (1.4274 rad). cos B = (25 + 64 − 49) ÷ 80 = 1/2, so B = 60°. By Heron's formula with s = 10, the area is √(10 × 5 × 3 × 2) = √300 = 17.320508.
b = 8, c = 7, C = 60° (SSA). a² − 2 × 8 × 0.5 × a + (64 − 49) = 0, so a² − 8a + 15 = 0 and a = 5 or 3. Both triangles fit.
a = 5, b = 7, C = 2 radians. c² = 74 − 70 × cos 2 = 74 + 29.130 = 103.130, so c = 10.155308.
Other questions people ask
What is the Law of Cosines?
The Law of Cosines is a trigonometric formula that relates the lengths of the sides of a triangle to the cosine of one of its angles. It's an extension of the Pythagorean theorem for non-right triangles.
When should I use the Law of Cosines?
Use the Law of Cosines when you have either: 1) Two sides and the included angle (SAS case) to find the third side, or 2) Three sides (SSS case) to find the angles. It also finds a side from two sides and an angle that is not between them (SSA case).
What's the difference between SAS and SSS cases?
SAS (Side-Angle-Side) means you know two sides and the angle between them. SSS (Side-Side-Side) means you know all three sides. The calculator handles both cases automatically.
Does the calculator support SSA (Side-Side-Angle)?
Yes. SSA can result in the 'ambiguous case' where there are two possible triangles or no triangle at all. Leave side a or side b empty and fill in the other two sides and angle C: when two triangles fit, the calculator shows both values of the missing side; when none fits, it says so.
What units should I use for angles?
You can use either degrees (default) or radians for angle C. The calculator will convert between them automatically. Angles A and B are shown in degrees. Degrees are more common for most applications.
What additional properties does the calculator provide?
Besides the sides and angles, the calculator provides the triangle's perimeter, area (using Heron's formula), inradius, and circumradius.