Skip to main content

The law of cosines and the angle-addition formulas

Two formulas from two pictures. Put one corner of a triangle at the origin and the distance formula gives the law of cosines; stand one right triangle on another and reading one corner two ways gives the sine and the cosine of a sum of two angles.
M01.5.4L0 Foundation25 minIn review

Before this lesson

M01.5.2 The unit circle and polar coordinates M01.5.3 Radians and sine waves

After this lesson you can

  • Derive the law of cosines from the distance formula with one corner of the triangle at the origin, and use it to find a missing side or a missing angle.
  • Explain why Pythagoras’ theorem is the case of a right angle, and how the sign of the cosine makes the third side shorter or longer.
  • Derive the angle-addition formulas for sine and cosine from the picture of one right triangle standing on another.
  • Find exact values such as sin 75° from the formulas, and check both formulas over a grid of angles in Python.

In review. The maths and code on this page are checked by automated tests on every change, but an independent reader has not signed it off yet. Spot a mistake or a confusing step? Tell us.

The question

Two sides of a triangle are 8 and 5 long, with an angle of \(60^\circ\) between them. How long is the third side? Pythagoras answers only when the angle is \(90^\circ\). And if you know the sine and cosine of \(45^\circ\) and of \(30^\circ\) exactly, can you find \(\sin 75^\circ\) exactly, with no calculator? Each question has a one-picture answer, and both answers return in machine learning: the first is behind the angle between two vectors, the second behind the position codes of the original transformer.

From the last lesson

1. Convert \(60^\circ\) to radians.

Show answer

\({60 \times \pi/180}\), which is \({\pi/3}\), about \(1.0472\).

2. What is the period of the wave \({y = 3\sin(2\pi t / 5)}\)?

Show answer

5: when \(t\) grows by 5, the angle grows by \(2\pi\), one full turn.

Intuition

A triangle with no right angle has no hypotenuse, so the ratios of M01.5.1 cannot be used on it directly. The trick is to put it on the coordinate plane in the most convenient place: the corner with the known angle \(C\) at the origin, and one of its two sides along the \(x\)-axis.

A triangle on the coordinate plane. Its corner with the blue angle C is at the origin (0, 0). The blue side a runs along the x-axis to the corner (a, 0), and the blue side b rises at the angle C to the corner (b cosine C, b sine C). The vermillion side c joins those two corners. A green dashed line drops from the top corner to the x-axis, labelled b sine C, with a right angle at its foot. Under the axis, measuring lines mark b cosine C in sky blue from the origin to the foot, and a minus b cosine C in green from the foot to (a, 0). Top right: c squared equals a minus b cosine C, squared, plus b sine C, squared, which equals a squared plus b squared minus 2 a b cosine C. Bottom right: a equals 8, b equals 5, C equals 60 degrees gives c equals 7.
M01.5.4-F1

With the angle \(C\) at the origin, the far corner of the side \(b\) is \({(b\cos C, b\sin C)}\), and the third side \(c\) is a distance between two known points.

Then every corner has known coordinates. The side \(a\) ends at \({(a, 0)}\). The side \(b\) leaves the origin at the angle \(C\), so by the polar coordinates of M01.5.2 its far end is \({(b\cos C, b\sin C)}\). The third side, \(c\), joins two points whose coordinates we know, and the distance formula (M01.2.3) measures it.

Build it up

Step 1. The two changes. From \({(b\cos C, b\sin C)}\) to \({(a, 0)}\), the horizontal change is \({a - b\cos C}\) and the vertical change is \({0 - b\sin C}\). These are the two green sides in the picture.

Step 2. The distance formula. The third side is the hypotenuse of the right triangle made by those two changes (the square of \({-b\sin C}\) is the square of \(b\sin C\), since squaring removes the sign):

\[ c^2 = (a - b\cos C)^2 + (b\sin C)^2 . \]

Step 3. Multiply out. Lesson M01.1.2 expanded the square of a sum, \({(x + z)^2 = x^2 + 2xz + z^2}\). Put \({z = -y}\): since \({(-y)^2 = y^2}\), the square of a difference is \({(x - y)^2 = x^2 - 2xy + y^2}\). Here \({x = a}\) and \({y = b\cos C}\):

\[ \begin{aligned} (a - b\cos C)^2 &= a^2 - 2ab\cos C \\ &\quad + b^2\cos^2 C . \end{aligned} \]

Step 4. Collect, and use the circle. Add \(b^2\sin^2 C\) and take out the common factor \(b^2\) from the two terms that contain it. What is left in the bracket is 1, by M01.5.2:

\[ \begin{aligned} c^2 &= a^2 - 2ab\cos C \\ &\quad + b^2(\cos^2 C + \sin^2 C) \\ &= a^2 + b^2 - 2ab\cos C . \end{aligned} \]

That is the law of cosines. For the hook’s triangle, \({\cos 60^\circ = \tfrac12}\), so

\[ \begin{aligned} c^2 &= 64 + 25 - 2 \times 8 \times 5 \times \tfrac12 \\ &= 89 - 40 = 49 , \end{aligned} \]

and the third side is 7.

Step 5. Pythagoras is the right-angle case. At \({C = 90^\circ}\) the cosine is 0, the last term vanishes and \({c^2 = a^2 + b^2}\). For a smaller angle the cosine is positive, the term takes something away, and the third side is shorter than Pythagoras would say; for a wider angle the cosine is negative, the term adds, and the third side is longer.

Two blue sides from the corner C: side a of length 8 along the horizontal axis to B, and three copies of side b of length 5 rising at 60, 90 and 120 degrees, ending on a dashed circle of radius 5. Three vermillion sides c join each end to B, labelled C equals 60 degrees: c equals 7; C equals 90 degrees: c about 9.43; and C equals 120 degrees: c about 11.36. A note reads dashed: where b can reach.
M01.5.4-F2

Two sides fixed at 8 and 5. As the angle \(C\) opens, the third side grows: 7 at \(60^\circ\), \({\sqrt{89} \approx 9.43}\) at \(90^\circ\) (Pythagoras) and \({\sqrt{129} \approx 11.36}\) at \(120^\circ\).

The formal statement

NoteThe law of cosines

In any triangle with sides \(a\) and \(b\) and the angle \(C\) between them, the third side \(c\) (the side across from \(C\)) satisfies

\[ \cmodel{c}^2 = \cdata{a}^2 + \cdata{b}^2 - 2\cdata{a}\cdata{b}\cos \cdata{C} . \]

Run backwards, it gives an angle from three sides. Solve for \(\cos C\):

\[ \cos C = \frac{a^2 + b^2 - c^2}{2ab} . \]

For sides 8, 5 and 7, the fraction is \({40/80}\), which is \(\tfrac12\), and \(\operatorname{acos}\) gives \({C = 60^\circ}\), as it should. Lesson M02.3.1 builds the angle formula of the dot product on this law.

NoteThe angle-addition formulas

For any two angles \(\alpha\) and \(\beta\),

\[ \begin{aligned} \sin(\alpha + \beta) &= \sin\alpha\cos\beta \\ &\quad + \cos\alpha\sin\beta, \\[0.4em] \cos(\alpha + \beta) &= \cos\alpha\cos\beta \\ &\quad - \sin\alpha\sin\beta . \end{aligned} \]

The picture. Take \(\alpha\) and \(\beta\) positive with \({\alpha + \beta}\) below \(90^\circ\). Draw the ray from the origin \(O\) at the angle \(\alpha\). On it, stand a right triangle \(OQP\) with the angle \(\beta\) at \(O\), its right angle at \(Q\) and its hypotenuse \(OP\) of length 1. Then \(P\) is 1 from the origin at the angle \({\alpha + \beta}\), so by M01.5.2

\[ P = \big(\cos(\alpha + \beta),\ \sin(\alpha + \beta)\big). \]

The angle-addition picture. From the origin O, a black side OQ of length cosine beta rises at the blue angle alpha. A right triangle OQP stands on it, with the blue angle beta at O, a right angle at Q, the side QP of length sine beta and the hypotenuse OP of length 1. Under Q, the point R on the axis makes a right triangle ORQ with a sky-blue bottom side cosine alpha cosine beta and a vermillion upright side sine alpha cosine beta. A small right triangle QTP has a sky-blue level side QT of length sine alpha sine beta, a vermillion upright side TP of length cosine alpha sine beta and the blue angle alpha at P. P is labelled (cosine of alpha plus beta, sine of alpha plus beta). Beside the picture: height of P, sine alpha cosine beta plus cosine alpha sine beta, equals sine of alpha plus beta; width of P, cosine alpha cosine beta minus sine alpha sine beta, equals cosine of alpha plus beta.
M01.5.4-F3

One right triangle standing on another. The height of \(P\) is the sum of the two vermillion pieces, and its width is the sky-blue bottom side minus the sky-blue level side.

Now find the same point a second way, one triangle at a time.

The triangle \(OQP\). Its hypotenuse is 1 and its angle at \(O\) is \(\beta\), so \({OQ = \cos\beta}\) and \({QP = \sin\beta}\).

The triangle \(ORQ\), with \(R\) on the axis straight below \(Q\). Its hypotenuse is \(OQ\), which is \(\cos\beta\), and its angle at \(O\) is \(\alpha\). A hypotenuse of \(\cos\beta\) instead of 1 scales every side by \(\cos\beta\), so

\[ \begin{aligned} OR &= \cos\alpha\cos\beta, \\ RQ &= \sin\alpha\cos\beta . \end{aligned} \]

The triangle \(QTP\), with \(T\) level with \(Q\) and straight below \(P\). Its angle at \(P\) is \(\alpha\) too. The level line \(QT\) is parallel to the \(x\)-axis, and the side \(OQ\) crosses both. Where a line crosses two parallel lines, the alternate angles, in the shape of a Z, are equal (M01.2.2), so the angle between \(QO\) and \(QT\) is \(\alpha\), the same as the angle between \(OQ\) and the axis. The angle \(OQP\) is a right angle and \(QT\) lies inside it, so the angle \(TQP\) is \({90^\circ - \alpha}\). The angles of \(QTP\) add to \(180^\circ\), so its angle at \(P\) is

\[ 180^\circ - 90^\circ - (90^\circ - \alpha) = \alpha . \]

Its hypotenuse is \(QP\), which is \(\sin\beta\). The side \(TP\) touches the angle \(\alpha\) and the side \(QT\) lies across from it, so they are the hypotenuse times \(\cos\alpha\) and times \(\sin\alpha\):

\[ \begin{aligned} TP &= \cos\alpha\sin\beta, \\ QT &= \sin\alpha\sin\beta . \end{aligned} \]

Read the height of \(P\) two ways. Climbing from the axis to \(P\) means climbing \(RQ\) and then \(TP\):

\[ \begin{aligned} \sin(\alpha + \beta) &= RQ + TP \\ &= \sin\alpha\cos\beta \\ &\quad + \cos\alpha\sin\beta . \end{aligned} \]

Read the width of \(P\) two ways. Going along to \(R\) and then back by \(QT\) lands straight below \(P\):

\[ \begin{aligned} \cos(\alpha + \beta) &= OR - QT \\ &= \cos\alpha\cos\beta \\ &\quad - \sin\alpha\sin\beta . \end{aligned} \]

The picture needs \(\alpha\) and \(\beta\) positive with a sum below \(90^\circ\), so that every side has a positive length. The formulas hold for every pair of angles, positive or negative, large or small; the code below checks 2,401 pairs of them, and lesson M01.9.3 proves it with complex numbers.

Frontier note: angle addition inside a transformer

The original transformer (DL05.3) gives position \(p\) a list of numbers that includes pairs \(\sin(\omega p)\) and \(\cos(\omega p)\) for many rates \(\omega\) (Greek omega). Move \(k\) places on and the angle-addition formulas give

\[ \begin{aligned} &\sin(\omega(p + k)) \\ &\quad = \cos(\omega k)\sin(\omega p) \\ &\qquad + \sin(\omega k)\cos(\omega p). \end{aligned} \]

The two weights depend only on the offset \(k\), not on the position \(p\). So the code for position \({p + k}\) is a fixed mix of the code for position \(p\). The paper’s authors chose sines and cosines because they expected this to make it easy for a model to learn to attend to words by how far apart they are. The same formulas are how M04.3.2 finds the slope of a sine wave.

Worked example

Find \(\sin 75^\circ\) and \(\cos 75^\circ\) exactly.

Write \(75^\circ\) as \({45^\circ + 30^\circ}\), two angles whose sines and cosines M01.5.1 found exactly: \(\sin 45^\circ\) and \(\cos 45^\circ\) are both \({\sqrt{2}/2}\), while \(\sin 30^\circ\) is \(\tfrac12\) and \(\cos 30^\circ\) is \({\sqrt{3}/2}\).

\[ \begin{aligned} \sin 75^\circ &= \sin 45^\circ\cos 30^\circ \\ &\quad + \cos 45^\circ\sin 30^\circ \\ &= \tfrac{\sqrt{2}}{2}\cdot\tfrac{\sqrt{3}}{2} + \tfrac{\sqrt{2}}{2}\cdot\tfrac{1}{2} \\ &= \tfrac{\sqrt{6}}{4} + \tfrac{\sqrt{2}}{4} \\ &= \tfrac{\sqrt{6} + \sqrt{2}}{4} \approx 0.9659 . \end{aligned} \]

The cosine has a minus sign in the middle:

\[ \begin{aligned} \cos 75^\circ &= \cos 45^\circ\cos 30^\circ \\ &\quad - \sin 45^\circ\sin 30^\circ \\ &= \tfrac{\sqrt{2}}{2}\cdot\tfrac{\sqrt{3}}{2} - \tfrac{\sqrt{2}}{2}\cdot\tfrac{1}{2} \\ &= \tfrac{\sqrt{6}}{4} - \tfrac{\sqrt{2}}{4} \\ &= \tfrac{\sqrt{6} - \sqrt{2}}{4} \approx 0.2588 . \end{aligned} \]

The angle-addition picture with alpha equal to 45 degrees and beta equal to 30 degrees, every length written as a number: the bottom side 0.6124 in sky blue, the upright side under Q 0.6124 in vermillion, the level side 0.3536 in sky blue, the upright side under P 0.3536 in vermillion, the side OQ 0.8660, the side QP 0.5 and the hypotenuse 1. P is labelled (cosine 75 degrees, sine 75 degrees). Beside it: height of P, root 6 over 4 plus root 2 over 4, equals sine 75 degrees, about 0.9659; width of P, root 6 over 4 minus root 2 over 4, equals cosine 75 degrees, about 0.2588.
M01.5.4-F4

The same picture with \(45^\circ\) and \(30^\circ\). The two heights, \({\sqrt{6}/4}\) and \({\sqrt{2}/4}\), add to \(\sin 75^\circ\), and the two widths subtract to \(\cos 75^\circ\).

Check with the circle: the squares should add to 1. Multiplying out, \({(\sqrt{6} + \sqrt{2})^2}\) is \({8 + 2\sqrt{12}}\) and \({(\sqrt{6} - \sqrt{2})^2}\) is \({8 - 2\sqrt{12}}\), so

\[ \sin^2 75^\circ + \cos^2 75^\circ = \frac{16}{16} = 1 . \]

Code

The law of cosines from scratch, checked against the coordinates of the picture:

import math

def third_side(a, b, angle_degrees):
    """The side across from the angle C, from the two sides a and b around it."""
    C = math.radians(angle_degrees)
    return math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(C))

for angle in [60, 90, 120]:
    print(angle, "degrees: third side", round(third_side(8, 5, angle), 4))

corner = (5 * math.cos(math.radians(60)), 5 * math.sin(math.radians(60)))   # (b cos C, b sin C)
print("distance from the coordinates:", round(math.dist(corner, (8, 0)), 4))

cos_C = (8 ** 2 + 5 ** 2 - 7 ** 2) / (2 * 8 * 5)    # the angle from three sides
print("angle across from 7:", round(math.degrees(math.acos(cos_C)), 2), "degrees")
60 degrees: third side 7.0
90 degrees: third side 9.434
120 degrees: third side 11.3578
distance from the coordinates: 7.0
angle across from 7: 60.0 degrees

Now both angle-addition formulas against Python’s own sine and cosine, on every pair of angles from \({-360^\circ}\) to \(360^\circ\) in steps of \(15^\circ\): far outside the picture’s limit of \(90^\circ\). The values are floats, so they are compared with math.isclose and a small absolute tolerance, which also covers answers that should be exactly 0.

checked, failed = 0, 0
for alpha_deg in range(-360, 361, 15):
    for beta_deg in range(-360, 361, 15):
        a, b = math.radians(alpha_deg), math.radians(beta_deg)
        sin_sum = math.sin(a) * math.cos(b) + math.cos(a) * math.sin(b)
        cos_sum = math.cos(a) * math.cos(b) - math.sin(a) * math.sin(b)
        checked += 1
        if not (math.isclose(sin_sum, math.sin(a + b), abs_tol=1e-12)
                and math.isclose(cos_sum, math.cos(a + b), abs_tol=1e-12)):
            failed += 1
print("pairs checked:", checked, " pairs that failed:", failed)

exact = (math.sqrt(6) + math.sqrt(2)) / 4
print("sin 75 degrees:", round(exact, 4), "from the formula,", round(math.sin(math.radians(75)), 4), "from Python")
pairs checked: 2401  pairs that failed: 0
sin 75 degrees: 0.9659 from the formula, 0.9659 from Python

A grid of 2,401 agreeing pairs is strong evidence, not a proof (lesson M01.6.3 shows why no number of examples can be): the proof for every angle comes in M01.9.3. Finally the NumPy version, one line per formula on a whole array of angles, and the shifted wave of the frontier box as a fixed mix of two waves:

import numpy as np

alpha = np.linspace(-2 * np.pi, 2 * np.pi, 101)     # 101 angles, in radians
beta = 1.1
print(np.allclose(np.sin(alpha + beta), np.sin(alpha) * np.cos(beta) + np.cos(alpha) * np.sin(beta)))
print(np.allclose(np.cos(alpha + beta), np.cos(alpha) * np.cos(beta) - np.sin(alpha) * np.sin(beta)))

phi = 0.7                                           # a shift: sin(theta + phi) mixes sin and cos
print(np.allclose(np.sin(alpha + phi), np.cos(phi) * np.sin(alpha) + np.sin(phi) * np.cos(alpha)))
True
True
True

Explore

Open the unit-circle explorer in lesson M01.5.2, press Start again and then Step +15° five times, to \(75^\circ\). The read-out gives the height as \(0.97\) and the width as \(0.26\): the values of \(\sin 75^\circ\) and \(\cos 75^\circ\) found above, rounded to two places. Two more steps reach \(105^\circ\), the mirror image of \(75^\circ\): the same height, and a negative width (Exercise 2).

Pitfalls

Two quarter circles of radius 1 with a dashed line at height 1 labelled the top of the circle. Left, marked with a cross and titled Add the sines: the points at 30 and 60 degrees with vermillion heights 0.5 and 0.866, and a reddish-purple bar stacking the two heights to 1.366, well above the dashed line; the label reads sine 30 degrees plus sine 60 degrees. Right, marked with a tick and titled Add the angles first: a vermillion height of 1 up to the top of the circle, with the label sine of 30 degrees plus 60 degrees equals sine 90 degrees equals 1.
M01.5.4-F5

Wrong beside right. Adding the two sines stacks two heights to \(1.366\), higher than any point of the unit circle. The sine of the sum is the height at \(90^\circ\), which is 1.

“\({\sin(\alpha + \beta) = \sin\alpha + \sin\beta}\).”

The sine is not a number that multiplies the bracket; it is a function, and functions rarely split over a sum. With \(30^\circ\) and \(60^\circ\) the false rule gives \(1.366\), a height that no point of the unit circle can reach, while \(\sin 90^\circ\) is 1. With \(45^\circ\) twice it gives about \(1.4142\) for \(\sin 90^\circ\). Use the formula, with its two products.

“Any angle of the triangle will do in the law of cosines.”

The angle must be the one between the sides \(a\) and \(b\), across from the side \(c\) you want. Mind the minus sign too: with a plus sign, the triangle with sides 8 and 5 at \(60^\circ\) gets \({\sqrt{129} \approx 11.36}\), the third side of the \(120^\circ\) triangle, instead of 7.

“The picture proves the formulas for every angle.”

It proves them for positive angles with a sum below \(90^\circ\), where all its sides have positive lengths. The numerical check makes the general case very believable, and lesson M01.9.3 proves it, but a picture of one case and a table of examples are not a proof of every case (more on this in M01.6.3).

Check yourself

Recall

1. State the law of cosines, and say which angle it uses.

Show answer

\({c^2 = a^2 + b^2 - 2ab\cos C}\), where \(C\) is the angle between the sides \(a\) and \(b\), across from the side \(c\).

2. What does the law of cosines become when that angle is \(90^\circ\), and why?

Show answer

Pythagoras’ theorem, \({c^2 = a^2 + b^2}\), because \(\cos 90^\circ\) is 0 and the last term vanishes.

3. State the angle-addition formulas for sine and cosine.

Show answer

\[ \begin{aligned} \sin(\alpha + \beta) &= \sin\alpha\cos\beta \\ &\quad + \cos\alpha\sin\beta, \\[0.3em] \cos(\alpha + \beta) &= \cos\alpha\cos\beta \\ &\quad - \sin\alpha\sin\beta . \end{aligned} \]

4. What is \(\sin 75^\circ\) exactly, and about how much is it?

Show answer

\({(\sqrt{6} + \sqrt{2})/4}\), about \(0.9659\), from \({\sin(45^\circ + 30^\circ)}\).

5. Why can \({\sin(30^\circ + 60^\circ)}\) not be \({\sin 30^\circ + \sin 60^\circ}\)?

Show answer

The sum of the sines is about \(1.366\), but a sine is the height of a point on the unit circle and is never more than 1. In fact \(\sin 90^\circ\) is exactly 1.

Exercises

1. ★ Two sides of a triangle are 3 and 5, with \(120^\circ\) between them. Find the third side.

Show solution

\(\cos 120^\circ\) is \({-\tfrac12}\) (the point at \(120^\circ\) mirrors the point at \(60^\circ\) in the vertical axis), so

\[ \begin{aligned} c^2 &= 9 + 25 - 2 \times 3 \times 5 \times \left(-\tfrac12\right) \\ &= 34 + 15 = 49 , \end{aligned} \]

and the third side is 7. The wide angle makes it longer than \({\sqrt{34} \approx 5.83}\), the right-angle answer.

2. ★★ Find \(\sin 105^\circ\) and \(\cos 105^\circ\) exactly, from \({105^\circ = 60^\circ + 45^\circ}\). Explain the signs.

Show solution

\[ \begin{aligned} \sin 105^\circ &= \sin 60^\circ\cos 45^\circ \\ &\quad + \cos 60^\circ\sin 45^\circ \\ &= \tfrac{\sqrt{3}}{2}\cdot\tfrac{\sqrt{2}}{2} + \tfrac{1}{2}\cdot\tfrac{\sqrt{2}}{2} \\ &= \tfrac{\sqrt{6}}{4} + \tfrac{\sqrt{2}}{4} \\ &= \tfrac{\sqrt{6} + \sqrt{2}}{4} \approx 0.9659, \end{aligned} \]

\[ \begin{aligned} \cos 105^\circ &= \cos 60^\circ\cos 45^\circ \\ &\quad - \sin 60^\circ\sin 45^\circ \\ &= \tfrac{1}{2}\cdot\tfrac{\sqrt{2}}{2} - \tfrac{\sqrt{3}}{2}\cdot\tfrac{\sqrt{2}}{2} \\ &= \tfrac{\sqrt{2}}{4} - \tfrac{\sqrt{6}}{4} \\ &= \tfrac{\sqrt{2} - \sqrt{6}}{4} \approx -0.2588 . \end{aligned} \]

The point at \(105^\circ\) is in the second quarter, where the cosine is negative and the sine positive. It is the mirror image of the point at \(75^\circ\) in the vertical axis, so it has the same height as \(75^\circ\) and the opposite width, which is exactly what the numbers show.

3. ★★★ (a) A triangle has sides 7, 8 and 13. Find its largest angle. (b) Show that in every triangle the third side \(c\) lies between the difference and the sum of \(a\) and \(b\).

Show solution

(a) The largest angle is across from the longest side, 13. With the law of cosines run backwards,

\[ \begin{aligned} \cos C &= \frac{49 + 64 - 169}{2 \times 7 \times 8} \\ &= \frac{-56}{112} = -\tfrac12 , \end{aligned} \]

so \({C = 120^\circ}\).

(b) In a triangle, \(C\) is more than \(0^\circ\) and less than \(180^\circ\), so \(\cos C\) is more than \({-1}\) and less than \(1\). Then \({-2ab\cos C}\) is more than \({-2ab}\) and less than \(2ab\), so

\[ \begin{aligned} c^2 &> a^2 + b^2 - 2ab = (a - b)^2, \\ c^2 &< a^2 + b^2 + 2ab = (a + b)^2 . \end{aligned} \]

All three lengths are positive, so \(c\) is more than the gap between \(a\) and \(b\) and less than their sum: a side can never be longer than the other two together.

Summary card

Two pictures, two formulas.

The anchor figure again: a triangle with the angle C at the origin, sides a along the axis and b to the point (b cosine C, b sine C), and the third side c found by the distance formula.
M01.5.4-F1

Put the angle at the origin.

\[ c^2 = a^2 + b^2 - 2ab\cos C \]

\[ \begin{aligned} \sin(\alpha + \beta) &= \sin\alpha\cos\beta \\ &\quad + \cos\alpha\sin\beta \\[0.3em] \cos(\alpha + \beta) &= \cos\alpha\cos\beta \\ &\quad - \sin\alpha\sin\beta \end{aligned} \]

  • In the law of cosines, \(C\) is the angle between \(a\) and \(b\); at \(90^\circ\) the law is Pythagoras.
  • Run backwards, it gives an angle from three sides.
  • With \(45^\circ\) and \(30^\circ\): \(\sin 75^\circ\) is \({(\sqrt{6} + \sqrt{2})/4}\), about \(0.9659\). Never add the sines of two angles.

Sources and next steps

Sources. Each was opened and checked against this lesson on 12 November 2026.

  • Jay Abramson and others, Algebra and Trigonometry 2e, Section 10.2 Non-right Triangles: Law of Cosines, OpenStax. States \({c^2 = a^2 + b^2 - 2ab\cos\gamma}\) with \(\gamma\) the angle across from \(c\), and derives it by placing a corner at the origin, so that the far corner is \({(b\cos\theta, b\sin\theta)}\), and using Pythagoras with \({\cos^2\theta + \sin^2\theta = 1}\).
  • Jay Abramson and others, Algebra and Trigonometry 2e, Section 9.2 Sum and Difference Identities, OpenStax. The sum formulas for sine and cosine, and Example 2, which finds \({\cos 75^\circ = (\sqrt{6} - \sqrt{2})/4}\) from \({45^\circ + 30^\circ}\). The section derives the cosine formula differently, from the distance between two points of the unit circle.
  • Python Software Foundation, math — Mathematical functions, Python 3.12 documentation: math.isclose has a default relative tolerance of \({10^{-9}}\) and an absolute tolerance abs_tol of 0, so comparing a number with 0 needs a positive abs_tol; and math.dist. NumPy reference, numpy.allclose: true when two arrays agree element by element within a tolerance.
  • Ashish Vaswani and others, Attention Is All You Need, 2017, Section 3.5 Positional Encoding: the authors chose sine and cosine encodings because they “hypothesized it would allow the model to easily learn to attend by relative positions”, since for any fixed offset \(k\) the encoding of position \({p + k}\) can be represented as a linear function of the encoding of position \(p\).

Next. This closes the module. Complex numbers (M01.9) meet the angle-addition formulas again as the product of two points on the unit circle; the dot product (M02.3) is built on the law of cosines; and calculus (M04.3.2) uses the two angle-addition formulas to find the slope of a sine wave.

This lesson unlocks

M01.9 Complex numbers M02.3 Dot product, norms, angles and projections M04.3 Differentiation rules and the chain rule

Your progress is saved in this browser only. No account, no tracking.
Back to top