What Is the Law of Cosines?
The Law of Cosines (also known as the cosine rule) is one of the most powerful tools in trigonometry. It relates the three sides of any triangle to one of its angles, allowing you to solve triangles when you know either two sides and the included angle (SAS) or all three sides (SSS).
If you have ever wondered how the Pythagorean theorem might work for non-right triangles, the Law of Cosines is your answer. It is literally a generalization of that famous theorem, with an extra correction term that accounts for the deviation of the angle from 90 degrees.
This formula can be written for any side of the triangle. The three symmetric forms are:
b² = a² + c² − 2ac · cos B
c² = a² + b² − 2ab · cos C
In each formula, the side on the left is the one opposite the angle that appears inside the cosine function. The other two sides appear as the squared terms and in the product on the right.
Relationship to the Pythagorean Theorem
The Pythagorean theorem states that for a right triangle, c² = a² + b². Now look at the Law of Cosines: c² = a² + b² − 2ab cos C. What happens when C = 90 degrees?
Since cos 90° = 0, the term −2ab cos C vanishes entirely, leaving:
This is exactly the Pythagorean theorem. The Law of Cosines reduces to the Pythagorean theorem as a special case when the angle is 90 degrees. This is why we call the Law of Cosines a generalization of the Pythagorean theorem.
The correction term −2ab cos C adjusts for how much the angle deviates from a right angle:
- If C < 90°: cos C is positive, so −2ab cos C is negative, making c² smaller than a² + b². The side opposite an acute angle is shorter than the Pythagorean prediction.
- If C = 90°: cos C = 0, and the formula becomes the Pythagorean theorem exactly.
- If C > 90°: cos C is negative, so −2ab cos C is positive, making c² larger than a² + b². The side opposite an obtuse angle is longer than the Pythagorean prediction.
Key Takeaway
The Law of Cosines is the Pythagorean theorem with a correction factor. When C = 90 degrees, the correction vanishes and you recover c² = a² + b² exactly.
Proof of the Law of Cosines
We can prove the Law of Cosines using coordinate geometry. Place triangle ABC with vertex C at the origin, side a along the positive x-axis, and vertex B at point (a, 0).
With C at the origin, vertex A is located at (b cos C, b sin C) because side b has length b and makes angle C with the x-axis. Vertex B is at (a, 0).
The distance from A to B is side c. Using the distance formula:
Expanding:
Since cos²C + sin²C = 1, the b²cos²C + b²sin²C terms combine to b²:
When to Use the Law of Cosines
The Law of Cosines is your primary tool for two specific triangle configurations:
SAS (Side-Angle-Side)
When you know two sides and the included angle (the angle between them), the Law of Cosines directly computes the third side. After finding the third side, you can use either the Law of Cosines again or the Law of Sines to find the remaining angles.
SSS (Side-Side-Side)
When you know all three sides but no angles, rearrange the Law of Cosines to solve for an angle:
Apply this formula three times (or find two angles and use the angle sum property for the third) to determine all angles of the triangle.
Key Takeaway
The Law of Cosines handles SAS and SSS configurations. For AAS, ASA, or SSA configurations, use the Law of Sines instead. If you are unsure which law to use, ask yourself: Do I know an angle and its opposite side? If yes, use the Law of Sines. Otherwise, use the Law of Cosines.
Finding Angles from Three Sides
When solving SSS triangles, it is good practice to find the largest angle first. The largest angle is opposite the longest side. This matters because if the triangle has an obtuse angle, it must be the largest angle, and computing it first with the Law of Cosines avoids ambiguity issues that can arise with the Law of Sines.
After finding the largest angle with the Law of Cosines, you can safely use the Law of Sines for the remaining angles (since they must both be acute) or continue using the Law of Cosines for all three.
Connection to Heron's Formula
Heron's formula computes the area of a triangle from its three sides:
where s = (a + b + c) / 2
The Law of Cosines and Heron's formula are deeply connected. You can derive Heron's formula from the Law of Cosines combined with the sine area formula Area = (1/2)ab sin C. First use the Law of Cosines to express cos C in terms of sides, then use sin²C = 1 − cos²C to find sin C, and substitute into the area formula. After algebraic simplification, Heron's formula emerges.
Worked Examples
Example 1: SAS — Find the Missing Side
Given: In triangle ABC, a = 8, b = 11, and angle C = 37°.
Step 1: Apply the Law of Cosines to find side c.
c² = a² + b² − 2ab cos C
c² = 8² + 11² − 2(8)(11) cos 37°
c² = 64 + 121 − 176(0.7986)
c² = 185 − 140.55 = 44.45
Step 2: Take the square root.
c = √44.45 = 6.67
Step 3: Find angle A using the Law of Sines.
sin A / a = sin C / c
sin A = 8 · sin 37° / 6.67 = 8(0.6018) / 6.67 = 0.7218
A = arcsin(0.7218) = 46.22°
Step 4: Find angle B.
B = 180° − 37° − 46.22° = 96.78°
Solution: c ≈ 6.67, A ≈ 46.22°, B ≈ 96.78°
Example 2: SSS — Find All Angles
Given: In triangle ABC, a = 5, b = 7, c = 9.
Step 1: Find the largest angle first. Side c = 9 is longest, so find angle C.
cos C = (a² + b² − c²) / (2ab)
cos C = (25 + 49 − 81) / (2 · 5 · 7)
cos C = −7 / 70 = −0.1
C = arccos(−0.1) = 95.74°
Step 2: Find angle A using the Law of Cosines.
cos A = (b² + c² − a²) / (2bc)
cos A = (49 + 81 − 25) / (2 · 7 · 9)
cos A = 105 / 126 = 0.8333
A = arccos(0.8333) = 33.56°
Step 3: Find angle B.
B = 180° − 95.74° − 33.56° = 50.70°
Solution: A ≈ 33.56°, B ≈ 50.70°, C ≈ 95.74°
Example 3: Word Problem — Navigation
Problem: A ship sails 40 km due east, then changes course by 65° to the left (turning toward the northeast) and sails another 30 km. How far is the ship from its starting point?
Step 1: Model the situation as a triangle. The starting point, the turning point, and the final position form a triangle. The two known sides are 40 km and 30 km.
Step 2: Find the included angle. The ship turned 65° to the left from its eastward course. The interior angle of the triangle at the turning point is 180° − 65° = 115°.
Step 3: Apply the Law of Cosines (SAS).
d² = 40² + 30² − 2(40)(30) cos 115°
d² = 1600 + 900 − 2400(−0.4226)
d² = 2500 + 1014.3 = 3514.3
d = √3514.3 = 59.28 km
Practice Problems
Practice 1
In triangle ABC, b = 12, c = 15, and angle A = 50°. Find side a and the remaining angles.
Solution:
a² = 12² + 15² − 2(12)(15) cos 50°
a² = 144 + 225 − 360(0.6428) = 369 − 231.4 = 137.6
a = √137.6 = 11.73
cos B = (a² + c² − b²) / (2ac) = (137.6 + 225 − 144) / (2 · 11.73 · 15) = 218.6 / 351.9 = 0.6211
B = arccos(0.6211) = 51.60°
C = 180° − 50° − 51.60° = 78.40°
Practice 2
A triangle has sides of length 13, 14, and 15. Find all three angles.
Solution:
Let a = 13, b = 14, c = 15 (largest side). Find C first:
cos C = (169 + 196 − 225) / (2 · 13 · 14) = 140 / 364 = 0.3846
C = arccos(0.3846) = 67.38°
cos B = (169 + 225 − 196) / (2 · 13 · 15) = 198 / 390 = 0.5077
B = arccos(0.5077) = 59.49°
A = 180° − 67.38° − 59.49° = 53.13°
Practice 3
Two hikers start from the same point. Hiker A walks 5 km on a bearing of N 40° E. Hiker B walks 7 km on a bearing of S 60° E. How far apart are the hikers?
Solution:
The angle between the two paths at the starting point: the bearing N 40° E is 40° from north, and S 60° E is 120° from north (measured clockwise). The included angle is 120° − 40° = 80°.
d² = 5² + 7² − 2(5)(7) cos 80°
d² = 25 + 49 − 70(0.1736) = 74 − 12.15 = 61.85
d = √61.85 = 7.86 km
Practice 4
Verify that the triangle with sides 3, 4, and 5 has a right angle using the Law of Cosines.
Solution:
Find the angle opposite the longest side (5):
cos C = (3² + 4² − 5²) / (2 · 3 · 4)
cos C = (9 + 16 − 25) / 24 = 0 / 24 = 0
C = arccos(0) = 90°
This confirms the 3-4-5 triangle is a right triangle, exactly as the Pythagorean theorem predicts.