The Law of Cosines

In this tutorial, we’ll look at the law of cosines – a critical concept when it comes to solving triangles.

But before we dive into the law, here’s a quick summary of the convention we use to denote angles and side-lengths in a triangle.

The key idea is the length of each side is represented by the small case version of the letter for the opposite angle.

Law of cosines - a triangle with labeled sides and angles

For example, the angle opposite to the side AB\hspace{0.2em} AB \hspace{0.2em} is angle C\hspace{0.2em} C \hspace{0.2em}. So the side and its length are represented by c\hspace{0.2em} c \hspace{0.2em}.

The Law of Cosines – Formulas & Proof

The law of cosines gives the relationship between the side lengths of a triangle and the cosine of any of its angles.

It says –

a2=b2+c22bccosAa^2 = b^2 + c^2 - 2bc \, \cos A

We can re-frame the formula above for other sides/angles.

b2=a2+c22accosBc2=a2+b22abcosC\begin{align*} b^2 = a^2 + c^2 - 2ac \, \cos B \\[1em] c^2 = a^2 + b^2 - 2ab \, \cos C \end{align*}

Now, the most common use cases for the law of cosines are –

  • to find a side (length), when the other two sides and their included angle is known, or
  • to find an angle if all three sides are known.

For cases where we need to find angles using the cosine rule, the three formulas can be rearranged as –

cosA=b2+c2a22bccosB=a2+c2b22accosC=a2+b2c22ab\begin{align*} \cos A \, = \, \frac{b^2 + c^2 - a^2}{2bc} \\[1.5em] \cos B \, = \, \frac{a^2 + c^2 - b^2}{2ac} \\[1.5em] \cos C \, = \, \frac{a^2 + b^2 - c^2}{2ab} \end{align*}

The law of cosines is also known as the cosine rule.

Law of Cosines – Proof

To prove the cosine law, we will make use of the following figure.

Law of cosines - proof (diagram)

In ABD\hspace{0.2em} \triangle ABD \hspace{0.2em},

cosA=rbr=bcosA(1)\begin{align*} \cos A \, \, &= \, \, \frac{r}{b} \\[1em] r \, \, &= \, \, b \, \cos A \hspace{0.25cm} \rule[0.1cm]{1cm}{0.1em} \hspace{0.15cm} (1) \end{align*}

Also, in the same triangle,

sinB=hbh=bsinB(2)\begin{align*} \sin B \, \, &= \, \, \frac{h}{b} \\[1em] h \, \, &= \, \, b \, \sin B \hspace{0.25cm} \rule[0.1cm]{1cm}{0.1em} \hspace{0.15cm} (2) \end{align*}

In ADC\hspace{0.2em} \triangle ADC \hspace{0.2em},

a2=h2+(cr)2a2=h2+c2+r22cr\begin{align*} a^2 \, \, &= \, \, h^2 + (c - r)^2 \\[1em] a^2 \, \, &= \, \, h^2 + c^2 + r^2 - 2 \cdot c \cdot r \end{align*}

Substituting the values of r\hspace{0.2em} r \hspace{0.2em} and h\hspace{0.2em} h \hspace{0.2em} from equations (1)\hspace{0.2em} (1) \hspace{0.2em} and (2)\hspace{0.2em} (2) \hspace{0.2em}, we have

a2=(bsinA)2+c2+(bcosA)22cbcosA=b2sin2A+c2+b2cos2A2cbcosA=b2(sin2A+cos2A)+c22cbcosA=b2+c22cbcosA\begin{align*} a^2 \, \, &= \, \, (b \, \sin A)^2 + c^2 + (b \, \cos A)^2 - 2 \cdot c \cdot b \, \cos A \\[1em] &= \, \, {\color{Red} b^2 \, \sin^2 A} + c^2 + {\color{Red} b^2 \, \cos^2 A} - 2 \cdot c \cdot b \, \cos A \\[1em] &= \, \, {\color{Red} b^2 (\sin^2 A + \cos^2 A)} + c^2 - 2 \cdot c \cdot b \, \cos A \\[1em] &= \, \, {\color{Red} b^2} + c^2 - 2 \cdot c \cdot b \, \cos A \end{align*}
a2=(bsinA)2+c2+(bcosA)22cbcosA=b2sin2A+c2+b2cos2A2cbcosA=b2(sin2A+cos2A)+c22cbcosA=b2+c22cbcosA\begin{align*} a^2 \, \, &= \, \, (b \, \sin A)^2 + c^2 + (b \, \cos A)^2 \\[0.5em] &\hspace{8.5em} - 2 \cdot c \cdot b \, \cos A \\[1.3em] &= \, \, {\color{Red} b^2 \, \sin^2 A} + c^2 + {\color{Red} b^2 \, \cos^2 A} \\[0.5em] &\hspace{8.5em} - 2 \cdot c \cdot b \, \cos A \\[1.3em] &= \, \, {\color{Red} b^2 (\sin^2 A + \cos^2 A)} + c^2 \\[0.5em] &\hspace{8.5em} - 2 \cdot c \cdot b \, \cos A \\[1.3em] &= \, \, {\color{Red} b^2} + c^2 - 2 \cdot c \cdot b \, \cos A \end{align*}

And that’s it. We just proved the law of cosines.

In the last three steps, we factored out b2\hspace{0.2em} b^2 \hspace{0.2em} from two terms (in red) and then made use of the following trigonometric identity –

sin2A+cos2A=1 {\color{Red} \sin^2 A + \cos^2 A} \, \, = \, \, 1

Solving Triangles Using Law of Cosines

Alright, now it’s time to cement our understanding of the law of cosines and learn how to use it to solve triangles.

Note – In most cases, we need to use the sine rule along with the cosine rule to solve triangles. However, since the focus of this tutorial is on the cosine rule, we will only use examples that do not need the sine rule.

Also, in the following examples, I would encourage you to pay special attention to how the cosine rule is being used in the solution and not worry too much about how to solve triangles.

Example

Solve the triangle below for the missing sides and angles.

Solution

Here are the steps to solve this triangle.

Step 1.  Use the Cosine Rule to find the missing side

When we have two sides and the included angle, the law of cosines allows us to find the third side.

Applying the cosine rule for side b,

a2=b2+c22bccosA=102+622106cos88°131.81\begin{align*} a^2 \, \, &= \, \, b^2 + c^2 - 2bc \, \cos A \\[1em] &= \, \, 10^2 + 6^2 - 2 \cdot 10 \cdot 6 \, \cos 88 \degree \\[1em] &\approx \, \, 131.81 \end{align*}

Taking the square root on both sides

a11.48a \, \, \approx \, \, 11.48

Step 2.  Use the Cosine Rule for one of the remaining angles

Using the law of cosines (arranged for angles),

cosB=a2+c2b22ac62+11.4821022611.480.4921\begin{align*} \cos B \, &= \, \frac{a^2 + c^2 - b^2}{2ac} \\[1.3em] &\approx \, \frac{6^2 + 11.48^2 - 10^2}{2 \cdot 6 \cdot 11.48} \\[1.3em] &\approx \, 0.4921 \end{align*}

Taking cos inverse on both sides,

B60.52°B \, \approx \, 60.52 \degree

Step 3.  Finally, we can use the "Sum of Angles" property to find C\hspace{0.2em} \angle C \hspace{0.2em},

A+B+C=180°88°+60.52°+C180°C31.48°\begin{align*} A + B + C \, \, &= \, \, 180 \degree \\[1em] 88 \degree + 60.52 \degree + C \, \, &\approx \, \, 180 \degree \\[1em] C \, \, &\approx \, \, 31.48 \degree \end{align*}
Example

The sides of a triangle measure 5, 8, and 9. Find the measure of its angles.

Solution

This time, the question doesn't contain the drawing. So, let's start by drawing a rough sketch of the triangle and labeling the information given in the question. It’s not necessary but often makes things easier and helps avoid silly mistakes.

Step 1.  Use the Cosine Rule to find the largest angle

When we know all the side lengths, we can use the cosine rule to find any of the angles. But it’s best to start with the largest angle – the angle opposite to the longest side. Why?

Because if there is an obtuse angle (>90°)\hspace{0.2em} (> 90 \degree) \hspace{0.2em} in the triangle, it has to be this angle. The other two angles must be acute. And that’s useful to know when using the sine rule.

Here the largest angle would be A\hspace{0.2em} A \hspace{0.2em}. So let’s work on that.

cosA=b2+c2a22bc=52+8292258=0.1\begin{align*} \cos A \, &= \, \frac{b^2 + c^2 - a^2}{2bc} \\[1.3em] &= \, \frac{5^2 + 8^2 - 9^2}{2 \cdot 5 \cdot 8} \\[1.3em] &= \, 0.1 \end{align*}

Taking cos inverse on both sides, we have

A84.26°A \, \approx \, 84.26 \degree

Step 2.  Use the Cosine Rule for another angle

Because this is a tutorial on the law of cosines, here we are using it to find this angle. However, in general, I would suggest using the sine rule. It involves simpler calculations, and so is less error-prone.

cosB=a2+c2b22ac=92+82522980.8333\begin{align*} \cos B \, &= \, \frac{a^2 + c^2 - b^2}{2ac} \\[1.3em] &= \, \frac{9^2 + 8^2 - 5^2}{2 \cdot 9 \cdot 8} \\[1.3em] &\approx \, 0.8333 \end{align*}

Again, taking cos inverse on both sides, we have

B33.56°B \, \approx \, 33.56 \degree

Step 3.  Finally, we can use the "Sum of Angles" property to find C\hspace{0.2em} \angle C \hspace{0.2em},

A+B+C=180°84.26°+33.56°+C180°C62.18°\begin{align*} A + B + C \, \, &= \, \, 180 \degree \\[1em] 84.26 \degree + 33.56 \degree + C \, \, &\approx \, \, 180 \degree \\[1em] C \, \, &\approx \, \, 62.18 \degree \end{align*}

And that brings us to the end of this tutorial on the law of cosines. Until next time.