Trigonometry

Law of Cosines

The law of cosines, c² = a² + b² − 2ab·cos C, generalises the Pythagorean theorem to any triangle. Given two sides and the angle between them, this solver finds the third side, then uses the law of cosines again to find the remaining angles.

Law of Cosines

Solve a triangle from two sides and the included angle.

Try:
Answerc = 7, A = 81.7868°, B = 38.2132°
  1. Givena = 8, b = 5, included angle C = 60°
  2. Third sidec² = a² + b² − 2ab·cos C = 89 − 40 → c = 7
  3. Angle Acos A = (b² + c² − a²)/(2bc) → A = 81.7868°
  4. Angle BB = 180° − C − A = 38.2132°

The case where the sine rule cannot start

The Pythagorean theorem relates the three sides of a right triangle. Take the right angle away and the relation breaks — but not by much, and not unpredictably. The law of cosines is what it becomes: the same sum of two squares, plus a correction measuring how far the angle departs from a right angle.

This solver applies it to the SAS case. Given two sides and the angle between them, it finds the third side and then both remaining angles, completing the triangle from the three pieces that determine it.

The sine rule needs an angle paired with the side opposite it. In the SAS configuration no such pair exists: the known angle sits between the two known sides, opposite the side you do not have. Nothing can start until the third side is found, and this law finds it.

Once that side exists the triangle is fully determined, and the same law is applied a second time to recover an angle. Using it rather than the sine rule for that step avoids an ambiguity that would otherwise have to be resolved.

How to use this calculator

  1. Enter the two known sides Both must be positive. They are the two arms of the known angle, and the calculation is symmetric in them, so which you call a and which b does not matter.
  2. Enter the angle between them in degrees Strictly between 0 and 180. This must be the included angle — the one formed where the two sides meet — not one of the others.
  3. Read the third side first It is computed before either angle and both angles depend on it, so an error here propagates. It should fall between the difference and the sum of the two given sides.
  4. Read the two remaining angles One comes from the law of cosines again, the other from the angle sum. All three angles should total 180 degrees.

The formula, and where it comes from

c² = a² + b² − 2ab·cos C cos A = (b² + c² − a²)/(2bc) B = 180° − C − A

Read the first formula as Pythagoras plus a correction. When the included angle is a right angle its cosine is zero, the correction vanishes, and what remains is a² + b² = c² exactly. Any other angle leaves a term that lengthens or shortens the third side.

The sign of that term does the work. For an acute angle the cosine is positive, so the correction is subtracted and the third side is shorter than the right-angled case; for an obtuse angle the cosine is negative, the subtraction becomes an addition, and the side is longer — the algebra of opening an angle pushing its opposite side away.

The second formula is the first one rearranged to make an angle the subject. Once all three sides are known, any angle can be recovered this way, and the implementation uses it for angle A rather than reaching for the sine rule.

The last angle is taken from the 180-degree sum rather than computed a third time. That is both cheaper and safer: it guarantees the three reported angles are consistent with each other.

What each input means

a First side — form field “Side a”
One arm of the known angle. Must be positive. The angle opposite it is the first one reported.
b Second side — form field “Side b”
The other arm, also positive. Interchanging a and b swaps the two reported angles and nothing else.
C Included angle — form field “Included angle C (°)”
The angle between the two given sides, in degrees, strictly between 0 and 180. Values at or beyond those bounds describe no triangle and are rejected. Units: degrees.
c Third side
Opposite the included angle. Computed first, then used to find the remaining angles.

Worked examples

Every number below is produced by the same calculation engine the tool above runs. Nothing here is typed by hand, so the walkthrough cannot drift from what you get when you enter the same values yourself.

An acute included angle

Sides of 8 and 5 with 60 degrees between them. The cosine of 60 degrees is exactly one half, which makes the correction term easy to follow.

Inputs Side a = 8, Side b = 5, Included angle C (°) = 60

  1. Given a = 8, b = 5, included angle C = 60°
  2. Third side c² = a² + b² − 2ab·cos C = 89 − 40 → c = 7
  3. Angle A cos A = (b² + c² − a²)/(2bc) → A = 81.7868°
  4. Angle B B = 180° − C − A = 38.2132°

Result c = 7, A = 81.7868°, B = 38.2132°

The correction subtracts one whole product of the two sides, since twice the product times a half is just the product. The third side therefore comes out well short of the right-angled value, which is what an angle narrower than 90 degrees should do.

The third side is the shortest of the three, and it sits opposite the smallest angle. That correspondence between side order and angle order holds in every triangle and is a quick sanity check on any solution.

An obtuse included angle

Sides of 7 and 9 with 120 degrees between them. The cosine is now negative, so the correction changes sign.

Inputs Side a = 7, Side b = 9, Included angle C (°) = 120

  1. Given a = 7, b = 9, included angle C = 120°
  2. Third side c² = a² + b² − 2ab·cos C = 130 − -63 → c = 13.8924
  3. Angle A cos A = (b² + c² − a²)/(2bc) → A = 25.8722°
  4. Angle B B = 180° − C − A = 34.1278°

Result c = 13.8924, A = 25.8722°, B = 34.1278°

The third side exceeds both given sides, because subtracting a negative correction adds to the sum of squares. Opening the angle past 90 degrees pushes the two far ends apart, and the formula reproduces that without any special case.

The obtuse angle is the largest of the three, and the other two must therefore share less than 60 degrees between them. A triangle can hold at most one angle of 90 degrees or more, which is worth remembering when checking an answer.

Reading the result

Where the third side must lie

Between the difference of the two given sides and their sum. Those extremes correspond to the angle collapsing to zero or opening to a straight line, and the triangle inequality is exactly the statement that the real value falls strictly between them.

No ambiguity here

SAS determines a triangle uniquely: two sides and the angle between them fix the third vertex completely. Unlike some other configurations, there is never a second triangle satisfying the same data.

When you would use this

Finding a distance across an obstacle

Where two legs of a journey and the turn between them are known but the direct line is not, this gives it. Surveying, navigation and structural layout all reduce to that shape.

Recovering an angle from three known sides

The rearranged form works from three sides alone, which is the SSS case. Computing one angle that way and the rest from the sine rule solves a triangle given only its side lengths.

Assumptions and limitations

What this calculator assumes

  • The triangle is planar and its angles are entered in degrees.
  • Both given sides are strictly positive and the given angle lies strictly between 0 and 180 degrees.
  • The given angle is the one included between the two given sides.
  • The third angle is derived from the 180-degree sum rather than computed independently.

Where it stops being the right tool

  • Only the SAS configuration is accepted. The tool does not take three sides directly, nor two angles and a side.
  • Angles are entered and reported in degrees only, with no radian mode.
  • Area, perimeter, and the inradius or circumradius are not reported.

Common mistakes

Entering an angle that is not the included one

Why it happens. Any of the three angles can be measured, and the field simply asks for an angle. Using one of the others produces a plausible triangle that is not the one you have.

How to avoid it. Identify the vertex where the two given sides meet. The angle there is the included one; if your known angle sits elsewhere, the sine rule is the tool you need instead.

Omitting the factor of two in the correction

Why it happens. The term is written as 2ab·cos C, and the leading 2 is easy to drop when the expression is recalled from memory rather than looked up.

How to avoid it. Test the formula at 90 degrees. The correction should vanish entirely and leave Pythagoras — a check that catches a missing factor along with most other slips.

Forgetting to take a square root

Why it happens. The formula computes c², and that value is a natural place to stop because it looks like a finished number.

How to avoid it. Compare the result against the two given sides. A third side much larger than their sum has not been rooted, since the true value must be smaller than that sum.

Key terms

Frequently asked questions

What is the SAS case?

Side-Angle-Side: two sides are known along with the angle between them. That combination fixes the triangle uniquely, and the law of cosines solves it directly because the unknown side sits opposite the known angle.

How is this related to the Pythagorean theorem?

It is a generalisation. When the included angle is 90 degrees its cosine is zero, the correction term disappears, and the formula reduces exactly to c² = a² + b². Every other angle leaves a correction that lengthens or shortens the third side.

Can the included angle be obtuse?

Yes, any angle strictly between 0 and 180 degrees is valid. An obtuse angle has a negative cosine, so the correction is added rather than subtracted and the third side comes out longer than the right-angled case.

Why is the last angle found by subtraction?

Because the three angles must sum to 180 degrees, so once two are known the third is determined. Taking it from that sum is cheaper than a third inverse cosine and guarantees the reported angles are consistent.