Let , , and be the lengths of the legs of a triangle opposite angles , , and . Then the law of cosines states
(1)
| |||
(2)
| |||
(3)
|
Solving for the cosines yields the equivalent formulas
(4)
| |||
(5)
| |||
(6)
|
This law can be derived in a number of ways. The definition of the dot product incorporates the law of cosines, so that the length of the vector from to is given by
(7)
| |||
(8)
| |||
(9)
|
where is the angle between and .
The formula can also be derived using a little geometry and simple algebra. From the above diagram,
(10)
| |||
(11)
| |||
(12)
|
The law of cosines for the sides of a spherical triangle states that
(13)
| |||
(14)
| |||
(15)
|
(Beyer 1987). The law of cosines for the angles of a spherical triangle states that
(16)
| |||
(17)
| |||
(18)
|
(Beyer 1987).
For similar triangles, a generalized law of cosines is given by
(19)
|
(Lee 1997). Furthermore, consider an arbitrary tetrahedron with triangles , , , and . Let the areas of these triangles be , , , and , respectively, and denote the dihedral angle with respect to and for by . Then
(20)
|
which gives the law of cosines in a tetrahedron,
(21)
|
(Lee 1997). A corollary gives the nice identity
(22)
|