# Law of Cosines

The Law of Cosines (also known as the Cosine Rule) allows to find the length of the third side of a triangle knowing two other sides and the angle between them.

## Theorem (Law of Cosines)

Consider a triangle with the sides a, b, c and angles α, β, γ.

The Law of Cosines states that

where $$\gamma$$ denotes the angle between the sides $$a$$ and $$b.$$

The sides $$a$$ and $$b$$ can also be expressed in terms of two other sides and angle between them:

When the angle $$\gamma$$ between the sides $$a$$ and $$b$$ is a right angle, the Law of Cosines reduces to the Pythagorean Identity:

${c^2} = {a^2} + {b^2}.$

So the law of cosines is a generalization of the Pythagorean Theorem for an arbitrary triangle.

### Proof

We consider separately the cases of acute and obtuse triangles.

In the first case, assume that the angle $$\gamma$$ is an acute angle.

Draw the altitude $$BD$$ from the vertex $$B$$ to the side $$AC = b.$$ Its height $$h$$ can be found from the trigonometric identity for the right triangle $$BDC:$$

$h = BD = a\sin \gamma .$

The line segment $$CD$$ (the projection of side $$a$$ onto the side $$b$$) has the length

$CD = a\cos \gamma .$

In the right traingle $$ADB,$$ the side $$AD$$ is given by

$AD = b - CD = b - a\cos \gamma .$

Using the Pythagorean Identity for $$\triangle ADB$$, we get:

$A{B^2} = A{D^2} + B{D^2}, \;\Rightarrow {c^2} = {\left( {b - a\cos \gamma } \right)^2} + {h^2}, \;\Rightarrow {c^2} = {\left( {b - a\cos \gamma } \right)^2} + {\left( {a\sin \gamma } \right)^2}, \;\Rightarrow {c^2} = {b^2} - 2ab\cos \gamma + {a^2}{\cos ^2}\gamma + {a^2}{\sin ^2}\gamma .$

Notice that

${a^2}{\cos ^2}\gamma + {a^2}{\sin ^2}\gamma = {a^2}\left( {\underbrace {{{\cos }^2}\gamma + {{\sin }^2}\gamma }_1} \right) = {a^2}.$

Therefore

${c^2} = {a^2} + {b^2} - 2ab\cos \gamma .$

Let now the angle $$\gamma$$ be obtuse.

In this case, the altitude $$BD = h$$ is given by

$h = BD = a\sin \left( {180^\circ - \gamma } \right).$

By the reduction identity, $$\sin \left( {180^\circ - \gamma } \right) = \sin \gamma .$$ Hence, the height $$h$$ is expressed by the same formula:

$h = BD = a\sin \left( {180^\circ - \gamma } \right) = a\sin \gamma .$

Again, by the reduction identity, the length of the line segment $$CD$$ is given by

$CD = a\cos \left( {180^\circ - \gamma } \right) = - a\cos \gamma .$

From the right triangle $$ADB,$$ we have

$A{B^2} = A{D^2} + B{D^2}, \;\Rightarrow {c^2} = {\left[ {b + \left( { - a\cos \gamma } \right)} \right]^2} + {h^2}, \;\Rightarrow {c^2} = {\left( {b - a\cos \gamma } \right)^2} + {\left( {a\sin \gamma } \right)^2}, \;\Rightarrow {c^2} = {b^2} - 2ab\cos \gamma + {a^2}{\cos ^2}\gamma + {a^2}{\sin ^2}\gamma , \;\Rightarrow {c^2} = {a^2} + {b^2} - 2ab\cos \gamma .$

Similarly, the Law of Cosines can be proved for two other sides of the triangle.

See solved problems on Page 2.