Home/Mathematics/Law of Cosines

Formula & Calculator

Law of Cosines

Generalizes the Pythagorean theorem to any triangle, relating one side's length to the other two sides and the angle between them.

MathematicsTrigonometryDaily Life

Law of Cosines Calculatorc² = a² + b² − 2ab·cos(C)

c² = a² + b² − 2·a·b·cos( C )
a, b, c = side lengths  ·  C = angle opposite side c
⟹ Solvea, b, c, C
°
Angle unit:
Solve for:
Presets:
c
a: b: c: C:
✓ Copied!
Triangle Side Gauge
Small Medium Large Very Large
c² = a² + b² − 2ab·cos(C)  ·  All side lengths in same units
c^2 = a^2 + b^2 - 2ab*cos(C)
Law of Cosines

Variables

SymbolQuantityUnit
a, b, cSide lengths of the triangle
CAngle opposite side c

What it means

The law of cosines gives the relationship between the three sides of any triangle and one of its angles. It states that the square of one side equals the sum of the squares of the other two minus twice their product times the cosine of the included angle. It is a generalisation of the Pythagorean theorem (which is the special case when the angle is 90°). This law is used in surveying (triangulation), navigation, physics (resolving vectors), and computer graphics (angle between vectors). It is also used to find angles when all sides are known. Understanding the law of cosines is essential for trigonometry and its applications.

Worked example

Law of Cosines – Two Examples

Real‑World
Scenario: A surveyor measures two sides of a triangular plot: a=5 m, b=7 m, and the included angle C=60°. He finds the third side c.
ParameterValue
a5
b7
C60°
1c² = 5² + 7² − 2·5·7·cos60° = 25+49 − 35 = 39
2c = √39 ≈ 6.24 m
Result 6.24 m ✓ Third side
Scenario: A navigator wants the distance between two ships that are 8 km and 6 km from a lighthouse, with angle 120° between them.
ParameterValue
a8
b6
C120°
1c² = 64+36 − 2·8·6·cos120° = 100 − 96·(−0.5) = 100 + 48 = 148
2c = √148 ≈ 12.17 km
Result 12.17 km ✓ Ship distance
Insight: Generalises Pythagoras – works for any triangle. When C=90°, it reduces to c²=a²+b².

Common mistakes

  • Law of Cosines: c² = a² + b² − 2ab·cos(C) – where C is the angle opposite side c.
  • Angle: C is in the triangle, between sides a and b.
  • Unit: The angle is in radians or degrees – ensure your calculator is in the correct mode.
  • Check: If C = 90°, the term 2ab·cos(C) = 0, so it reduces to the Pythagorean theorem.
  • Side lengths: a, b, c are lengths in the same units.

Applications

The law of cosines, c² = a² + b² − 2ab·cos(C), generalises the Pythagorean theorem to any triangle, relating the sides to the included angle. This is used to solve triangles when two sides and the included angle are known, or when three sides are known. In surveying and navigation, it helps compute distances and bearings. In physics, it resolves vectors using non‑right‑angle components. In engineering, it is used in structural analysis, bridge design, and robotics kinematics. By applying the law of cosines, professionals can analyse oblique triangles, which are common in real‑world geometry, enabling accurate measurements and design.

  • Surveying and land measurement (triangulation)
  • Navigation and course calculation (great‑circle routes)
  • Structural analysis of trusses and frames
  • Robotics – forward and inverse kinematics
  • Physics – resultant of non‑perpendicular vectors