calc-hub logocalc-hub.net

Law of Cosines Calculator

Enter two sides and the angle between them (SAS), or all three sides (SSS). The calculator uses c² = a² + b² − 2ab·cos C to find the missing side or the angles, then gives the area and perimeter. For SSS it first checks that the sides can form a triangle.

Enter sides a and b and the angle C between them.

How to use the Law of Cosines Calculator

  1. Pick SAS if you know two sides and the angle between them, or SSS if you know all three sides.
  2. For SAS, enter sides a and b and the angle C where they meet, in degrees. For SSS, enter sides a, b and c.
  3. Press Calculate to get all three sides, all three angles, the area and the perimeter.

The law of cosines formula

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

The square of one side equals the sum of the squares of the other two, minus twice their product times the cosine of the angle between them. Use the first form to find a side (SAS). Rearrange it into the second form to find an angle from three sides (SSS). Swap the letters to get the same rule for side a and angle A, or side b and angle B.

Worked example (SAS)

Given a = 8, b = 11 and the angle between them, C = 37°. c² = 8² + 11² − 2 × 8 × 11 × cos 37° = 185 − 140.56 = 44.44, so c = 6.67. The law of cosines then gives A = 46.24°, and B = 180° − 37° − 46.24° = 96.76°. Enter the same values in SAS mode above to check.

When to use the law of cosines

Use the law of cosines when no angle has its opposite side known. That happens in two cases. In SAS the known angle sits between the known sides, and in SSS you know no angles at all. For AAS, ASA and SSA the law of sines is shorter.

The same rule has a form for every side and every angle. Pick the row that matches what you are solving for.

Law of cosines, every form
To findFormula
Side c from a, b and Cc² = a² + b² − 2ab·cos(C)
Side a from b, c and Aa² = b² + c² − 2bc·cos(A)
Side b from a, c and Bb² = a² + c² − 2ac·cos(B)
Angle C from three sidescos(C) = (a² + b² − c²) / (2ab)
Angle A from three sidescos(A) = (b² + c² − a²) / (2bc)
Angle B from three sidescos(B) = (a² + c² − b²) / (2ac)

Example 2: SSS (a = 7, b = 9, c = 12)

Start with the largest angle, C, which sits opposite the longest side. cos C = (49 + 81 − 144) / 126 = −0.1111, so C = 96.38°. A negative cosine means an obtuse angle, and the inverse cosine returns it correctly.

cos A = (81 + 144 − 49) / 216 = 0.8148, so A = 35.43°. Then B = 180° − 35.43° − 96.38° = 48.19°.

Watch out for the law of sines after SAS

In the SAS example above, once you know c = 6.67 it is tempting to find B with the law of sines. sin B = 11 × sin 37° / 6.6663, and the inverse sine of that returns 83.24°. The true angle is 96.76°, the other angle with the same sine. Use the law of cosines for any angle that might be obtuse, or find the smaller angle first with sines and get the last one from the 180° sum. This calculator finds the angles with cosines and the 180° sum, so it never falls into that trap.

Example 3: no triangle (a = 3, b = 4, c = 8)

3 + 4 = 7, which is shorter than 8, so the two short sides cannot meet. The formula shows it too. cos C = (9 + 16 − 64) / 24 = −1.625, and no angle has a cosine below −1. The calculator checks the triangle inequality before it solves and shows a message instead of a broken result.

Frequently asked questions

When should you use the law of cosines?

When you know two sides and the angle between them (SAS), or all three sides (SSS). In both cases no angle is paired with its opposite side, so the law of sines has nothing to start from.

How is the law of cosines related to the Pythagorean theorem?

It is the general version. When C = 90°, cos C = 0, the last term drops out, and c² = a² + b² is left. For angles above 90° the cosine is negative, so c comes out longer than the Pythagorean value. Below 90° it comes out shorter.

Can the law of cosines give an obtuse angle?

Yes, and that is a good reason to use it for angles. The inverse cosine returns values from 0° to 180°, so a negative cosine gives an obtuse angle directly. With sides 7, 9 and 12, cos C = −0.1111 and C = 96.38°. The inverse sine never returns more than 90°.

What if my three sides do not form a triangle?

Each side has to be shorter than the other two added together. Sides 3, 4 and 8 fail, because 3 + 4 = 7 is less than 8. The calculator checks this first and shows a message instead of a result.

We use cookies

We use cookies to ensure you get the best experience on our website. For more information on how we use cookies, please see our cookie policy.

By clicking "Accept", you agree to our use of cookies.
Learn more.