The law of cosines
The law of sines needs an angle and the side across from it. If you know two sides and the angle between them, or all three sides, there is no such pair. The law of cosines handles these cases. It is the Pythagorean theorem, corrected for angles that are not ${90^\circ}$.
The law
In any triangle with sides ${a}$, ${b}$, ${c}$ opposite angles ${A}$, ${B}$, ${C}$:
${c^2=a^2+b^2-2ab\cos C}$
${a^2=b^2+c^2-2bc\cos A}$
${b^2=a^2+c^2-2ac\cos B}$
All three say the same thing: the square of one side equals the sum of the squares of the other two, minus twice their product times the cosine of the angle between them.
If ${C=90^\circ}$, then ${\cos C=0}$, and the first formula becomes ${c^2=a^2+b^2}$, the Pythagorean theorem.
Why it is true
Place the triangle on coordinate axes, with ${C}$ at the origin and ${A}$ at ${(b,0)}$. Since ${B}$ is a distance ${a}$ from the origin at angle ${C}$, its coordinates are ${(a\cos C,\ a\sin C)}$.
Now ${c}$ is the distance from ${A}$ to ${B}$. By the distance formula,
${c^2=(a\cos C-b)^2+(a\sin C)^2}$
Multiply out the first square, and collect the terms with ${a^2}$:
$\begin{align*}c^2&=a^2\cos^2 C-2ab\cos C+b^2+a^2\sin^2 C\\&=a^2(\cos^2 C+\sin^2 C)+b^2-2ab\cos C\\&=a^2+b^2-2ab\cos C\end{align*}$
Two sides and the angle between them
This case is called SAS (side, angle, side). Use the law of cosines to find the third side. Then find a second angle, and get the last one by subtracting from ${180^\circ}$.
Example 1: Solve the triangle with ${a=5}$, ${b=8}$, and ${C=60^\circ}$.
Solution:
Side ${c}$:
$\begin{align*}&c^2\\&=5^2+8^2-2(5)(8)\cos 60^\circ\\&=25+64-80\cdot\dfrac{1}{2}\\&=49\end{align*}$
So ${c=7}$.
Angle ${A}$: Solve ${a^2=b^2+c^2-2bc\cos A}$ for ${\cos A}$:
$\begin{align*}\cos A&=\dfrac{b^2+c^2-a^2}{2bc}\\&=\dfrac{64+49-25}{2(8)(7)}\\&=\dfrac{88}{112}\end{align*}$
So $A=\cos^{-1}\dfrac{88}{112}\approx 38.21^\circ$.
Angle ${B}$: The angles add up to ${180^\circ}$, so ${B\approx 81.79^\circ}$.
Solving the law of cosines for the cosine gives a form that finds any angle from the three sides:
${\cos C=\dfrac{a^2+b^2-c^2}{2ab}}$
Unlike the inverse sine, the inverse cosine gives angles from ${0^\circ}$ to ${180^\circ}$. So there is no ambiguous case: an obtuse angle shows up as a negative cosine.
Three sides
This case is called SSS. Find the largest angle first (the one across from the longest side). If the triangle has an obtuse angle, that is the one, and the law of cosines catches it.
Example 2: Solve the triangle with ${a=7}$, ${b=9}$, and ${c=12}$.
Solution:
Angle ${C}$ (across from the longest side):
$\begin{align*}\cos C&=\dfrac{7^2+9^2-12^2}{2(7)(9)}\\&=\dfrac{49+81-144}{126}=-\dfrac{14}{126}\end{align*}$
So
$C=\cos^{-1}\left(-\dfrac{14}{126}\right)\approx 96.38^\circ$
The cosine is negative, so ${C}$ is obtuse.
Angle ${A}$:
$\begin{align*}\cos A&=\dfrac{9^2+12^2-7^2}{2(9)(12)}\\&=\dfrac{176}{216}\end{align*}$
So ${A\approx 35.43^\circ}$.
Angle ${B}$: The angles add up to ${180^\circ}$, so ${B\approx 48.19^\circ}$.
Watch out: Three lengths make a triangle only if each one is less than the sum of the other two. For example, ${2}$, ${3}$, ${6}$ make no triangle. The law of cosines then gives a cosine greater than ${1}$ or less than ${-1}$.
Applications
Example 3: A tunnel is to be dug through a hill from ${A}$ to ${B}$. A surveyor at a point ${C}$ finds that ${A}$ is ${380}$ m away and ${B}$ is ${520}$ m away, with an angle of ${72^\circ}$ between the two directions. How long will the tunnel be?
Solution:
This is SAS. Use the law of cosines:
$\begin{align*}AB^2&=380^2+520^2-2(380)(520)\cos 72^\circ\\&\approx 144{,}400+270{,}400-122{,}124\\&\approx 292{,}676\end{align*}$
So ${AB\approx\sqrt{292{,}676}\approx 541}$ m.
Example 4: Two ships leave a port at the same time. One sails at ${20}$ mi/h and the other at ${25}$ mi/h, on courses that differ by ${110^\circ}$. How far apart are they after ${2}$ hours?
Solution:
After ${2}$ hours, the ships are ${40}$ mi and ${50}$ mi from port, with an angle of ${110^\circ}$ at the port between them:
$\begin{align*}d^2&=40^2+50^2-2(40)(50)\cos 110^\circ\\&\approx 1600+2500+1368\\&\approx 5468\end{align*}$
So ${d\approx 73.9}$ mi. Since ${\cos 110^\circ}$ is negative, the last term adds to the total: an angle wider than ${90^\circ}$ makes the ships farther apart than the Pythagorean theorem alone would say.
Which law should I use?
| You know | Use |
|---|---|
| two angles and a side (AAS, ASA) | law of sines |
| two sides and an angle opposite one of them (SSA) | law of sines (check for two triangles) |
| two sides and the angle between them (SAS) | law of cosines |
| three sides (SSS) | law of cosines |
Summary
- Law of cosines: ${c^2=a^2+b^2-2ab\cos C}$, and the same with the letters moved around.
- Solved for an angle: ${\cos C=\dfrac{a^2+b^2-c^2}{2ab}}$.
- Use it for SAS and SSS. It never has an ambiguous case, because ${\cos^{-1}}$ covers ${0^\circ}$ to ${180^\circ}$.
- A negative cosine means an obtuse angle.