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
a,
b,
c,
\alpha,
\beta,
\gamma
\begin{align} c2&=a2+b2-2ab\cos\gamma,\\[3mu] a2&=b2+c2-2bc\cos\alpha,\\[3mu] b2&=a2+c2-2ac\cos\beta. \end{align}
The law of cosines generalizes the Pythagorean theorem, which holds only for right triangles: if
\gamma
\cos\gamma=0,
c2=a2+b2.
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 is small relative to and 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 . 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, only one positive solution if, and no solution if . These different cases are also explained by the side-side-angle congruence ambiguity.
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:
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.[1]
Using notation as in Fig. 2, Euclid's statement of proposition II.12 can be represented more concisely (though anachronistically) by the formula
AB2=CA2+CB2+2(CA)(CH).
To transform this into the familiar expression for the law of cosines, substitute
AB=c,
CA=b,
CB=a,
CH=a\cos(\pi-\gamma)
=-a\cos\gamma.
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).[2] 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).[3]
The 13th century Persian mathematician Naṣīr al-Dīn al-Ṭūsī, in his Arabic: Kitāb al-Shakl al-qattāʴ (Book on the Complete Quadrilateral, c. 1250), gave a method for finding the third side of a general scalene triangle given two sides and the included angle by dropping a perpendicular from the vertex of one of the unknown angles to the opposite base, reducing the problem to solving a right-angled triangle by the Pythagorean theorem. If written out using modern mathematical notation, the resulting relation can be algebraically manipulated into the modern law of cosines.[4]
About two centuries later, another Persian mathematician, Jamshīd al-Kāshī, who computed the most accurate trigonometric tables of his era, wrote about various methods of solving triangles in his Arabic: Miftāḥ al-ḥisāb (Key of Arithmetic, 1427), and repeated essentially al-Ṭūsī's method, including more explicit details, as follows:[5]
Using modern algebraic notation and conventions this might be written
c=\sqrt{(b-a\cos\gamma)2+(a\sin\gamma)2}
when
\gamma
c=\sqrt{\left(b+a\left|\cos\gamma\right|\right)2+\left(a\sin\gamma\right)2}
when
\gamma
\gamma
\cos\gamma
\cos(\pi-\gamma)=-\cos\gamma
\cos2\gamma+\sin2\gamma=1,
\begin{align} c2 &=b2-2ba\cos\gamma+a2\cos2\gamma+a2\sin2\gamma\\[5mu] &=a2+b2-2ab\cos\gamma. \end{align}
In France, the law of cosines is sometimes referred to as the théorème d'Al-Kashi.[6] [7]
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.[8]
Euclid proved this theorem by applying the Pythagorean theorem to each of the two right triangles in Fig. 2 (and). Using to denote the line segment and for the height, triangle gives us
c2=(b+d)2+h2,
and triangle gives
d2+h2=a2.
Expanding the first equation gives
c2=b2+2bd+d2+h2.
Substituting the second equation into this, the following can be obtained:
c2=a2+b2+2bd.
This is Euclid's Proposition 12 from Book 2 of the Elements.[9] To transform it into the modern form of the law of cosines, note that
d=a\cos(\pi-\gamma)=-a\cos\gamma.
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 and uses the square of a difference to simplify.
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:
\begin{align} c2&=(b-a\cos\gamma)2+(a\sin\gamma)2\\ &=b2-2ab\cos\gamma+a2\cos2\gamma+a2\sin2\gamma\\ &=b2+a2-2ab\cos\gamma, \end{align}
\cos2\gamma+\sin2\gamma=1.
This proof needs a slight modification if . In this case, the right triangle to which the Pythagorean theorem is applied moves outside the triangle . The only effect this has on the calculation is that the quantity is replaced by As this quantity enters the calculation only through its square, the rest of the proof is unaffected. However, this problem only occurs when is obtuse, and may be avoided by reflecting the triangle about the bisector of .
Referring to Fig. 6 it is worth noting that if the angle opposite side is then:
\tan\alpha=
a\sin\gamma | |
b-a\cos\gamma |
.
This is useful for direct calculation of a second angle when two sides and an included angle are given.
The altitude through vertex is a segment perpendicular to side . The distance from the foot of the altitude to vertex plus the distance from the foot of the altitude to vertex is equal to the length of side (see Fig. 5). Each of these distances can be written as one of the other sides multiplied by the cosine of the adjacent angle,[10]
c=a\cos\beta+b\cos\alpha.
(This is still true if or is obtuse, in which case the perpendicular falls outside the triangle.) Multiplying both sides by yields
c2=ac\cos\beta+bc\cos\alpha.
The same steps work just as well when treating either of the other sides as the base of the triangle:
\begin{align} a2&=ac\cos\beta+ab\cos\gamma,\\[3mu] b2&=bc\cos\alpha+ab\cos\gamma. \end{align}
Taking the equation for
c2
b2
a2,
\begin{align} c2-a2-b2&={\color{BlueGreen}\cancel{\color{Black}ac\cos\beta}}+{\color{Peach}\cancel{\color{Black}bc\cos\alpha}}-{\color{BlueGreen}\cancel{\color{Black}ac\cos\beta}}-{\color{Peach}\cancel{\color{Black}bc\cos\alpha}}-2ab\cos\gamma\\ c2&=a2+b2-2ab\cos\gamma. \end{align}
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 as a label for the length of a certain line segment.[10]
Unlike many proofs, this one handles the cases of obtuse and acute angles in a unified fashion.
Consider a triangle with sides of length,,, where is the measurement of the angle opposite the side of length . This triangle can be placed on the Cartesian coordinate system with side aligned along the x axis and angle placed at the origin, by plotting the components of the 3 points of the triangle as shown in Fig. 4:
A=(b\cos\theta,b\sin\theta),B=(a,0),andC=(0,0).
By the distance formula,[11]
c=\sqrt{(a-b\cos\theta)2+(0-b\sin\theta)2}.
Squaring both sides and simplifying
\begin{align} c2&=(a-b\cos\theta)2+(-b\sin\theta)2\\ &=a2-2ab\cos\theta+b2\cos2\theta+b2\sin2\theta\\ &=a2+b2(\sin2\theta+\cos2\theta)-2ab\cos\theta\\ &=a2+b2-2ab\cos\theta. \end{align}
An advantage of this proof is that it does not require the consideration of separate cases depending on whether the angle 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.
Referring to the diagram, triangle ABC with sides =, = and = is drawn inside its circumcircle as shown. Triangle is constructed congruent to triangle with = and = . Perpendiculars from and meet base at and respectively. Then:
\begin{align} &BF=AE=BC\cos\hat{B}=a\cos\hat{B}\\ ⇒ &DC=EF=AB-2BF=c-2a\cos\hat{B}. \end{align}
Now the law of cosines is rendered by a straightforward application of Ptolemy's theorem to cyclic quadrilateral :
\begin{align} &AD x BC+AB x DC=AC x BD\\ ⇒ &a2+c(c-2a\cos\hat{B})=b2\\ ⇒ &a2+c2-2ac\cos\hat{B}=b2. \end{align}
Plainly if angle is right, then is a rectangle and application of Ptolemy's theorem yields the Pythagorean theorem:
a2+c2=b2.
One can also prove the law of cosines by calculating areas. The change of sign as the angle becomes obtuse makes a case distinction necessary.
Recall that
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
The equality of areas on the left and on the right gives
a2+b2=c2+2ab\cos\gamma.
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 is obtuse. We have
The equality of areas on the left and on the right gives
a2+b2-2ab\cos(\gamma)=c2.
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.
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, where . Drop the perpendicular from onto =, creating a line segment of length . Duplicate the right triangle to form the isosceles triangle . Construct the circle with center and radius, and its tangent through . The tangent forms a right angle with the radius (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
c2=b2+h2.
Then use the tangent secant theorem (Euclid's Elements: Book 3, Proposition 36), which says that the square on the tangent through a point outside the circle is equal to the product of the two lines segments (from) created by any secant of the circle through . In the present case:, or
h2=a(a-2b\cos\gamma).
Substituting into the previous equation gives the law of cosines:
c2=b2+a(a-2b\cos\gamma).
Note that is the power of the point 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, where . Drop the perpendicular from onto =, creating a line segment of length . Duplicate the right triangle to form the isosceles triangle . Construct the circle with center and radius, and a chord through perpendicular to half of which is Apply the Pythagorean theorem to obtain
b2=c2+h2.
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: or
h2=a(2b\cos\gamma-a).
Substituting into the previous equation gives the law of cosines:
b2=c2+a(2b\cos\gamma-a).
Note that the power of the point with respect to the circle has the negative value .
Case of obtuse angle . 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 and radius (see Figure 9), which intersects the secant through and in and . The power of the point with respect to the circle is equal to both and . Therefore,
\begin{align} c2-a2&{}=b(b+2a\cos(\pi-\gamma))\\ &{}=b(b-2a\cos\gamma), \end{align}
which is the law of cosines.
Using algebraic measures for line segments (allowing negative numbers as lengths of segments) the case of obtuse angle and acute angle can be treated simultaneously.
The law of cosines can be proven algebraically from the law of sines and a few standard trigonometric identities.[12] To start, three angles of a triangle sum to a straight angle (
\alpha+\beta+\gamma=\pi
\begin{alignat}{3} \sin\gamma&=\phantom{-}\sin(\pi-\gamma) &&=\phantom{-}\sin(\alpha+\beta) &&=\sin\alpha\cos\beta+\cos\alpha\sin\beta,\\[5mu] \cos\gamma&=-\cos(\pi-\gamma) &&=-\cos(\alpha+\beta) &&=\sin\alpha\sin\beta-\cos\alpha\cos\beta. \end{alignat}
Squaring the first of these identities, then substituting
\cos\alpha\cos\beta={}
\sin\alpha\sin\beta-\cos\gamma
\cos2\alpha+\sin2\alpha={}
\cos2\beta+\sin2\beta=1,
\begin{align} \sin2\gamma &=(\sin\alpha\cos\beta+\cos\alpha\sin\beta)2\\[3mu] &=\sin2\alpha\cos2\beta+2\sin\alpha\sin\beta\cos\alpha\cos\beta+\cos2\alpha\sin2\beta\\[3mu] &=\sin2\alpha\cos2\beta+2\sin\alpha\sin\beta(\sin\alpha\sin\beta-\cos\gamma)+\cos2\alpha\sin2\beta\\[3mu] &=\sin2\alpha(\cos2\beta+\sin2\beta)+\sin2\beta(\cos2\alpha+\sin2\alpha)-2\sin\alpha\sin\beta\cos\gamma\\[3mu] &=\sin2\alpha+\sin2\beta-2\sin\alpha\sin\beta\cos\gamma. \end{align}
The law of sines holds that
a | |
\sin\alpha\vphantom{\beta |
so to prove the law of cosines, we multiply both sides of our previous identity by
k2\colon
\begin{align} \sin2\gamma
c2 | |
\sin2\gamma |
&=\sin2\alpha
a2 | |
\sin2\alpha |
+\sin2\beta
b2 | |
\sin2\beta |
-2\sin\alpha\sin\beta\cos\gamma
ab | |
\sin\alpha\sin\beta\vphantom{\sin2 |
This concludes the proof.
Denote
\overrightarrow{CB}=\vec{a}, \overrightarrow{CA}=\vec{b}, \overrightarrow{AB}=\vec{c}
Therefore,
\vec{c}=\vec{a}-\vec{b}
Taking the dot product of each side with itself:
\vec{c} ⋅ \vec{c}=(\vec{a}-\vec{b}) ⋅ (\vec{a}-\vec{b})
\Vert\vec{c}\Vert2=\Vert\vec{a}\Vert2+\Vert\vec{b}\Vert2-2\vec{a} ⋅ \vec{b}
Using the identity
\vec{u} ⋅ \vec{v}=\Vert\vec{u}\Vert\Vert\vec{v}\Vert\cos\angle(\vec{u}, \vec{v})
leads to
\Vert\vec{c}\Vert2=\Vert\vec{a}\Vert2+{\Vert\vec{b}\Vert}2-2\Vert\vec{a}\Vert \Vert\vec{b}\Vert\cos\angle(\vec{a}, \vec{b})
The result follows.
When, i.e., when the triangle is isosceles with the two sides incident to the angle equal, the law of cosines simplifies significantly. Namely, because, the law of cosines becomes
\cos\gamma=1-
c2 | |
2a2 |
or
c2=2a2(1-\cos\gamma).
\varphiab
A2=B2+C2+D2-2\left(BC\cos\varphibc+CD\cos\varphicd+DB\cos\varphidb\right).
When the angle,, is small and the adjacent sides, and, 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:
\begin{align} c2&=(a-b)2+
| ||||
4ab\sin |
\right)\\ &=(a-b)2+4ab\operatorname{haversin}(\gamma). \end{align}
See main article: article, Spherical law of cosines and Hyperbolic law of cosines. Versions similar to the law of cosines for the Euclidean plane also hold on a unit sphere and in a hyperbolic plane. In spherical geometry, a triangle is defined by three points,, and on the unit sphere, and the arcs of great circles connecting those points. If these great circles make angles,, and with opposite sides,, then the spherical law of cosines asserts that both of the following relationships hold:
\begin{align} \cosa&=\cosb\cosc+\sinb\sinc\cosA\\ \cosA&=-\cosB\cosC+\sinB\sinC\cosa. \end{align}
In hyperbolic geometry, a pair of equations are collectively known as the hyperbolic law of cosines. The first is
\cosha=\coshb\coshc-\sinhb\sinhc\cosA
where and are the hyperbolic sine and cosine, and the second is
\cosA=-\cosB\cosC+\sinB\sinC\cosha.
As in Euclidean geometry, one can use the law of cosines to determine the angles,, from the knowledge of the sides,, . In contrast to Euclidean geometry, the reverse is also possible in both non-Euclidean models: the angles,, determine the sides,, .
The Law of Cosines can be generalized to all polyhedra by considering any polyhedron with vector sides and invoking the Divergence Theorem.[14]