Spherical law of cosines

In spherical trigonometry, the law of cosines (or, more specifically, the law of cosines for sides) is a theorem relating the three sides and one of the angles of a spherical triangle, analogous to the planar law of cosines for a triangle in the Euclidean plane.

A spherical triangle is a shape on a sphere consisting of three vertices (corner points) connected by three sides, each of which is part of a great circle, the analog on the sphere of a straight line in the plane (for example the equator and meridians of a globe). The arc lengths of the sides are proportional to the measures of the central angles they subtend. The angles between sides are dihedral angles between the planes containing them. In the image, u, v, and w represent three points on the sphere. If the angular lengths of the sides are a (from u to v), b (from u to w), and c (from v to w), and the angle of the corner opposite c is C, then the (first) spherical law of cosines states:

As a special case, when C = π/2 then cos C = 0, resulting in the spherical analogue of the Pythagorean theorem:

If the law of cosines is used to solve for c, the necessity of inverting the cosine magnifies rounding errors when c is small. In this case, the alternative formulation of the law of haversines is preferable.

A second spherical law of cosines, sometimes called the law of cosines for angles, relates the three angles and one of the sides of a triangle:

where A and B are the angles of the corners opposite to sides a and b, respectively. It is related to the first law by polar duality.