Law of cosines
Template:Short description Template:About

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 Template:Tmath, Template:Tmath, and Template:Tmath, opposite respective angles Template:Tmath, Template:Tmath, and Template:Tmath (see Fig. 1), the law of cosines states:
The law of cosines generalizes the Pythagorean theorem, which holds only for right triangles: if Template:Tmath is a right angle then Template:Tmath, and the law of cosines reduces to Template:Tmath.
The law of cosines is useful for solving a triangle when all three sides or two sides and their included angle are given.
Use in solving triangles


The theorem is used in solution of triangles, i.e., to find (see Figure 3):
- the third side of a triangle if two sides and the angle between them is known:
- the angles of a triangle if the three sides are known:
- the third side of a triangle if two sides and an angle opposite to one of them is known (this side can also be found by two applications of the law of sines):Template:Efn
These formulas produce high round-off errors in floating point calculations if the triangle is very acute, i.e., if Template:Math is small relative to Template:Math and Template:Math or Template:Math 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 Template:Math. 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 Template:Math, only one positive solution if Template:Math, and no solution if Template:Math. These different cases are also explained by the side-side-angle congruence ambiguity.
History
Book II of Euclid's Elements, compiled c. 300 BC from material up to a century or two older, contains a geometric theorem corresponding to the law of cosines but expressed in the contemporary language of rectangle areas; Hellenistic trigonometry developed later, and sine and cosine per se first appeared centuries afterward in India.
The cases of obtuse triangles and acute triangles (corresponding to the two cases of negative or positive cosine) are treated separately, in Propositions II.12 and II.13:[1]
Proposition 13 contains an analogous statement for acute triangles. In his (now-lost and only preserved through fragmentary quotations) commentary, Heron of Alexandria provided proofs of the converses of both II.12 and II.13.[2]

Using notation as in Fig. 2, Euclid's statement of proposition II.12 can be represented more concisely (though anachronistically) by the formula
To transform this into the familiar expression for the law of cosines, substitute Template:Tmath, Template:Tmath, Template:Tmath, and Template:Nobr
Proposition II.13 was not used in Euclid's time for the solution of triangles, but later it was used that way in the course of solving astronomical problems by al-Bīrūnī (11th century) and Johannes de Muris (14th century).[3] Something equivalent to the spherical law of cosines was used (but not stated in general) by al-Khwārizmī (9th century), al-Battānī (9th century), and Nīlakaṇṭha (15th century).[4]
The 13th century Persian mathematician Naṣīr al-Dīn al-Ṭūsī, in his Template:Lang (Book on the Complete Quadrilateral, c. 1250), systematically described how to solve triangles from various combinations of given data. Given two sides and their included angle in a scalene triangle, he proposed finding the third side by dropping a perpendicular from the vertex of one of the unknown angles to the opposite base, reducing the problem to finding the legs of one right triangle from a known angle and hypotenuse using the law of sines and then finding the hypotenuse of another right triangle from two known sides by the Pythagorean theorem.[5]
About two centuries later, another Persian mathematician, Jamshīd al-Kāshī, who computed the most accurate trigonometric tables of his era, also described the solution of triangles from various combinations of given data in his Template:Lang (Key of Arithmetic, 1427), and repeated essentially al-Ṭūsī's method, now consolidated into one formula and including more explicit details, as follows:[6]

Using modern algebraic notation and conventions this might be written
when Template:Tmath is acute or
when Template:Tmath is obtuse. (When Template:Tmath is obtuse, the modern convention is that Template:Tmath is negative and is positive; historically sines and cosines were considered to be line segments with non-negative lengths.) By squaring both sides, expanding the squared binomial, and then applying the Pythagorean trigonometric identity Template:Tmath, we obtain the familiar law of cosines:
In France, the law of cosines is sometimes referred to as the théorème d'Al-Kashi.[7][8]
The same method used by al-Ṭūsī appeared in Europe as early as the 15th century, in Regiomontanus's De triangulis omnimodis (On Triangles of All Kinds, 1464), a comprehensive survey of plane and spherical trigonometry known at the time.[9]
The theorem was first written using algebraic notation by François Viète in the 16th century. At the beginning of the 19th century, modern algebraic notation allowed the law of cosines to be written in its current symbolic form.[10]
Proofs
Using the Pythagorean theorem


Case of an obtuse angle
Euclid proved this theorem by applying the Pythagorean theorem to each of the two right triangles in Fig. 2 (Template:Math and Template:Math). Using Template:Math to denote the line segment Template:Math and Template:Math for the height Template:Math, triangle Template:Math gives us
and triangle Template:Math gives
Expanding the first equation gives
Substituting the second equation into this, the following can be obtained:
This is Euclid's Proposition 12 from Book 2 of the Elements.[11] To transform it into the modern form of the law of cosines, note that
Case of an acute angle
Euclid's proof of his Proposition 13 proceeds along the same lines as his proof of Proposition 12: he applies the Pythagorean theorem to both right triangles formed by dropping the perpendicular onto one of the sides enclosing the angle Template:Math and uses the square of a difference to simplify.
Another proof in the acute case

Using more trigonometry, the law of cosines can be deduced by using the Pythagorean theorem only once. In fact, by using the right triangle on the left hand side of Fig. 6 it can be shown that:
using the trigonometric identity Template:Tmath.
This proof needs a slight modification if Template:Math. In this case, the right triangle to which the Pythagorean theorem is applied moves outside the triangle Template:Math. The only effect this has on the calculation is that the quantity Template:Math is replaced by Template:Math As this quantity enters the calculation only through its square, the rest of the proof is unaffected. However, this problem only occurs when Template:Math is obtuse, and may be avoided by reflecting the triangle about the bisector of Template:Math.
Referring to Fig. 6 it is worth noting that if the angle opposite side Template:Math is Template:Math then:
This is useful for direct calculation of a second angle when two sides and an included angle are given.
From three altitudes

The altitude through vertex Template:Mvar is a segment perpendicular to side Template:Mvar. The distance from the foot of the altitude to vertex Template:Mvar plus the distance from the foot of the altitude to vertex Template:Mvar is equal to the length of side Template:Mvar (see Fig. 5). Each of these distances can be written as one of the other sides multiplied by the cosine of the adjacent angle,[12]
(This is still true if Template:Math or Template:Math is obtuse, in which case the perpendicular falls outside the triangle.) Multiplying both sides by Template:Math yields
The same steps work just as well when treating either of the other sides as the base of the triangle:
Taking the equation for Template:Tmath and subtracting the equations for Template:Tmath and Template:Tmath,
This proof is independent of the Pythagorean theorem, insofar as it is based only on the right-triangle definition of cosine and obtains squared side lengths algebraically. Other proofs typically invoke the Pythagorean theorem explicitly, and are more geometric, treating Template:Math as a label for the length of a certain line segment.[12]
Unlike many proofs, this one handles the cases of obtuse and acute angles Template:Math in a unified fashion.
Cartesian coordinates

Consider a triangle with sides of length Template:Math, Template:Math, Template:Math, where Template:Math is the measurement of the angle opposite the side of length Template:Math. This triangle can be placed on the Cartesian coordinate system with side Template:Math aligned along the x axis and angle Template:Math placed at the origin, by plotting the components of the 3 points of the triangle as shown in Fig. 4:
By the distance formula,[13]
Squaring both sides and simplifying
An advantage of this proof is that it does not require the consideration of separate cases depending on whether the angle Template:Mvar is acute, right, or obtuse. However, the cases treated separately in Elements II.12–13 and later by al-Ṭūsī, al-Kāshī, and others could themselves be combined by using concepts of signed lengths and areas and a concept of signed cosine, without needing a full Cartesian coordinate system.
Using Ptolemy's theorem

Referring to the diagram, triangle ABC with sides Template:Math = Template:Math, Template:Math = Template:Math and Template:Math = Template:Math is drawn inside its circumcircle as shown. Triangle Template:Math is constructed congruent to triangle Template:Math with Template:Math = Template:Math and Template:Math = Template:Math. Perpendiculars from Template:Math and Template:Math meet base Template:Math at Template:Math and Template:Math respectively. Then:
Now the law of cosines is rendered by a straightforward application of Ptolemy's theorem to cyclic quadrilateral Template:Math:
Plainly if angle Template:Math is right, then Template:Math is a rectangle and application of Ptolemy's theorem yields the Pythagorean theorem:
By comparing areas


One can also prove the law of cosines by calculating areas. The change of sign as the angle Template:Math becomes obtuse makes a case distinction necessary.
Recall that
- Template:Math, Template:Math, and Template:Math are the areas of the squares with sides Template:Math, Template:Math, and Template:Math, respectively;
- if Template:Math is acute, then Template:Math is the area of the parallelogram with sides Template:Math and Template:Math forming an angle of Template:Math;
- if Template:Math is obtuse, and so Template:Math is negative, then Template:Math is the area of the parallelogram with sides a and b forming an angle of Template:Math.
Acute case. Figure 7a shows a heptagon cut into smaller pieces (in two different ways) to yield a proof of the law of cosines. The various pieces are
- in pink, the areas Template:Math, Template:Math on the left and the areas Template:Math and Template:Math on the right;
- in blue, the triangle Template:Math, on the left and on the right;
- in grey, auxiliary triangles, all congruent to Template:Math, an equal number (namely 2) both on the left and on the right.
The equality of areas on the left and on the right gives
Obtuse case. Figure 7b cuts a hexagon in two different ways into smaller pieces, yielding a proof of the law of cosines in the case that the angle Template:Math is obtuse. We have
- in pink, the areas Template:Math, Template:Math, and Template:Math on the left and Template:Math on the right;
- in blue, the triangle Template:Math twice, on the left, as well as on the right.
The equality of areas on the left and on the right gives
The rigorous proof will have to include proofs that various shapes are congruent and therefore have equal area. This will use the theory of congruent triangles. Template:Clear
Using circle geometry



Using the geometry of the circle, it is possible to give a more geometric proof than using the Pythagorean theorem alone. Algebraic manipulations (in particular the binomial theorem) are avoided.
Case of acute angle Template:Math, where Template:Math. Drop the perpendicular from Template:Math onto Template:Math = Template:Math, creating a line segment of length Template:Math. Duplicate the right triangle to form the isosceles triangle Template:Math. Construct the circle with center Template:Math and radius Template:Math, and its tangent Template:Math through Template:Math. The tangent Template:Math forms a right angle with the radius Template:Math (Euclid's Elements: Book 3, Proposition 18; or see here), so the yellow triangle in Figure 8 is right. Apply the Pythagorean theorem to obtain
Then use the tangent secant theorem (Euclid's Elements: Book 3, Proposition 36), which says that the square on the tangent through a point Template:Math outside the circle is equal to the product of the two lines segments (from Template:Math) created by any secant of the circle through Template:Math. In the present case: Template:Math, or
Substituting into the previous equation gives the law of cosines:
Note that Template:Math is the power of the point Template:Math with respect to the circle. The use of the Pythagorean theorem and the tangent secant theorem can be replaced by a single application of the power of a point theorem.
Case of acute angle Template:Math, where Template:Math. Drop the perpendicular from Template:Math onto Template:Math = Template:Math, creating a line segment of length Template:Math. Duplicate the right triangle to form the isosceles triangle Template:Math. Construct the circle with center Template:Math and radius Template:Math, and a chord through Template:Math perpendicular to Template:Math half of which is Template:Math Apply the Pythagorean theorem to obtain
Now use the chord theorem (Euclid's Elements: Book 3, Proposition 35), which says that if two chords intersect, the product of the two line segments obtained on one chord is equal to the product of the two line segments obtained on the other chord. In the present case: Template:Math or
Substituting into the previous equation gives the law of cosines:
Note that the power of the point Template:Math with respect to the circle has the negative value Template:Math.
Case of obtuse angle Template:Math. This proof uses the power of a point theorem directly, without the auxiliary triangles obtained by constructing a tangent or a chord. Construct a circle with center Template:Math and radius Template:Math (see Figure 9), which intersects the secant through Template:Math and Template:Math in Template:Math and Template:Math. The power of the point Template:Math with respect to the circle is equal to both Template:Math and Template:Math. Therefore,
which is the law of cosines.
Using algebraic measures for line segments (allowing negative numbers as lengths of segments) the case of obtuse angle (Template:Math) and acute angle (Template:Math) can be treated simultaneously.
Using the law of sines
The law of cosines can be proven algebraically from the law of sines and a few standard trigonometric identities.[14] To start, three angles of a triangle sum to a straight angle ( radians). Thus by the angle sum identities for sine and cosine,
Squaring the first of these identities, then substituting from the second, and finally replacing the Pythagorean trigonometric identity, we have:
The law of sines holds that
so to prove the law of cosines, we multiply both sides of our previous identity by Template:Tmath:
This concludes the proof.
Using vectors

Denote
Therefore,
Taking the dot product of each side with itself:
Using the identity
leads to
The result follows.
Isosceles case
When Template:Math, i.e., when the triangle is isosceles with the two sides incident to the angle Template:Math equal, the law of cosines simplifies significantly. Namely, because Template:Math, the law of cosines becomes
or
Analogue for tetrahedra
Given an arbitrary tetrahedron whose four faces have areas Template:Mvar, Template:Mvar, Template:Mvar, and Template:Mvar, with dihedral angle Template:Tmath between faces Template:Mvar and Template:Mvar, etc., a higher-dimensional analogue of the law of cosines is:[15]
Version suited to small angles
When the angle, Template:Math, is small and the adjacent sides, Template:Math and Template:Math, are of similar length, the right hand side of the standard form of the law of cosines is subject to catastrophic cancellation in numerical approximations. In situations where this is an important concern, a mathematically equivalent version of the law of cosines, similar to the haversine formula, can prove useful:
In the limit of an infinitesimal angle, the law of cosines degenerates into the circular arc length formula, Template:Math.
In non-Euclidean geometry

As in Euclidean geometry, one can use the law of cosines to determine the angles Template:Math, Template:Math, Template:Math from the knowledge of the sides Template:Math, Template:Math, Template:Math. In contrast to Euclidean geometry, the reverse is also possible in both non-Euclidean models: the angles Template:Math, Template:Math, Template:Math determine the sides Template:Math, Template:Math, Template:Math.
A triangle is defined by three points Template:Math, Template:Math, and Template:Math on the unit sphere, and the arcs of great circles connecting those points. If these great circles make angles Template:Math, Template:Math, and Template:Math with opposite sides Template:Math, Template:Math, Template:Math then the spherical law of cosines asserts that all of the following relationships hold:
In hyperbolic geometry, a pair of equations are collectively known as the hyperbolic law of cosines. The first is
where Template:Math and Template:Math are the hyperbolic sine and cosine, and the second is
The length of the sides can be computed by:
Polyhedra
The law of cosines can be generalized to all polyhedra by considering any polyhedron with vector sides and invoking the divergence Theorem.[16]
See also
- Half-side formula
- Law of sines
- Law of tangents
- Law of cotangents
- List of trigonometric identities
- Mollweide's formula
Notes
References
External links
- Template:Springer
- Several derivations of the Cosine Law, including Euclid's at cut-the-knot
- Interactive applet of Law of Cosines
- ↑ Cite error: Invalid
<ref>tag; no text was provided for refs namedEuclid-Heath-Elements Book II Propositions - ↑ Template:Cite book
- ↑ Template:Cite journal Template:Pb Johannes de Muris credits an anonymous author for the relevant section of his work De Arte Mesurandi. See Template:Cite book
- ↑ Template:Cite book
- ↑ Template:Cite book
- ↑ Template:Cite journal
- ↑ Template:Cite book
- ↑ Template:Cite book
- ↑ Template:Cite book English translation of De triangulis omnimodis by Johann Müller, otherwise known as Regiomontanus, with facsimile of the 1533 Latin edition. Theorem I.49, Template:Pgs.
- ↑ For example in Template:Cite book
- ↑ Java applet version by Prof. D E Joyce of Clark University.
- ↑ 12.0 12.1 Alexander Bogomolny credits this proof to teacher John Molokach (2011), but it may be older. Template:Cite web
- ↑ Template:Cite book
- ↑ Template:Cite journal
- ↑ Template:Cite book
- ↑ Template:Cite journal