Law of Cosines: Pythagoras for Every Triangle, and What It Solves

Updated 19 min read Intermediate Baca dalam Bahasa Indonesia

Geometry Algebra Computing Python JavaScript

Quick answer

The law of cosines says that in a triangle with sides a, b and the angle C between them, the opposite side satisfies c^2=a^2+b^2-2ab\cos C: the Pythagorean theorem with a correction that vanishes at a right angle. It finds the third side from two sides and the angle between them, and every angle from three sides, with \cos C=(a^2+b^2-c^2)/(2ab). The sign of the correction also says whether the angle is acute, right or obtuse. It also adds forces at an angle.

Key takeaways

  • In c^2=a^2+b^2-2ab\cos C, C is the angle between a and b, which is also the angle opposite c. At C=90^\circ, \cos C=0 and it is the Pythagorean theorem; for an acute angle the correction subtracts and c is shorter than the hypotenuse of the same legs, for an obtuse angle it adds.
  • It follows from one altitude and Pythagoras: the altitude splits a into b\cos C and a-b\cos C (the first is negative, and the foot falls outside, if C is obtuse), and c^2=h^2+(a-b\cos C)^2 with h=b\sin C.
  • Two sides and the angle between them (SAS) give the third side directly. Three sides (SSS) give every angle, \cos C=(a^2+b^2-c^2)/(2ab): find the largest angle first, the one opposite the longest side, because it is the only one that can be obtuse.
  • Since -1\le\cos C\le1, the third side is always between |a-b| and a+b: the law contains the triangle inequality. And comparing c^2 with a^2+b^2 tells acute, right or obtuse from the sides alone, which proves the converse of the Pythagorean theorem.
  • Two forces F_1 and F_2 whose directions make the angle θ add to R with R^2=F_1^2+F_2^2+2F_1F_2\cosθ, a plus because the triangle's angle is 180^\circ-θ. A journey of two legs on bearings is the same triangle, and the law gives the distance and the bearing back.
  • In a program, the arccosine form loses the angle of a thin triangle: sides 10^8, 10^8 and 1 give \cos C rounded to 1 and an angle of 0 instead of 5.7×10^-7 degrees. The half-angle form \tan\frac C2=√(((s-a)(s-b))/(s(s-c))), with s-a and s-b computed as (c±(b-a))/(2), keeps it.

What does the law of cosines say?

The law of cosines says that in a triangle with sides a and b enclosing the angle C, the third side c, opposite C, satisfies c^2=a^2+b^2-2ab\cos C. Read it as the Pythagorean theorem plus a correction. If C is a right angle, \cos C=0, the correction disappears and c^2=a^2+b^2. If C is acute, \cos C>0 and the correction subtracts: the third side is shorter than the hypotenuse of a right triangle with the same two legs. If C is obtuse, \cos C<0 and the correction adds: it is longer.

The letters follow the same convention as in the law of sines: A, B, C are the angles and a, b, c the sides opposite them. In the formula above C is both the angle opposite c and the angle between a and b, and it is the same angle. The other two forms are the same law with the letters moved: a^2=b^2+c^2-2bc\cos A and b^2=a^2+c^2-2ac\cos B. Solving for the cosine gives the form for finding an angle: \cos C=(a^2+b^2-c^2)/(2ab).

A first check with the triangle 13, 14, 15: for the angle A opposite 13, \cos A=(14^2+15^2-13^2)/(2·14·15)=(252)/(420)=0.6, so A=53.13^\circ, the same angle as in the 3-4-5 triangle. When is it needed? The law of sines needs a side together with its opposite angle; when there is none, with two sides and the angle between them or with three sides, the law of cosines is the way in (see the law of sines for the choice between them, and the article on triangles for the overview).

Why is the law of cosines true? A proof with one altitude

The law of cosines follows from the Pythagorean theorem applied to a right triangle cut off by an altitude. Put the angle C at the vertex C and drop the altitude h from A onto the line CB. In the right triangle with hypotenuse b and the angle C, the adjacent side is b\cos C and the height is h=b\sin C (see the right triangle). The altitude cuts the side a into b\cos C and a-b\cos C. The other right triangle has the hypotenuse c and legs h and a-b\cos C, so by Pythagoras c^2=h^2+(a-b\cos C)^2=b^2\sin^2C+a^2-2ab\cos C+b^2\cos^2C. Collect b^2\sin^2C+b^2\cos^2C=b^2 (the identity \sin^2C+\cos^2C=1, see the identities) and you are left with c^2=a^2+b^2-2ab\cos C.

If C is obtuse, the foot of the altitude falls outside the triangle, on the extension of a, at the distance -b\cos C (a positive number, since \cos C<0) from C, and the right triangle has the leg a+(-b\cos C)=a-b\cos C. The computation is word for word the same, so one formula covers both cases.

A second proof, by coordinates. Put C at the origin, B at (a,0) and A at (b\cos C, b\sin C). The distance from A to B squared is (b\cos C-a)^2+(b\sin C)^2, which expands to the same thing. In vector language it is the identity |u-v|^2=|u|^2+|v|^2-2 u· v with u· v=|u||v|\cos C, which is why the dot product is defined with a cosine.

An acute angle $C$. The altitude $h$ from $A$ falls on the side $a$ and cuts it into $b\cos C$ and $a-b\cos C$, with $h=b\sin C$. Pythagoras in the right triangle on the right gives $c^2=h^2+(a-b\cos C)^2$, which with $h=b\sin C$ expands to $a^2+b^2-2ab\cos C$.
An obtuse angle $C$. The foot of the altitude is now outside the triangle, on the extension of $a$, at the distance $|b\cos C|=-b\cos C$ from $C$. The right triangle has the leg $a+|b\cos C|=a-b\cos C$, so the same computation gives $c^2=h^2+(a-b\cos C)^2=a^2+b^2-2ab\cos C$: the formula needs no separate case, since $\cos C$ is negative.

How does the law turn the Pythagorean theorem into a rule for every angle?

Picture two sides of fixed lengths a and b joined at a hinge, with the angle C between them: the third side c is the distance between their free ends, and it grows as the hinge opens. At C near 0^\circ the two sides lie almost on top of each other and c≈|a-b|. At C=90^\circ they are perpendicular and c=√(a^2+b^2). At C near 180^\circ they point in opposite directions and c≈ a+b. In between, c increases steadily, because \cos C decreases from 1 to -1.

This is the triangle inequality in disguise. Since -1\le\cos C\le1, the law gives a^2+b^2-2ab\le c^2\le a^2+b^2+2ab, that is (a-b)^2\le c^2\le(a+b)^2, so |a-b|\le c\le a+b. Here is the sign rule in one line: c^2<a^2+b^2 exactly when \cos C>0 (C acute), c^2=a^2+b^2 exactly when C=90^\circ, and c^2>a^2+b^2 exactly when C is obtuse. So the Pythagorean theorem and its converse (a triangle with c^2=a^2+b^2 has a right angle at C) are the one case \cos C=0 of a single law.

Open the hinge below, move the two sides, and watch the correction term change sign at the right angle.

Interactive: the hinge, how the third side grows with the angle

Open two sides of lengths a and b like a hinge and watch c² = a² + b² − 2ab cos C: the correction term, the right angle where it vanishes, and the limits |a − b| and a + b.

How do you find the third side from two sides, or all the angles from three sides?

With two sides and the angle between them (SAS), the law of cosines gives the third side in one step; with three sides (SSS), it gives each angle, and the order matters: start with the largest angle.

SAS. a=7, b=10 and C=120^\circ. Then c^2=149-140\cos120^\circ=149+70=219, so c=14.80. The angle is obtuse and the correction +70 made c longer than the hypotenuse √(149)=12.21. The two other angles come next, with the law of cosines again or with the law of sines: \sin A=(7\sin120^\circ)/(14.80)=0.4096, and since A is not the largest angle it is acute, so A=24.18^\circ and B=180^\circ-120^\circ-24.18^\circ=35.82^\circ.

SSS. Take the sides 5, 7, 10. The longest side, 10, is opposite the largest angle C, and it is the only angle that could be obtuse, so find it first: \cos C=(25+49-100)/(2·5·7)=(-26)/(70)=-0.3714, and the negative cosine says C=111.80^\circ is obtuse (the arccosine returns a single angle from 0^\circ to 180^\circ, so it cannot be wrong about that). Then \cos A=(49+100-25)/(2·7·10)=(124)/(140)=0.8857, A=27.66^\circ, and B=180^\circ-111.80^\circ-27.66^\circ=40.54^\circ. A check: the angles add up to 180^\circ, and the largest angle faces the longest side.

Why largest first? Once the largest angle is known to be acute (or found to be obtuse) the others are certainly acute, so even the law of sines, whose arcsine only returns acute angles, is safe for them. Start with a smaller angle by the law of sines and an obtuse largest angle gives the wrong answer.

How can you tell from the sides alone whether a triangle is acute, right or obtuse?

Compare the square of the longest side with the sum of the squares of the other two: smaller means all angles are acute, equal means a right angle, larger means an obtuse angle. This is the law of cosines read for the sign. If c is the longest side, the angle C opposite it is the largest, and c^2-(a^2+b^2)=-2ab\cos C has the sign of -\cos C: negative for an acute C, zero for a right angle, positive for an obtuse one. The other two angles are smaller than C, so they are acute whenever C is not obtuse; if C is obtuse they are acute anyway, since a triangle has at most one angle of 90^\circ or more.

Sidesc^2a^2+b^2The largest angle
4, 5, 63641acute: c^2<a^2+b^2
5, 12, 13169169right: c^2=a^2+b^2
4, 5, 74941obtuse: c^2>a^2+b^2

The middle row is the converse of the Pythagorean theorem: if the squares of the sides satisfy c^2=a^2+b^2, the triangle has a right angle opposite c. The converse is not obvious from the statement of the theorem alone, but with the law of cosines it takes a line: c^2=a^2+b^2 forces -2ab\cos C=0, so \cos C=0 and C=90^\circ. This test needs only squares of lengths, so it can be done exactly (see the types of triangles).

How do you add two forces that pull at an angle?

Two forces pulling in directions that make the angle θ add up to a single force R with R^2=F_1^2+F_2^2+2F_1F_2\cosθ, which is the law of cosines with the other angle of the parallelogram. Draw F_1 and then F_2 from its tip: the resultant R closes the triangle. The angle of that triangle at the tip of F_1 is not θ but 180^\circ-θ, because the direction of F_2 makes θ with the extension of F_1. Since \cos(180^\circ-θ)=-\cosθ, the minus of the law becomes a plus.

Example. 30 N and 40 N with 60^\circ between their directions: R^2=2500+2400\cos60^\circ=2500+1200=3700, so R=60.83 N. At 90^\circ it is √(900+1600)=50 N, the Pythagorean theorem. At 0^\circ the forces pull the same way and add, 70 N; at 180^\circ they oppose and subtract, 10 N. The direction of R makes the angle \arctan(F_2\sinθ)/(F_1+F_2\cosθ)=34.7^\circ with F_1. The same rule adds any two vectors, such as velocities (a boat and a current) or displacements.

The mistake to avoid is writing the minus: it belongs to the angle inside the triangle, the plus to the angle between the two directions as the problem gives it.

Two forces of $30$ N and $40$ N whose directions make an angle of $60^\circ$ (drawn at a tenth of the scale). Their sum $R$ is the diagonal of the parallelogram, and the triangle $0,F_1,R$ has the angle $180^\circ-60^\circ=120^\circ$ at the end of $F_1$. So $R^2=30^2+40^2-2\cdot30\cdot40\cos120^\circ=3700$ and $R\approx60.83$ N.

How do you find the distance and the bearing after a journey of two legs?

A journey of two straight legs is two sides of a triangle, the distance back to the start is the third side, and the law of cosines gives it from the lengths and the turn at the bend. A bearing is an angle measured clockwise from north, written with three digits (060^\circ, 085^\circ), the way a ship or aircraft is steered. If the course changes from the bearing b_1 to b_2, it turns through |b_2-b_1| (the smaller way round, never more than 180^\circ), and the angle of the triangle at the bend is 180^\circ minus that turn.

Example. 120 km on 060^\circ, then 90 km on 120^\circ. The turn is 60^\circ, so the angle at the bend is 120^\circ and the distance back is s=√(120^2+90^2-2·120·90\cos120^\circ)=√(33300)=182.48 km. For the direction, find the angle at the start between the first leg and the straight line, again by the law of cosines on the three sides. It is opposite the second leg of 90 km, so \cosα=(120^2+182.48^2-90^2)/(2·120·182.48)=0.9042 and α=25.3^\circ. The course turned to the right at the bend, so the end lies to the right of the first bearing: 060^\circ+25.3^\circ=085.3^\circ. The bearing back is 085.3^\circ+180^\circ=265.3^\circ.

Set your own journey below; the widget finds the angle at the start by the law of cosines and chooses the side from the direction of the turn.

A ship sails $120$ km on bearing $060^\circ$ (measured clockwise from north) and then $90$ km on bearing $120^\circ$. The course turns by $60^\circ$ at the bend, so the triangle's angle there is $180^\circ-60^\circ=120^\circ$ and the law of cosines gives the distance back to the start: $\sqrt{120^2+90^2-2\cdot120\cdot90\cos120^\circ}=\sqrt{33300}\approx182.5$ km, on bearing $085.3^\circ$.

Interactive: a ship on two bearings, how far and in which direction

Sail a distance on one bearing and then another and get the straight-line distance, the bearing of the end and the bearing home, with the law of cosines on the triangle of the journey.

How is the law of cosines connected to Heron's formula and to the length of a median?

Two classic formulas come out of the law of cosines by algebra: the area from three sides (Heron) and the length of a median (Apollonius).

Heron's formula. The area is K=\frac12ab\sin C, so 16K^2=4a^2b^2\sin^2C=4a^2b^2(1-\cos^2C). Put in 2ab\cos C=a^2+b^2-c^2 from the law: 16K^2=4a^2b^2-(a^2+b^2-c^2)^2=\left[2ab-(a^2+b^2-c^2)\right]\left[2ab+(a^2+b^2-c^2)\right]. The first bracket is c^2-(a-b)^2=(c-a+b)(c+a-b) and the second is (a+b)^2-c^2=(a+b-c)(a+b+c), so 16K^2=(a+b+c)(-a+b+c)(a-b+c)(a+b-c), which with s=(a+b+c)/(2) is K=√(s(s-a)(s-b)(s-c)). For 13, 14, 15 this is √(21·8·7·6)=84 (see the area of a triangle).

The median. Let m_c be the median from C to the midpoint M of c. Apply the law of cosines to the two triangles ACM and BCM, whose angles at M add up to 180^\circ, so their cosines are opposite: a^2=m_c^2+(c^2)/(4)-m_cc\cos\mu and b^2=m_c^2+(c^2)/(4)+m_cc\cos\mu. Add the two equations and the cosine cancels: a^2+b^2=2m_c^2+(c^2)/(2) ⇒ m_c=\frac12√(2a^2+2b^2-c^2). For a=13, b=15, c=14: m_c=\frac12√(338+450-196)=\frac12√(592)=12.17. In a right triangle with a=6, b=8, c=10 it gives \frac12√(72+128-100)=5, half the hypotenuse, a fact about the circumcenter of a right triangle (see the medians and centers).

Why does the law of cosines lose the angle of a thin triangle, and what do you do?

For a very thin triangle the arccosine form \arccos(a^2+b^2-c^2)/(2ab) throws away the angle, because the cosine of a tiny angle is a number that rounds to 1; the half-angle form keeps it. Take the sides 10^8, 10^8 and 1. The true angle opposite the side 1 is 2\arcsin(1)/(2·10^8)=5.73×10^-7 degrees. But a^2+b^2=2×10^16 and subtracting c^2=1 changes nothing a double-precision number can show (the spacing of doubles near 2×10^16 is 4), so the ratio is exactly 1 and the arccosine is exactly 0: the angle has vanished. Before that point, the angle is correct but carries fewer and fewer digits: the cosine of an angle near 0 is flat, so an error of 10^-16 in it is an error of 10^-8 radians in the angle.

Two ways out. For a thin triangle with a small angle C, find that angle with the law of sines, which does not square anything. Or use the half-angle form, in terms of the half-perimeter s=(a+b+c)/(2): \tan\frac C2=√(((s-a)(s-b))/(s(s-c))). It needs care in one place: s-a=(b+c-a)/(2) is a small difference of big numbers if c is tiny, so write it as s-a=(c+(b-a))/(2) and s-b=(c-(b-a))/(2), where the subtraction b-a of two long, close sides is exact. The widget below shows both forms for any three sides; try "very thin".

Interactive: the three angles from three sides, and the thin triangle

Type three side lengths and get the angles two ways, by the arccosine and by the half-angle form, with the kind of each angle; a triangle with two very long sides shows where the plain arccosine fails.

How do you use the law of cosines in a program?

A program uses the law of cosines in three functions: the third side from two sides and the included angle, the angle from three sides, and the resultant of two vectors; the one place that needs care is the angle from three sides. Convert degrees to radians before cos, check the triangle inequality before taking an arccosine, and clamp the ratio into [-1,1] so that rounding cannot make acos fail. For a thin triangle, do not trust the plain arccosine, as the section above showed.

The programs below find the third side for a=7, b=10, C=120^\circ (giving 14.7986), the three angles of the triangle 5, 7, 10 (largest first: 111.80^\circ, 27.66^\circ, 40.54^\circ), the resultant of 30 N and 40 N at 60^\circ (60.83 N), and the thin triangle 10^8, 10^8, 1 whose angle, in millionths of a degree, is 0 by the arccosine and 0.573 by the half-angle form.

Python: the third side, the angles, the resultant and a thin triangle
import math


def third_side(a, b, C):
    """The side opposite C (degrees) between the sides a and b: c^2 = a^2 + b^2 - 2ab cos C."""
    return math.sqrt(a * a + b * b - 2 * a * b * math.cos(math.radians(C)))


def angle_naive(a, b, c):
    """The angle opposite c by the arccosine, the ratio clamped into [-1, 1]."""
    x = (a * a + b * b - c * c) / (2 * a * b)
    return math.degrees(math.acos(max(-1.0, min(1.0, x))))


def angle_stable(a, b, c):
    """The same angle by the half-angle form; s - a and s - b are written (c +- (b - a)) / 2 so a tiny c is not lost."""
    u = (c + (b - a)) / 2
    v = (c - (b - a)) / 2
    s = (a + b + c) / 2
    return math.degrees(2 * math.atan(math.sqrt(u * v / (s * (s - c)))))


def resultant(F1, F2, theta):
    """The size of the sum of two forces whose directions make the angle theta (degrees)."""
    return math.sqrt(F1 * F1 + F2 * F2 + 2 * F1 * F2 * math.cos(math.radians(theta)))


print(round(third_side(7, 10, 120), 4))                       # 14.7986
a, b, c = 5, 7, 10                                             # the largest angle first: the one opposite the longest side
C = angle_naive(a, b, c)
A = angle_naive(b, c, a)
print(round(C, 2), round(A, 2), round(180 - C - A, 2))         # 111.8 27.66 40.54
print(round(resultant(30, 40, 60), 2))                         # 60.83
print(round(angle_naive(1e8, 1e8, 1) * 1e6, 4), round(angle_stable(1e8, 1e8, 1) * 1e6, 4))   # 0.0 0.573
JavaScript: the same four functions
const rad = (d) => (d * Math.PI) / 180
const deg = (r) => (r * 180) / Math.PI

// the side opposite C (degrees) between the sides a and b: c^2 = a^2 + b^2 - 2ab cos C
const thirdSide = (a, b, C) => Math.sqrt(a * a + b * b - 2 * a * b * Math.cos(rad(C)))

// the angle opposite c by the arccosine, the ratio clamped into [-1, 1]
function angleNaive(a, b, c) {
  const x = (a * a + b * b - c * c) / (2 * a * b)
  return deg(Math.acos(Math.max(-1, Math.min(1, x))))
}

// the same angle by the half-angle form; s - a and s - b are written (c +- (b - a)) / 2 so a tiny c is not lost
function angleStable(a, b, c) {
  const u = (c + (b - a)) / 2
  const v = (c - (b - a)) / 2
  const s = (a + b + c) / 2
  return deg(2 * Math.atan(Math.sqrt((u * v) / (s * (s - c)))))
}

// the size of the sum of two forces whose directions make the angle theta (degrees)
const resultant = (F1, F2, theta) => Math.sqrt(F1 * F1 + F2 * F2 + 2 * F1 * F2 * Math.cos(rad(theta)))

+thirdSide(7, 10, 120).toFixed(4)                              // 14.7986
const [a, b, c] = [5, 7, 10]                                   // the largest angle first: the one opposite the longest side
const C = angleNaive(a, b, c)
const A = angleNaive(b, c, a)
;[+C.toFixed(2), +A.toFixed(2), +(180 - C - A).toFixed(2)]     // [111.8, 27.66, 40.54]
+resultant(30, 40, 60).toFixed(2)                              // 60.83
;[+(angleNaive(1e8, 1e8, 1) * 1e6).toFixed(4), +(angleStable(1e8, 1e8, 1) * 1e6).toFixed(4)]   // [0, 0.573]
C++: the same with <cmath>
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

const double PI = 3.14159265358979323846;
double rad(double d) { return d * PI / 180.0; }
double deg(double r) { return r * 180.0 / PI; }

// the side opposite C (degrees) between the sides a and b
double thirdSide(double a, double b, double C) { return sqrt(a * a + b * b - 2 * a * b * cos(rad(C))); }

// the angle opposite c by the arccosine, the ratio clamped into [-1, 1]
double angleNaive(double a, double b, double c) {
  double x = (a * a + b * b - c * c) / (2 * a * b);
  if (x > 1) x = 1;
  if (x < -1) x = -1;
  return deg(acos(x));
}

// the same angle by the half-angle form; s - a and s - b are written (c +- (b - a)) / 2 so a tiny c is not lost
double angleStable(double a, double b, double c) {
  double u = (c + (b - a)) / 2;
  double v = (c - (b - a)) / 2;
  double s = (a + b + c) / 2;
  return deg(2 * atan(sqrt(u * v / (s * (s - c)))));
}

// the size of the sum of two forces whose directions make the angle theta (degrees)
double resultant(double F1, double F2, double theta) { return sqrt(F1 * F1 + F2 * F2 + 2 * F1 * F2 * cos(rad(theta))); }

int main() {
  printf("%.4f\n", thirdSide(7, 10, 120));
  double C = angleNaive(5, 7, 10);                  // the largest angle first: the one opposite the longest side
  double A = angleNaive(7, 10, 5);
  printf("%.2f %.2f %.2f\n", C, A, 180 - C - A);
  printf("%.2f\n", resultant(30, 40, 60));
  printf("%.4f %.4f\n", angleNaive(1e8, 1e8, 1) * 1e6, angleStable(1e8, 1e8, 1) * 1e6);
  return 0;
}

/* output:
14.7986
111.80 27.66 40.54
60.83
0.0000 0.5730
*/

Where does the law of cosines come from?

The law of cosines is older than the cosine: Euclid proved it as two theorems about squares and rectangles, and it became a formula only when the cosine became a number.

  • About 300 BCE. Euclid's Elements, Book II, Propositions 12 and 13, are the law of cosines in the language of geometry: in an obtuse triangle the square on the side opposite the obtuse angle is greater than the squares on the other two sides by twice a rectangle, and in an acute triangle it is less by twice a rectangle. The rectangle is a· b\cos C, built from a side and the projection of the other.
  • 15th century. Jamshid al-Kashi, working in Samarkand, states the law in a form suited to computing a side from two sides and the angle between them with a table of sines. In France it is still called Al-Kashi's theorem.
  • 1748. Euler's Introductio treats the sine and cosine as functions of a number, so that the rectangle can be written ab\cos C and the law as the single formula used today.
  • 19th and 20th centuries. With vectors, the law becomes |u-v|^2=|u|^2+|v|^2-2 u· v, and the dot product u· v=|u||v|\cosθ is defined so that this holds, which carries the law into any number of dimensions.

What are the common mistakes with the law of cosines?

The most common mistakes with the law of cosines are the nine below, each with the correct statement.

MistakeCorrect
❌ c^2=a^2+b^2-2ab\cos A (the wrong angle)The angle is C, between a and b and opposite c.
❌ c=a+b-2ab\cos C (forgetting the squares)It is c^2 on the left; take the square root at the end.
❌ (a^2+b^2-2ab)\cos CThe cosine multiplies only the term 2ab: a^2+b^2-2ab\cos C.
❌ Take \arccos of a ratio without checkingCheck the triangle inequality first, and clamp the ratio into [-1,1] in a program.
❌ Calculator in radian mode with degree dataSet degrees, or convert, or every cosine is wrong.
❌ R^2=F_1^2+F_2^2-2F_1F_2\cosθ for forces at the angle θThe triangle's angle is 180^\circ-θ: R^2=F_1^2+F_2^2+2F_1F_2\cosθ.
❌ Find a small angle first by the arccosine and subtract to get the largestFind the largest angle first (opposite the longest side); only it can be obtuse.
❌ Trust \arccos for a very thin triangleThe cosine rounds to 1: use the half-angle form or the law of sines.
❌ A bearing is measured from the east axisA bearing is measured clockwise from north, with three digits (060^\circ).

Practice: test your understanding

These questions mix everything above. A wrong answer costs nothing here: read the hint and try again.

True or false?

Decide whether each statement is True or False.

  • At C=90^\circ the law of cosines is the Pythagorean theorem.
  • In c^2=a^2+b^2-2ab\cos C, C is the angle between a and b, opposite c.
  • If C is obtuse, then c^2 is smaller than a^2+b^2.
  • Given all three sides, the law of cosines gives each angle.
  • The law of cosines works only for acute triangles.
  • The third side of a triangle with sides a and b can be longer than a+b.

The third side

Two sides of a triangle are 3 and 5 and the angle between them is 120^\circ. How long is the third side?

A cosine from three sides

A triangle has sides 13, 14 and 15. What is the cosine of the angle opposite the side 13?

Another cosine

A triangle has sides 5, 6 and 7. What is the cosine of the angle opposite the side 7?

How long can the third side be?

Two sides of a triangle are 9 and 4. How many whole-number lengths can the third side have?

Two forces

Two forces of 6 N and 8 N pull at right angles to each other. What is the size of their sum, in newtons?

A median

A triangle has sides a=6, b=8 and c=10. How long is the median to the side c?

Which angle first?

You know all three sides and want all three angles. What should you find first?

  • the largest angle, opposite the longest side
  • the smallest angle, opposite the shortest side
  • the angle sum, 180°
  • the area

What kind of triangle?

A triangle has sides 6, 7 and 10. What is the largest angle?

  • acute
  • a right angle
  • obtuse
  • it cannot be a triangle

Which forms are right?

Which of these are correct forms of the law of cosines? Choose all that apply.

  • c^2=a^2+b^2-2ab\cos C
  • a^2=b^2+c^2-2bc\cos A
  • a^2=b^2+c^2-2bc\cos B
  • c^2=a^2+b^2+2ab\cos C
  • \cos C=(a^2+b^2-c^2)/(2ab)

Order the solution

Put the steps of finding the angles of a triangle from its three sides in order.

Fill in the angle

Complete the law of cosines for the side c.

Summary: the law of cosines at a glance

  • The law: c^2=a^2+b^2-2ab\cos C, with C between a and b and opposite c; and \cos C=(a^2+b^2-c^2)/(2ab).
  • Pythagoras with a correction: at 90^\circ it vanishes; acute subtracts, obtuse adds.
  • Proof: the altitude splits a into b\cos C and a-b\cos C (the first is negative for an obtuse C), and h=b\sin C.
  • Range and kinds: |a-b|\le c\le a+b; comparing c^2 with a^2+b^2 gives acute, right or obtuse, and proves the converse of Pythagoras.
  • SAS: the third side in one step. SSS: each angle; the largest first.
  • Forces: R^2=F_1^2+F_2^2+2F_1F_2\cosθ for the angle θ between the directions. Journeys: the angle at the bend is 180^\circ minus the turn.
  • Heron and median: 16K^2=4a^2b^2-(a^2+b^2-c^2)^2 gives Heron's formula; m_c=\frac12√(2a^2+2b^2-c^2).
  • Numerics: the arccosine loses a thin triangle's angle; use \tan\frac C2=√(((s-a)(s-b))/(s(s-c))) with s-a=(c+(b-a))/(2) and s-b=(c-(b-a))/(2).

Glossary: key terms

Law of cosines
The rule that in a triangle the square of a side equals the sum of the squares of the other two minus twice their product times the cosine of the angle between them.
Included angle
The angle between two given sides of a triangle, which is also the angle opposite the third side.
Correction term
The term minus 2ab cos C that turns the Pythagorean theorem into the law of cosines; it is zero at a right angle, negative for an acute angle and positive for an obtuse one.
Triangle inequality
The rule that each side of a triangle is shorter than the sum of the other two and longer than their difference, which the law of cosines contains.
Resultant
The single force or vector equal to the sum of two others; its size follows from the law of cosines with the angle 180 degrees minus the angle between the directions.
Bearing
A direction given as an angle measured clockwise from north, written with three digits, such as 060 degrees.
Median
The segment from a vertex of a triangle to the midpoint of the opposite side; its length is a half of the square root of 2a squared plus 2b squared minus c squared.
Half-angle form
The formula tan of C over 2 equals the square root of s minus a times s minus b over s times s minus c, which finds an angle from three sides without losing the digits of a tiny angle.

Frequently asked questions

What is the formula for the law of cosines?

In a triangle with sides a, b, c and the angle C between a and b, c squared equals a squared plus b squared minus 2 a b times the cosine of C. For a right angle the cosine is zero and it becomes the Pythagorean theorem.

How do you prove the law of cosines?

Drop the altitude from A onto side a. It cuts a into b cos C and a minus b cos C, and its height is b sin C. Pythagoras in the right triangle on the other side gives c squared, and sin squared plus cos squared equals 1 finishes it.

When do you use the law of cosines instead of the law of sines?

When no side comes with its opposite angle: two sides and the angle between them, or three sides. With a side and its opposite angle known, the law of sines is quicker. For finding an angle the law of cosines is also safer.

How do you find an angle from three sides?

Use cos C equals a squared plus b squared minus c squared, over 2 a b, and take the arccosine. Find the largest angle first, opposite the longest side, since only it can be obtuse; a negative cosine means obtuse.

Why does the law of cosines become the Pythagorean theorem at 90 degrees?

The cosine of 90 degrees is zero, so the term minus 2 a b cos C disappears and c squared equals a squared plus b squared. The term is the correction for an angle that is not a right angle: negative if acute, positive if obtuse.

How do you add two forces at an angle?

Use R squared equals F1 squared plus F2 squared plus 2 F1 F2 cos theta, where theta is the angle between the directions of the two forces. It is a plus because the angle inside the triangle is 180 degrees minus theta.

Why does the law of cosines give a wrong angle for a very thin triangle?

The cosine of a tiny angle is a number extremely close to 1, which a computer rounds to exactly 1, so the arccosine returns 0. Use the half-angle formula for tan of C over 2, or the law of sines, which keep the digits.

How do you find the distance after two legs of a journey with different bearings?

The angle of the triangle at the bend is 180 degrees minus the turn between the two bearings. Then the distance is the square root of d1 squared plus d2 squared minus 2 d1 d2 times the cosine of that angle.

References

  1. James Stewart, Lothar Redlin, Saleem Watson (2016). Precalculus: Mathematics for Calculus (chapters on the law of sines and the law of cosines). Cengage Learning.
  2. I. M. Gelfand, Mark Saul (2001). Trigonometry (2nd ed.). Birkhäuser.
  3. Eli Maor (1998). Trigonometric Delights. Princeton University Press.
  4. Thomas L. Heath (translator) (1956). The Thirteen Books of Euclid's Elements (Book II, Propositions 12 and 13). Dover.
  5. Carl B. Boyer, Uta C. Merzbach (2011). A History of Mathematics (3rd ed.). Wiley.
  6. Leonhard Euler (1748). Introductio in analysin infinitorum. Marcum-Michaelem Bousquet.
  7. David Goldberg (1991). What Every Computer Scientist Should Know About Floating-Point Arithmetic. ACM Computing Surveys.