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

(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