MathematicsTrigonometryMedium

Law of Cosines

Also known as:Cosine RuleCosine Formulaal-Kashi's theorem

The Law of Cosines generalises the Pythagorean theorem to any triangle, relating the square of one side to the sum of the squares of the other two sides minus twice their product times the cosine of the included angle. When the included angle is 90°, cos(90°) = 0 and the formula reduces to the Pythagorean theorem a² = b² + c². It is used to solve triangles when three sides (SSS) or two sides and the included angle (SAS) are known, and is fundamental in physics (vector addition), engineering, and 3D geometry.

Key Formula

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

LaTeX: c^2 = a^2 + b^2 - 2ab\cos(C)

SymbolMeaningUnit
cside opposite to angle Clength units
aone of the two sides enclosing angle Clength units
bthe other side enclosing angle Clength units
Cthe angle between sides a and bdegrees or radians

Worked Example

Problem

Two ships leave a port. Ship A travels 30 km on a bearing of N60°E, and Ship B travels 40 km due East. Find the distance between the two ships.

Solution

Step 1: Let side a = 30 km (Ship A), side b = 40 km (Ship B). The angle between them: Ship A goes 60° from North (= 30° from East), Ship B goes East (= 0° from East). Angle C between paths = 30°. Step 2: c² = a² + b² − 2ab·cos(C) = 30² + 40² − 2(30)(40)cos(30°). Step 3: c² = 900 + 1600 − 2400 × 0.8660 = 2500 − 2078.5 = 421.5. Step 4: c = √421.5 ≈ 20.53 km.

Answer

The two ships are approximately 20.5 km apart.

Law of Cosines — Solving Different Triangle Cases

KnownUnknownFormula UsedApplication
a, b, C (SAS)Side cc² = a² + b² − 2ab·cos(C)Most common SAS use
a, b, c (SSS)Angle Acos(A) = (b² + c² − a²) / (2bc)Find any angle from 3 sides
a, b, c (SSS)Angle Bcos(B) = (a² + c² − b²) / (2ac)Find second angle
a, b, 90° (right Δ)Hypotenuse cc² = a² + b²Reduces to Pythagoras
b, c, A (SAS)Side aa² = b² + c² − 2bc·cos(A)Equivalent form

Interactive Tools

Wolfram Alpha

Solve triangles using the Law of Cosines with symbolic and numerical solutions.

Open Tool

Desmos Graphing Calculator

Build triangle models and verify the Law of Cosines numerically.

Open Tool

Khan Academy — Trigonometry

Step-by-step lessons on the Law of Cosines with SAS and SSS examples.

Open Tool
Triangle showing sides a, b, c and angle C for the Law of Cosines

Wikimedia Commons, CC BY-SA

Related Terms

Known to Euclid as Proposition 12–13 of Book II of the Elements (c. 300 BC), though without trigonometric notation. The cosine formulation was developed by François Viète and others during the Renaissance. The name "Law of Cosines" became standard in 19th-century English textbooks; in French it is called théorème d'Al-Kashi, honouring Persian mathematician Jamshid al-Kashi (c. 1427 AD).

law-of-cosinestrigonometrytrianglepythagorean-theoremvector-additionoblique-triangle