## Cosine theorem on the sphere

The cosine theorem on a sphere is an interesting relation that holds for a spherical triangle. One of it’s main applications is the computation of the air distance between two geographical points given by their latitude – longitude coordinates (I’ll show how in the next post).

Consider the spherical triangle $NA'B'$ (see figure). The cosine theorem express a relation between the angles $a, b, c$ and $u$ which I’ll prove with basic geometry knowledge.

First of all note that $AN$ and $BN$ have nothing to do with the problem, they are just an auxiliary construction used for the proof. So first look only at the sphere and ignore $AA', AN, B'B, BN, AB$.

Then let’s consider $AN$ the tangent to the arc $A'N$ in the point $N$, and $BN$, the tangent to the arc $B'N$ in the point $N$. Thus we’ll have $AN||A''O$ and $BN||B''O$.
To prove the spherical cosine theorem the length of the segment $AB$ can be written in two different ways: using cosine theorem in the triangle $NAB$ and using cosine theorem in the triangle $OAB$.

Note that $OAN$ is a right triangle($N$ being the right angle) because $AN$ is a tangent to the sphere. Thus $AN = R \cdot tg(a)$ and $OA = \frac{R}{ cos(a)}$. Note that $ON=R$. Take it slowly to understand it, and make sure you visualise correctly the 3D figure :).  (*)

Same for triangle $OBN$ we get: $BN = R \cdot tg(b)$ and $OB = \frac{R}{cos(b)}$. (**)

From the cosine theorem in triangle $OAB$ we get:
$AB^2 = OA^2 + OB^2 - 2 \cdot OA \cdot OB \cdot cos(c)$

Note that the angle $ANB$ is $u$. From generalised cosine theorem in $NAB$ we get:
$AB^2 = NA^2 + NB^2 -2 \cdot NA \cdot NB \cdot cos(u)$

It follows that: $OA^2 + OB^2 - 2 \cdot OA \cdot OB \cdot cos(c) = NA^2 + NB^2 -2 \cdot NA \cdot NB \cdot cos(u)$

Replacing with the values computed in (*) and (**) leads to:

$\left(\frac{R}{cos(a)}\right)^2+\left(\frac{R}{cos(b)}\right)^2-2 \cdot \frac{R^2 \cdot cos(c)}{cos(a) \cdot cos(b)}$ =
$\left(\frac{R \cdot sin(a)}{cos(a)}\right)^2+\left(\frac{R \cdot sin(b)}{cos(b)}\right)^2-2 \cdot \frac{R^2 \cdot sin(a) \cdot sin(b) \cdot cos(u)}{cos(a) \cdot cos(b)}$

Now add the fractions on both sides of the equality by making them have the same denominator, and divide both sides by $R^2$:
$cos(b)^2 + cos(a)^2 - 2 \cdot cos(a) \cdot cos(b) \cdot cos(c)$=$sin(a)^2 \cdot cos(b)^2 + sin(b)^2 \cdot cos(a)^2 - 2 \cdot sin(a) \cdot sin(b) \cdot cos(a) \cdot cos(b) \cdot cos(u)$ (***)

Because $cos(x)^2+sin(x)^2=1$ for every $x$:

$cos(b)^2 - sin(a)^2 \cdot cos(b)^2 = cos(a)^2 \cdot cos(b)^2$ and $cos(a)^2 - sin(b)^2 \cdot cos(a)^2 = cos(a)^2 \cdot cos(b)^2$

Then (***) become:

$cos(a)^2 \cdot cos(b)^2 + cos(a)^2 \cdot cos(b)^2 - 2 \cdot cos(a) \cdot cos(b) \cdot cos(c)=-2 \cdot sin(a) \cdot sin(b) \cdot cos(a) \cdot cos(b) \cdot cos(u)$

By dividing with $2 \cdot cos(a) \cdot cos (b)$ we get:

$cos(a) \cdot cos(b) - cos(c) = -sin(a) \cdot sin(b) \cdot cos(u)$  that can be written in a final form as:

$cos(a)cos(b) + sin(a)sin(b)cos(u) = cos(c)$

A remarkable thing is that when $u$ is a right angle, $cos(u)=0$, and we get the Pithagora theorem on the sphere:

$cos(a)cos(b) = cos(c)$