Bash and Effectiveness

The Law of Cosines is like the bigger, better brother to the Law of Sines. It is used quite often in computational contests (well, at least more than Law of Sines) and is key to bashing an unknown side in terms of a variable, finding a length directly, or finding the cosine of an angle. You can then use this derived length in whatever tools you need (e.g. similar triangles, pythagorean theorem, etc.).

Formula & Derivation

Let's lay out some notation first. In any triangle △ABC\triangle ABC, we label each side with the lowercase letter of the angle it sits across from, so side aa is opposite angle AA, side bb is opposite BB, and side cc is opposite CC.

A B C c a b

Each side is named after the angle it faces.

The Law of Cosines states:

c2=a2+b2−2abcos⁡Cc^2 = a^2 + b^2 - 2ab\cos C

There's nothing special about CC; by symmetry, you get one version at each angle:

a2=b2+c2−2bccos⁡Ab2=a2+c2−2accos⁡Ba^2 = b^2 + c^2 - 2bc\cos A \qquad\qquad b^2 = a^2 + c^2 - 2ac\cos B

And if it's the angle you want rather than a side, just solve for the cosine:

cos⁡C=a2+b2−c22ab\cos C = \frac{a^2 + b^2 - c^2}{2ab}

Why "generalized Pythagorean theorem"? Set C=90∘C = 90^\circ. Then cos⁡C=0\cos C = 0, the last term cancels to 0, and you're left with c2=a2+b2c^2 = a^2 + b^2. The −2abcos⁡C-2ab\cos C term is indeed the correction for the angle not being right. And note: if CC is obtuse then cos⁡C<0\cos C < 0, so the term adds to cc, which is basically what you'd expect from opening the angle wider.

Derivation

The trick is the one that we have stressed many times: drop an altitude and split one annoying triangle into two right triangles, where trigonometry and Pythagoras actually apply.

Drop a perpendicular from BB onto side b=CAb = CA, call the foot HH.

A B C H h b − a cos C a cos C

The altitude hh splits △ABC\triangle ABC into two right triangles, △BHC\triangle BHC and △BHA\triangle BHA.

Look at the right triangle △BHC\triangle BHC. Its hypotenuse is aa, and the angle at CC is our angle CC, so from trigonometry:

h=asin⁡CCH=acos⁡Ch = a\sin C \qquad\qquad CH = a\cos C

Since the full base CACA has length bb, the leftover segment is:

AH=b−acos⁡CAH = b - a\cos C

Now apply the Pythagorean theorem to the other right triangle, △BHA\triangle BHA — its legs are AHAH and hh, and its hypotenuse is cc:

c2=AH2+h2=(b−acos⁡C)2+(asin⁡C)2c^2 = AH^2 + h^2 = (b - a\cos C)^2 + (a\sin C)^2

Expand:

c2=b2−2abcos⁡C+a2cos⁡2C+a2sin⁡2Cc^2 = b^2 - 2ab\cos C + a^2\cos^2 C + a^2\sin^2 C

Group the two a2a^2 terms and cancel them with sin⁡2C+cos⁡2C=1\sin^2 C + \cos^2 C = 1:

c2=a2(sin⁡2C+cos⁡2C)+b2−2abcos⁡C=a2+b2−2abcos⁡C■c^2 = a^2\left(\sin^2 C + \cos^2 C\right) + b^2 - 2ab\cos C = a^2 + b^2 - 2ab\cos C \qquad \blacksquare

(If CC is obtuse, HH lands outside segment CACA and cos⁡C\cos C comes out negative, so the formula still holds.)

Techniques

The Law of Cosines is useful in a variety of ways, one obvious case being finding a missing side length given two side lengths and a known angle between them. However, there is quite some nuance in how it's used at more advanced levels of competition. For instance:

  • You may get a side length in terms of a variable and use that new side length as new information to solve further. If this is unclear, consider the examples we present, and as always, practice!
  • Solve for the cosine of the angle. You may have similar triangles, and knowing the cosine of that angle can be used in other triangles where that angle is also present.
  • Noticing congruent, complementary, or supplementary angles and using how their cosines relate to the cosine of the original angle (e.g. cos⁡(180∘−θ)=−cos⁡θ\cos(180^\circ - \theta) = -\cos\theta).

Always match aa with AA, bb with BB, and cc with CC. The side opposite to the angle is the one being solved for in a2=b2+c2−2bccos⁡Aa^2=b^2+c^2-2bc\cos A.

Elementary Examples

Example 1: Solving for a side

Find the missing side. In △ABC\triangle ABC, two sides of length 88 and 55 meet at a 60∘60^\circ angle at vertex CC. Find the length of the third side c=ABc = AB.

C B A 60° 5 8 c

The 60∘60^\circ angle is enclosed by the two known sides, sitting opposite the unknown side cc — exactly the configuration the Law of Cosines handles:

c2=82+52−2(8)(5)cos⁡60∘=64+25−80⋅12=89−40=49.c^2 = 8^2 + 5^2 - 2(8)(5)\cos 60^\circ = 64 + 25 - 80\cdot\tfrac{1}{2} = 89 - 40 = 49.

Hence c=49=7c = \sqrt{49} = 7.

Example 2: Cosine of an angle in terms of a variable

Express the angle. In △ABC\triangle ABC, the side BCBC has unknown length xx, while AB=3AB = 3 and AC=5AC = 5. Write cos⁡B\cos B as a function of xx.

B C A 3 x 5

We want the angle at BB. It is enclosed by the sides AB=3AB = 3 and BC=xBC = x, and it sits opposite the side AC=5AC = 5. Solving the Law of Cosines for the cosine gives what we want:

cos⁡B=AB2+BC2−AC22⋅AB⋅BC=32+x2−522(3)(x)=x2−166x.\cos B = \frac{AB^2 + BC^2 - AC^2}{2\cdot AB\cdot BC} = \frac{3^2 + x^2 - 5^2}{2(3)(x)} = \frac{x^2 - 16}{6x}.

Worked Example

2026 AIME I · Problem 5. Points AA and BB lie in a plane with AB=1AB = 1. Rotate AA counterclockwise about BB through an acute angle θ\theta to land at A′A'; then rotate BB clockwise about A′A' through the same angle θ\theta to land at B′B'. Given that AB′=43AB' = \tfrac{4}{3}, write cos⁡θ=mn\cos\theta = \tfrac{m}{n} in lowest terms and find m+nm+n.

B A A' B' O θ 1 1/2 2/3

Solid: the parallelogram BAA′B′BAA'B'. Dashed: its diagonals, meeting at the midpoint OO.

Rotation preserves distance to its center, so BA′=BA=1BA' = BA = 1, and then A′B′=A′B=1A'B' = A'B = 1. Hence three of the four connecting segments equal 11, with AB′=43AB' = \tfrac{4}{3} given.

Because the two rotations turn BA⃗\vec{BA} into B′A′⃗\vec{B'A'}, the points form a parallelogram BAA′B′BAA'B' whose diagonals are BA′=1BA' = 1 and AB′=43AB' = \tfrac{4}{3}. Diagonals bisect each other at OO, so

BO=12,AO=23.BO = \tfrac{1}{2}, \qquad AO = \tfrac{2}{3}.

The rotation angle is exactly ∠ABA′=θ\angle ABA' = \theta, which is the angle at BB in △ABO\triangle ABO (since OO lies on BA′BA'). That triangle has sides AB=1AB = 1 and BO=12BO = \tfrac{1}{2} enclosing θ\theta, opposite the side AO=23AO = \tfrac{2}{3}. Apply the Law of Cosines:

AO2=AB2+BO2−2 (AB)(BO)cos⁡θAO^2 = AB^2 + BO^2 - 2\,(AB)(BO)\cos\theta
(23)2=12+(12)2−2(1) ⁣(12)cos⁡θ    ⟹    49=54−cos⁡θ.\left(\tfrac{2}{3}\right)^2 = 1^2 + \left(\tfrac{1}{2}\right)^2 - 2(1)\!\left(\tfrac{1}{2}\right)\cos\theta \;\;\Longrightarrow\;\; \tfrac{4}{9} = \tfrac{5}{4} - \cos\theta.

Therefore cos⁡θ=54−49=45−1636=2936\cos\theta = \tfrac{5}{4} - \tfrac{4}{9} = \tfrac{45 - 16}{36} = \tfrac{29}{36}, giving m+n=29+36=65m + n = 29 + 36 = \boxed{65}.

Practice Problems

StatusSourceProblem NameDifficultyTags
AMC 12AHard
Show TagsCircles, Geometry, Tangency
AMC 12AHard
Show TagsCyclic Quadrilateral, Geometry, Law of Cosines
Berkeley Math Circle Monthly Contest 3Hard
Show TagsDistance chasing, Triangle trigonometry
MathNetHard
Show TagsTangents, Triangle trigonometry
MathNetHard
Show TagsOptimization in geometry, Triangle trigonometry, Trigonometry
Berkeley Math Circle: Monthly Contest 7Hard
Show TagsConstructions and loci, Triangle trigonometry
Berkeley Math Circle Monthly Contest 1Hard
Show TagsAngle chasing, Tangents, Triangle trigonometry
Berkeley Math Circle Monthly Contest 2Hard
Show TagsAngle chasing, Cyclic quadrilaterals, Triangle trigonometry
Berkeley Math Circle Monthly Contest 3Hard
Show TagsAngle chasing, Triangle trigonometry
Berkeley Math CircleHard
Show TagsAngle chasing, Triangle trigonometry
MathNetHard
Show Tags3D Shapes, Triangle trigonometry, Trigonometry, Volume
Berkeley Math CircleHard
Show TagsAngle chasing, Spiral similarity, Triangle trigonometry
MathNetHard
Show TagsOptimization in geometry, Triangle centers: centroid, incenter, circumcenter, orthocenter, Euler line, nine-point circle, Triangle trigonometry
Berkeley Math Circle: Monthly Contest 7Hard
Show TagsAngle chasing, Constructions and loci, Triangle centers: centroid, incenter, circumcenter, orthocenter, Euler line, nine-point circle, Triangle trigonometry
Berkeley Math Circle Monthly Contest 7Hard
Show TagsAngle chasing, Triangle trigonometry
Berkeley Math Circle: Monthly Contest 7Hard
Show TagsDistance chasing, Triangle centers: centroid, incenter, circumcenter, Euler line, nine-point circle, Triangle trigonometry
Berkeley Math Circle Monthly Contest 2Hard
Show TagsDistance chasing, Tangents, Triangle trigonometry
Berkeley Math Circle Monthly Contest 2Hard
Show TagsAngle chasing, Cyclic quadrilaterals, Triangle trigonometry
Harvard-MIT Math TournamentHard
Show TagsAngle chasing, Triangle trigonometry
Harvard-MIT Math TournamentHard
Show TagsTriangle trigonometry, Trigonometry
USA IMOHard
Show TagsAngle chasing, Triangle centers: centroid, incenter, circumcenter, orthocenter, Euler line, nine-point circle, Triangle inequalities, Triangle trigonometry
Harvard-MIT Math TournamentHard
Show TagsTriangle trigonometry, Trigonometry
Harvard-MIT Math TournamentHard
Show TagsAngle chasing, Circles, Rotation, Triangle trigonometry

Module Progress:

Join the Discord Community!

Stuck on a problem, or don't understand a module? Join the Discord and get help with your doubts while making more math friends.