algebrica-org-pages/law-of-cosines.md

# The Law of Cosines

Source: algebrica.org - CC BY-NC 4.0
https://algebrica.org/law-of-cosines/
Fetched from algebrica.org post 7152; source modified 2026-05-02T15:38:48.

## Definition

The law of cosines relates the sides of any triangle through the angle opposite to one of them. It can be viewed as a generalisation of the [Pythagorean theorem](../pythagorean-theorem.md), valid not only for right triangles but for every triangle: the square of a side equals the sum of the squares of the other two sides, minus a corrective term that accounts for how open the angle between them is. For a triangle with sides \\(a, b, c\\) and angle \\(\\theta\\) opposite to side \\(c\\), the law states:

\\[
c^2 = a^2 + b^2 - 2ab \\cos(\\theta)
\\]

When \\(\\theta = 90^\\circ\\) the [cosine](../sine-and-cosine.md) term vanishes and the formula reduces exactly to the Pythagorean theorem, which confirms that the law of cosines is a strict generalisation of that result. For any other angle, the corrective term either subtracts from or adds to the sum \\(a^2 + b^2\\), depending on whether \\(\\theta\\) is acute or obtuse.

![Law of cosine.](https://algebrica.org/wp-content/uploads/resources/images/law-of-cosine-1.png "Law of cosine.")

To derive the formula, drop the altitude \\(h\\) from the vertex opposite to \\(c\\) to the side \\(b\\). This divides \\(b\\) into two segments: \\(m = a\\cos(\\theta)\\) and \\(n = b - a\\cos(\\theta)\\), while the altitude itself satisfies \\(h = a\\sin(\\theta)\\). Applying the Pythagorean theorem to the right triangle formed by \\(n\\), \\(h\\) and \\(c\\) gives:

\\[
\\begin{align} c^2 &= n^2 + h^2 \\[6pt] &= (b - a\\cos(\\theta))^2 + (a\\sin(\\theta))^2 \\[6pt] &= b^2 - 2ab\\cos(\\theta) + a^2\\cos^2(\\theta) + a^2\\sin^2(\\theta) \\[6pt] &= b^2 - 2ab\\cos(\\theta) + a^2(\\cos^2(\\theta) + \\sin^2(\\theta)) \\end{align}
\\]

Since the [Pythagorean identity](../pythagorean-identity.md) gives \\(\\sin^2(\\theta) + \\cos^2(\\theta) = 1\\), the expression simplifies to:

\\[
c^2 = a^2 + b^2 - 2ab\\cos(\\theta)
\\]

> The law of cosines is often used in conjunction with the [law of sines](../law-of-sines.md), which provides a complementary approach to solving triangles when different combinations of sides and angles are known.

## Example 1

Consider a triangle with sides \\(a = 8\\), \\(b = 6\\) and included angle \\(\\theta = 60^\\circ\\). The goal is to determine the length of the third side \\(c\\). Substituting the known values into the law of cosines gives:

\\[
\\begin{align} c^2 &= a^2 + b^2 - 2ab\\cos(\\theta) \\[6pt] &= 64 + 36 - 2(8)(6)\\cos(60^\\circ) \\[6pt] &= 64 + 36 - 96 \\cdot \\frac{1}{2} \\[6pt] &= 100 - 48 \\[6pt] &= 52 \\end{align}
\\]

Taking the positive square root, one obtains \\(c = \\sqrt{52} = 2\\sqrt{13} \\approx 7.21\\).

The length of the third side is approximately \\(7.21\\) units.

## Example 2

Consider a triangle with sides \\(a = 5\\), \\(b = 7\\) and \\(c = 9\\). The goal is to determine the angle \\(\\theta\\) opposite to side \\(c\\). Solving the law of cosines for \\(\\cos(\\theta)\\) gives:

\\[
\\cos(\\theta) = \\frac{a^2 + b^2 - c^2}{2ab}
\\]

Substituting the known values:

\\[
\\begin{align} \\cos(\\theta) &= \\frac{25 + 49 - 81}{2(5)(7)} \\[6pt] &= \\frac{-7}{70} \\[6pt] &= -0.1 \\end{align}
\\]

Since \\(\\cos(\\theta) < 0\\), the angle \\(\\theta\\) is obtuse. Taking the inverse cosine yields:

\\[
\\theta = \\arccos(-0.1) \\approx 95.7^\\circ
\\]

The angle opposite to the longest side is approximately \\(95.7^\\circ\\).

## Vector interpretation

The law of cosines admits a reading in terms of [vectors](../vectors.md) that exposes its deeper structure and connects it to the inner product. Consider a triangle with vertex \\(O\\), and let \\(\\vec{u}\\) and \\(\\vec{v}\\) denote the two sides of length \\(a\\) and \\(b\\) issuing from \\(O\\), so that \\(a = |\\vec{u}|\\) and \\(b = |\\vec{v}|\\). The third side of the triangle, of length \\(c\\), is then represented by the vector \\(\\vec{v} - \\vec{u}\\), which joins the endpoints of \\(\\vec{u}\\) and \\(\\vec{v}\\). Expanding the squared norm of this vector through the bilinearity of the inner product gives:

\\[
\\begin{align} |\\vec{v} - \\vec{u}|^2 &= (\\vec{v} - \\vec{u}) \\cdot (\\vec{v} - \\vec{u}) \\[6pt] &= |\\vec{v}|^2 - 2\\,\\vec{u} \\cdot \\vec{v} + |\\vec{u}|^2 \\end{align}
\\]

The geometric definition of the inner product states that:

\\[
\\vec{u} \\cdot \\vec{v} = |\\vec{u}||\\vec{v}|\\cos\\theta
\\]

\\(\\theta\\) is the angle between the two vectors at \\(O\\), which coincides with the angle between the sides \\(a\\) and \\(b\\) of the triangle. Substituting this identity into the expansion above gives:

\\[
c^2 = a^2 + b^2 - 2ab\\cos\\theta
\\]

From this point of view the law of cosines is a reformulation of the identity that defines the inner product in terms of lengths and angles. The corrective term \\(-2ab\\cos\\theta\\) that distinguishes a generic triangle from a right one is nothing other than \\(-2\\,\\vec{u} \\cdot \\vec{v}\\), and the Pythagorean case corresponds to the situation in which the two vectors are orthogonal, so that \\(\\vec{u} \\cdot \\vec{v} = 0\\).

Theorem

The structure of the entry is shown in the conceptual map, where each branch represents a core component and the sub-nodes highlight the specific notions discussed.

Intermediate

2

Requires

0

Enables

The following concepts, [Right Triangle Trigonometry](../right-triangle-trigonometry.md), [Sine and Cosine](../sine-and-cosine.md), are required as prerequisites for this entry.