Law of cosines
In trigonometry, the law of cosines (also known as the cosine formula or cosine rule) relates the lengths of the sides of a triangle to the cosine of one of its angles. For a triangle with sides and opposite respective angles and (see Fig. 1), the law of cosines states:
This article is about the trigonometric identity. For the cosine law of optics, see Lambert's cosine law.
The law of cosines generalizes the Pythagorean theorem, which holds only for right triangles: if is a right angle then and the law of cosines reduces to
The law of cosines is useful for solving a triangle when all three sides or two sides and their included angle are given.
The theorem is used in solution of triangles, i.e., to find (see Figure 3):
These formulas produce high round-off errors in floating point calculations if the triangle is very acute, i.e., if c is small relative to a and b or γ is small compared to 1. It is even possible to obtain a result slightly greater than one for the cosine of an angle.
The third formula shown is the result of solving for a in the quadratic equation a2 − 2ab cos γ + b2 − c2 = 0. This equation can have 2, 1, or 0 positive solutions corresponding to the number of possible triangles given the data. It will have two positive solutions if b sin γ < c < b, only one positive solution if c = b sin γ, and no solution if c < b sin γ. These different cases are also explained by the side-side-angle congruence ambiguity.
Polyhedra[edit]
The Law of Cosines can be generalized to all polyhedra by considering any polyhedron with vector sides and invoking the Divergence Theorem .[16]