Law of Cosines Calculator Formula

Understand the math behind the law of cosines calculator. Each variable explained with a worked example.

Formulas Used

Side C

side_c = sqrt(pow(side_a, 2) + pow(side_b, 2) - 2 * side_a * side_b * cos(angle_c * pi / 180))

Angle A

angle_a = acos((pow(side_b, 2) + pow(sqrt(pow(side_a, 2) + pow(side_b, 2) - 2 * side_a * side_b * cos(angle_c * pi / 180)), 2) - pow(side_a, 2)) / (2 * side_b * sqrt(pow(side_a, 2) + pow(side_b, 2) - 2 * side_a * side_b * cos(angle_c * pi / 180)))) * 180 / pi

Variables

VariableDescriptionDefault
side_aSide a7
side_bSide b10
angle_cIncluded Angle C (degrees)(deg)60

How It Works

Law of Cosines

Formula

c² = a² + b² - 2ab × cos(C)

c = sqrt(a² + b² - 2ab × cos(C))

This generalizes the Pythagorean theorem. When C = 90°, cos(C) = 0, and it reduces to c² = a² + b².

When to Use

  • You know two sides and the included angle (SAS) and want the third side
  • You know all three sides (SSS) and want an angle
  • Worked Example

    Find side c: a = 7, b = 10, angle C = 60°.

    side_a = 7side_b = 10angle_c = 60
    1. 01c² = 49 + 100 - 2(7)(10)cos(60°)
    2. 02= 149 - 140 × 0.5
    3. 03= 149 - 70 = 79
    4. 04c = √79 ≈ 8.8882

    Ready to run the numbers?

    Open Law of Cosines Calculator