FLXCode Law of Cosines Calculator

FLXCode apps

Appearance

Law of Cosines Calculator

Give three sides, or two sides and the angle between them. The tool applies the law of cosines, shows the numbers plugged in, and fills in the rest of the triangle.

Start from Example

Fill in any three values, at least one a side. Side a sits opposite angle A, b opposite B, c opposite C.

Solved. Method: SAS.

Scalene, obtuse triangle

A46.55°B93.45°C40°a = 8b = 11c = 7.084
Side a
8
Side b
11
Side c
7.084
Angle A
46.548°
Angle B
93.452°
Angle C
40°
Area
28.283
Perimeter
26.084
Height to side a
7.071
Height to side b
5.142
Height to side c
7.985
Inradius
2.169
Circumradius
5.51

The steps, with your numbers

  1. Law of cosines: c² = a² + b² − 2 × a × b × cos C = 8² + 11² − 2 × 8 × 11 × cos(40°) = 50.176, so c = 7.084
  2. Law of sines: sin A = a × sin C / c = 8 × sin(40°) / 7.084 = 0.726, so A = 46.548° (the angle opposite the shorter given side is always acute)
  3. Third angle: B = 180° − C − A = 180° − 40° − 46.548° = 93.452°

No ads. No account. Nothing you type or record is uploaded. We count page events with a daily code. Check it.

Problem or idea? Email us

The formula, three ways

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

The same law holds for every corner: a² = b² + c² − 2bc cos A and b² = a² + c² − 2ac cos B. To find an angle from three sides, solve for the cosine and use arccos:

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

Step by step: SAS, 8 and 11 with 40° between

  1. c² = 8² + 11² − 2 × 8 × 11 × cos 40° = 64 + 121 − 176 × 0.7660 = 50.18.
  2. c = √50.18 = 7.084.
  3. Angle A is opposite the shorter given side, so it is acute. sin A = 8 × sin 40° / 7.084, which gives A = 46.55°.
  4. B = 180° − 40° − 46.55° = 93.45°.

Step by step: SSS, 7, 9 and 12

  1. cos A = (9² + 12² − 7²) / (2 × 9 × 12) = (81 + 144 − 49) / 216 = 176 / 216 = 0.8148, so A = 35.43°.
  2. cos B = (12² + 7² − 9²) / (2 × 12 × 7) = (144 + 49 − 81) / 168 = 0.6667, so B = 48.19°.
  3. C = 180° − A − B = 96.38°. This is the largest angle, opposite the longest side, and it is obtuse only if c² is bigger than a² + b².

Worked examples

CaseYou enterResult
SASa = 8, b = 11, C = 40°a = 8, b = 11, c = 7.084; A = 46.548°, B = 93.452°, C = 40°
SSSa = 7, b = 9, c = 12a = 7, b = 9, c = 12; A = 35.431°, B = 48.19°, C = 96.379°
SAS with a right anglea = 3, b = 4, C = 90°a = 3, b = 4, c = 5; A = 36.87°, B = 53.13°, C = 90°
SAS with a wide anglea = 5, b = 8, C = 120°a = 5, b = 8, c = 11.358; A = 22.411°, B = 37.589°, C = 120°
SAS, equal sidesa = 10, b = 10, C = 36°a = 10, b = 10, c = 6.18; A = 72°, B = 72°, C = 36°
SSS, flata = 3, b = 4, c = 7No triangle: the two shorter sides (7) must add up to more than the longest (7).

The right-angle row shows the Pythagorean theorem as a special case: with C = 90° the law of cosines gives c = 5, the 3-4-5 triangle. The 120° row gives c longer than √(25 + 64) = 9.43, because cos 120° is negative.

Numbers this uses

  • Angles of a triangle add up to 180° (Euclid, Elements I.32).
  • cos 90° = 0, cos 60° = 0.5, cos 120° = −0.5. Between 90° and 180° the cosine is negative.
  • The triangle inequality: the two shorter sides must add up to more than the longest.
  • A computed cosine that lands just outside −1 to 1 by rounding is clamped to the nearest end. Anything further out is reported as no triangle.
  • π is the double-precision value 3.141592653589793 that your browser has built in.

For an angle opposite a known side, the law of sines calculator is the one to use. The triangle calculator takes every case and also gives heights and radii. For a right triangle, try the Pythagorean theorem calculator.

Nothing you type is uploaded. We count events without cookies (details).

FAQ

What is the law of cosines?

It is the Pythagorean theorem with a correction for the angle: c² = a² + b² − 2ab cos C. Side c is opposite angle C. When C is 90°, cos C is 0 and the extra term vanishes, leaving c² = a² + b².

When do I use it instead of the law of sines?

Use the law of cosines when you know three sides (SSS), or two sides and the angle between them (SAS). In both cases there is no side-and-opposite-angle pair to start the law of sines with. After one step with the law of cosines the tool switches to the law of sines for the rest.

How do I find an angle from three sides?

Rearrange the formula: cos C = (a² + b² − c²) / (2ab), then take arccos. For a = 7, b = 9, c = 12, cos A = (9² + 12² − 7²) / (2 × 9 × 12) = 176 / 216 = 0.8148, so A = 35.4°. The tool does this for two angles and subtracts from 180° for the third.

Why is the angle negative or over 90° sometimes?

A negative cosine means an obtuse angle, over 90°. With sides 5, 8 and an included angle of 120°, cos 120° = −0.5, so the −2ab cos C term adds instead of subtracting, and c comes out longer than the Pythagorean value.

Why does it say there is no triangle for three sides?

The two shorter sides must add up to more than the longest. For 3, 4 and 7, they add up to exactly 7, so the triangle is flat. For 1, 2 and 10 the short sides can not reach each other. Then the cosine would be outside the range −1 to 1, and no angle has that.

Is the law of cosines more accurate than the law of sines?

For finding angles, the law of cosines is steadier when an angle is near 0° or 180°, where the sine is flat. The tool uses the law of cosines for SSS for that reason, and uses the law of sines only for the angle opposite the shorter side, which is always acute.

Can I get a side from two sides and an angle that is not between them?

That is SSA, and it can have two answers. Use the law of sines calculator, which shows both.

Are my numbers uploaded or saved?

No. Everything runs in your browser. What you type is not put in the address bar, not stored and not counted. We only count which case was solved.

More from FLXCode

Share Law of Cosines Calculator