Law of Cosines Calculator

Enter two sides and the included angle to find the third side, the remaining angles and the area.

How it is calculated

You give two sides a and b (any length unit) and the angle C between them in degrees, strictly between 0 and 180. The tool computes c = √(a² + b² − 2ab·cos C) and the area ½·a·b·sin C in the square of whatever length unit you used. Angle A comes from the law of cosines again, cos A = (b² + c² − a²) ÷ (2bc), so an obtuse A is reported correctly, and then B = 180° − C − A. The side and area are shown to four decimals, the angles to two. Sides must be above zero. A side of 0, or an angle of 0 or 180 or more, shows no result.

Worked example

Let a = 9, b = 4 and the included angle C = 30°. Then c² = 81 + 16 − 2·9·4·cos 30° = 97 − 72 × 0.8660 = 34.646, so c = 5.8861. Area = ½ × 9 × 4 × sin 30° = 18 × 0.5 = 9.0000 sq units. Angle A: cos A = (16 + 34.646 − 81) ÷ (2 × 4 × 5.8861) = −0.6446, so A = 130.14°, an obtuse angle. Then B = 180 − 30 − 130.14 = 19.86°. For comparison, a = 7, b = 9 and C = 50° gives c = 7.0006 and A = 49.99°, B = 80.01°.

Try this example →

Common mistakes

  • Entering an angle that is not between the two known sides. This tool is for two sides and their included angle (SAS); an angle opposite one of the sides gives the wrong third side.
  • Typing the angle in radians. The tool reads degrees, so 0.87 is read as less than one degree and the result is a nearly flat triangle.
  • Entering a right or 180° angle and expecting a result. C must be strictly between 0 and 180, and a straight 180° angle is not a triangle.
  • Mixing units for a and b, such as one side in metres and the other in centimetres. The area is in the square of the same unit, so both sides must match.
  • Assuming A and B must be acute. If the longer side faces a large angle, A can be obtuse, as in the example where A = 130.14°.

About this calculator

The law of cosines, c² = a² + b² − 2ab·cos(C), generalizes the Pythagorean theorem to any triangle by relating the length of one side to the other two sides and the angle between them. Given two sides and the included angle (the SAS case), this calculator solves directly for the third side, then finds a second angle with another application of the law of cosines (which, unlike the law of sines, also gives obtuse angles correctly) and the third from the 180° angle sum and computes the triangle's area from two sides and the included angle: Area = ½ab·sin(C).

Because it works for any triangle — not just right triangles — the law of cosines is a core tool in surveying (triangulating distances from measured angles), navigation (dead-reckoning position from bearing and distance), structural and truss analysis, and any physics problem involving vector addition where the angle between two vectors is known but their resultant isn't.

Was this helpful?

You can pick up to 3 reactions.

Comments (1)

  • Editorial team

    Angles are usually the shakiest measurement in field work, so see how much a one-degree error costs. Sides 5 and 7 with a 60 degree angle give a third side of 6.2450, and at 61 degrees it is 6.3296, a shift of about 0.085 from a single degree. Longer sides magnify that error. As a quick plausibility test, the third side must stay between the difference and the sum of the other two. Which measurement do you trust least in your setup?

Popular calculators

All Calculators