Law of Cosines Calculator — Solve Any Triangle

Side c

--

Angle A

--

Angle B

--

Area

--

How the Law of Cosines Works

The Law of Cosines is a fundamental theorem in trigonometry that relates the lengths of the sides of any triangle to the cosine of one of its angles. It generalizes the Pythagorean theorem to non-right triangles and is attributed to the ancient Greek mathematician Euclid, who presented an equivalent geometric proposition in his Elements (Book II, Proposition 12-13) around 300 BCE. The modern algebraic form was developed by the French mathematician Francois Viete in the 16th century.

According to Wolfram MathWorld, the Law of Cosines is essential whenever you need to solve a triangle from SAS (two sides and the included angle) or SSS (all three sides) information. It is widely used in navigation, surveying, astronomy, structural engineering, and computer graphics. GPS systems use triangulation principles derived from this law to calculate positions. The companion theorem, the Law of Sines, handles different triangle configurations (ASA, AAS). Together, these two laws can solve any triangle given sufficient information. For right triangles specifically, use our Right Triangle Calculator.

The Law of Cosines Formula

The Law of Cosines has three equivalent forms, one for each side of the triangle:

To find an angle when all three sides are known, rearrange: cos(C) = (a^2 + b^2 - c^2) / (2ab)

Worked example (SAS): Given a = 5, b = 7, C = 60 degrees. c^2 = 25 + 49 - 2(5)(7)cos(60) = 74 - 70(0.5) = 74 - 35 = 39. So c = sqrt(39) = 6.245 units. Area = 0.5 x 5 x 7 x sin(60) = 15.155 sq units.

Key Terms You Should Know

Law of Cosines vs. Law of Sines

Choosing between these two fundamental triangle-solving laws depends on what information you have. This table summarizes when to use each.

Known Information Use Which Law Notes
SAS (2 sides + included angle) Law of Cosines Always gives 1 unique solution
SSS (3 sides) Law of Cosines Rearrange to find angles
ASA (2 angles + included side) Law of Sines Find 3rd angle first (180 - A - B)
AAS (2 angles + non-included side) Law of Sines Find 3rd angle first
SSA (2 sides + non-included angle) Law of Sines (caution) Ambiguous case: 0, 1, or 2 solutions

Practical Law of Cosines Examples

Surveying a lake: A surveyor stands at point A and measures distances to two points B and C on the opposite shore: AB = 200 m and AC = 150 m. The angle BAC = 75 degrees. Using the Law of Cosines: BC^2 = 200^2 + 150^2 - 2(200)(150)cos(75) = 40,000 + 22,500 - 60,000(0.2588) = 47,002. BC = 216.8 m. The distance across the lake is approximately 217 meters.

Finding an angle (SSS): A triangular lot has sides 30 ft, 40 ft, and 45 ft. To find the largest angle (opposite the longest side): cos(C) = (30^2 + 40^2 - 45^2) / (2 x 30 x 40) = (900 + 1600 - 2025) / 2400 = 475/2400 = 0.1979. C = arccos(0.1979) = 78.6 degrees. Calculate the area using the Triangle Area Calculator.

Navigation: A ship sails 12 km on a bearing of 040 degrees, then 8 km on a bearing of 120 degrees. The angle between the two legs is 120 - 40 = 80 degrees. Distance from start: d^2 = 12^2 + 8^2 - 2(12)(8)cos(80) = 144 + 64 - 192(0.1736) = 174.67. d = 13.22 km from the starting point.

Tips for Solving Law of Cosines Problems

Frequently Asked Questions

When should I use the Law of Cosines instead of the Law of Sines?

Use the Law of Cosines when you know SAS (two sides and the included angle between them) or SSS (all three side lengths). These are the two configurations where the Law of Sines cannot be directly applied. For example, if you know sides a = 8, b = 12, and the angle C = 50 degrees between them, the Law of Cosines gives you side c directly. Use the Law of Sines when you know ASA, AAS, or SSA -- but beware the ambiguous case with SSA, which can produce zero, one, or two valid triangles.

Can the Law of Cosines produce negative results?

The final result (a side length) is always positive for valid triangles because you take the square root of c^2. However, the intermediate expression inside the square root can involve a negative cosine term. When angle C is obtuse (greater than 90 degrees), cos(C) is negative, making the -2ab cos(C) term positive and increasing c^2. For example, if C = 120 degrees, cos(120) = -0.5, so -2ab(-0.5) = +ab, giving c^2 = a^2 + b^2 + ab. This correctly produces a longer side opposite the obtuse angle.

How is the Law of Cosines related to the Pythagorean theorem?

The Pythagorean theorem is a special case of the Law of Cosines where angle C = 90 degrees. Since cos(90) = 0, the term -2ab cos(C) vanishes, reducing c^2 = a^2 + b^2 - 2ab cos(90) to simply c^2 = a^2 + b^2. This makes the Law of Cosines the more general principle, applicable to all triangles -- acute, right, and obtuse. The Pythagorean theorem was known to ancient Babylonians around 1800 BCE, while the general cosine law was first explicitly stated by Euclid around 300 BCE.

How do I find all three angles using the Law of Cosines?

When you know all three sides (SSS), rearrange the formula to solve for each angle: cos(A) = (b^2 + c^2 - a^2) / (2bc), then A = arccos(result). Repeat for angle B using cos(B) = (a^2 + c^2 - b^2) / (2ac). Find the third angle as C = 180 - A - B. For example, with sides 5, 7, and 8: cos(A) = (49 + 64 - 25) / (2 x 7 x 8) = 88/112 = 0.786, so A = 38.2 degrees. This method always produces unique, unambiguous results for valid triangles.

What real-world applications use the Law of Cosines?

The Law of Cosines is used extensively in professional fields. Land surveyors use it to calculate distances across obstacles (lakes, buildings) from two measured sides and an angle. Navigators use it for dead reckoning -- determining position after sailing or flying two legs at known angles. Astronomers apply it in the celestial triangle to compute distances between stars. Structural engineers use it to analyze force triangles in trusses and bridges. GPS receivers use related triangulation mathematics to compute your position from satellite signals. Even video game developers use it for collision detection and character pathfinding.

Related Calculators