Law of Cosines Calculator

Solve any triangle by finding missing sides or angles using the formula c² = a² + b² - 2ab·cos(C). Supports both SAS and SSS configurations with step-by-step solutions.

Solve Any Triangle with the Law of Cosines

Choose a mode, enter known values, and calculate the missing side or angle

a b c C A B
Law of Cosines: c² = a² + b² - 2ab·cos(C)
Try examples:

How to Use This Calculator

1

Choose Your Mode

Select "Find a Side" if you know two sides and the included angle, or "Find an Angle" if you know all three sides

2

Enter Known Values

Input the side lengths and angle (in degrees or radians) that you already know

3

Get Full Solution

View the missing value, all angles and sides, triangle properties, and step-by-step work

Quick Tips:

  • SAS mode: Enter side a, side b, and the included angle C (the angle between them)
  • SSS mode: Enter all three side lengths to find all angles
  • The interactive triangle diagram updates after each calculation to show your triangle

Understanding the Law of Cosines

The Law of Cosines is one of the most versatile tools in trigonometry, capable of solving triangles that the Pythagorean theorem cannot handle. While the Pythagorean theorem only applies to right triangles, the Law of Cosines works for every triangle, regardless of its shape or angles. Written as c² = a² + b² - 2ab·cos(C), this formula connects the three sides of a triangle to one of its angles, making it possible to find unknown measurements whenever you have enough information.

The formula gets its name from the cosine function, which adjusts the calculation based on the angle between two known sides. When the angle is exactly 90 degrees, the cosine term becomes zero and the formula reduces to the familiar Pythagorean theorem. For acute angles, the cosine is positive and the opposite side is shorter than it would be in a right triangle. For obtuse angles, the cosine is negative and the opposite side becomes longer. This elegant adjustment makes the Law of Cosines a true generalization of the Pythagorean relationship.

The Formula and Its Three Variations

The Law of Cosines actually has three symmetric forms, depending on which side and angle pair you are working with. The standard form is c² = a² + b² - 2ab·cos(C), where C is the angle opposite to side c. By relabeling, you also get a² = b² + c² - 2bc·cos(A) and b² = a² + c² - 2ac·cos(B). Each version solves for a different side using the two remaining sides and their included angle.

To find a missing angle instead of a missing side, the formula can be rearranged algebraically. Solving for the angle gives cos(C) = (a² + b² - c²) / (2ab). Taking the inverse cosine of this expression produces the angle in radians or degrees. This rearranged form is what our calculator uses in "Find an Angle" mode when all three sides are known.

Finding a Missing Side (SAS)

When you know two sides of a triangle and the angle between them (called the included angle), you have a Side-Angle-Side (SAS) configuration. This is one of the most common situations where the Law of Cosines is applied. For example, if side a = 8, side b = 11, and the included angle C = 37°, you would compute c² = 64 + 121 - 2(8)(11)cos(37°) = 185 - 176(0.7986) = 185 - 140.56 = 44.44, giving c = 6.67.

After finding the missing side, the calculator also derives the remaining two angles. It does this by applying the Law of Cosines again in its angle-finding form for one of the unknown angles, then uses the fact that angles in a triangle sum to 180° to find the last angle. This gives you a complete picture of the triangle from just three initial measurements.

Finding a Missing Angle (SSS)

When all three side lengths are known but no angles are given, the Law of Cosines is the ideal tool for determining the angles. This Side-Side-Side (SSS) configuration requires the rearranged formula: cos(C) = (a² + b² - c²) / (2ab). By plugging in the three sides, you calculate the cosine of the angle opposite the side labeled c, then use the inverse cosine function to find the angle itself.

For instance, with sides a = 10, b = 14, and c = 18, you would calculate cos(C) = (100 + 196 - 324) / (2 · 10 · 14) = -28/280 = -0.1, giving C = arccos(-0.1) = 95.74°. The negative cosine value tells us immediately that angle C is obtuse (greater than 90°). Once one angle is found, the remaining angles follow from applying the same formula to a different side or by using the angle sum property.

Connection to the Pythagorean Theorem

The Pythagorean theorem is a special case of the Law of Cosines that applies when the included angle is exactly 90°. Since cos(90°) = 0, the term -2ab·cos(C) vanishes entirely, leaving c² = a² + b², which is the Pythagorean theorem. This connection reveals that the Pythagorean theorem is not a separate law but rather a specific instance of the broader cosine rule.

Understanding this relationship helps explain why the Pythagorean theorem works. The -2ab·cos(C) term represents the adjustment needed when the angle between two sides is not a right angle. For acute angles (less than 90°), cos(C) is positive, so this term subtracts from a² + b², making the opposite side shorter. For obtuse angles (greater than 90°), cos(C) is negative, so the term effectively adds to a² + b², making the opposite side longer.

Navigation and Surveying Applications

Land surveyors rely on the Law of Cosines regularly. When measuring the distance between two points that cannot be reached directly, a surveyor can measure two accessible distances and the angle between them, then calculate the unknown distance. This technique, known as triangulation, has been used for centuries to map terrain, establish property boundaries, and plan construction projects.

In marine and aviation navigation, the Law of Cosines helps calculate distances between waypoints when the route involves turns. If a ship sails 50 nautical miles on one heading, turns 40° to starboard, then sails another 70 nautical miles, the direct distance from start to finish forms a triangle that can be solved with the cosine rule. GPS systems and flight planning software use these calculations constantly behind the scenes.

Engineering and Construction Uses

Structural engineers use the Law of Cosines when designing trusses, bridges, and frameworks where members meet at angles other than 90°. Calculating the forces in each member requires knowing the exact geometry of the structure, and many real-world structures include non-right-angle joints. The cosine rule allows engineers to determine member lengths and angles precisely from design specifications.

Roof framing provides an everyday construction example. When two roof planes meet at a hip or valley, the resulting triangle is rarely a right triangle. Carpenters need the Law of Cosines to calculate the correct cut angles and rafter lengths. Similarly, when designing custom furniture with angled joints or building structures on sloped terrain, the cosine rule provides the accurate measurements needed for a proper fit.

Physics: Forces and Vectors

In physics, the Law of Cosines appears whenever two vectors are added or subtracted at an angle. When two forces act on an object at an angle to each other, their combined effect (the resultant force) forms the third side of a triangle. If forces of 30 N and 40 N act at 60° to each other, the resultant force has magnitude √(900 + 1600 - 2·30·40·cos(120°)) = √(2500 + 1200) = √3700 ≈ 60.83 N. Note that the angle used in the formula is the supplement of the angle between the forces.

The same principle applies to velocity and displacement vectors. When an airplane flies into a crosswind, the ground speed and track are determined by vector addition involving the Law of Cosines. Physicists also use the cosine rule in optics for calculating light path differences, in mechanics for resolving acceleration components, and in electrical engineering for analyzing AC circuit phasors.

Law of Cosines vs. Law of Sines

The Law of Cosines and the Law of Sines are complementary tools for solving triangles. The Law of Sines states that a/sin(A) = b/sin(B) = c/sin(C) and is particularly useful for ASA (Angle-Side-Angle) and AAS (Angle-Angle-Side) configurations. However, the Law of Sines can produce ambiguous results in SSA (Side-Side-Angle) situations, where two different triangles might satisfy the given conditions.

The Law of Cosines avoids this ambiguity entirely. When given SAS or SSS information, there is always exactly one triangle that fits, and the Law of Cosines finds it without any ambiguity. For this reason, many teachers and professionals prefer the Law of Cosines as the first approach to triangle problems, only turning to the Law of Sines when the given information naturally fits its format or when the calculation would be simpler.

Frequently Asked Questions

What is the Law of Cosines?

The Law of Cosines is a formula that relates the lengths of the sides of any triangle to the cosine of one of its angles. Written as c² = a² + b² - 2ab·cos(C), it allows you to find a missing side when you know two sides and the included angle (SAS), or a missing angle when you know all three sides (SSS). It works for all triangles, not just right triangles.

When should I use Find a Side (SAS) mode versus Find an Angle (SSS) mode?

Use Find a Side (SAS) mode when you know two sides of a triangle and the angle between them, and you need the third side. Use Find an Angle (SSS) mode when you know all three side lengths and need to find the angles. SAS stands for Side-Angle-Side, and SSS stands for Side-Side-Side.

How does the Law of Cosines relate to the Pythagorean theorem?

The Pythagorean theorem is a special case of the Law of Cosines. When angle C equals 90 degrees, cos(90°) = 0, so the formula c² = a² + b² - 2ab·cos(C) simplifies to c² = a² + b², which is exactly the Pythagorean theorem. The Law of Cosines generalizes this relationship to work with any angle.

Can the Law of Cosines solve any triangle?

The Law of Cosines can solve triangles when you have SAS (two sides and the included angle) or SSS (all three sides). For other configurations like ASA (angle-side-angle) or AAS (angle-angle-side), the Law of Sines is typically more appropriate. Between the Law of Cosines and Law of Sines, any valid triangle can be solved.

What is the difference between the Law of Cosines and the Law of Sines?

The Law of Cosines (c² = a² + b² - 2ab·cos(C)) relates all three sides to one angle and is best for SAS and SSS problems. The Law of Sines (a/sin(A) = b/sin(B) = c/sin(C)) relates each side to its opposite angle and is best for AAS and ASA problems. The Law of Cosines avoids the ambiguous case that can occur with the Law of Sines in SSA configurations.

What are real-world applications of the Law of Cosines?

The Law of Cosines is widely used in land surveying to calculate distances between points, in navigation for determining positions and bearings, in engineering for analyzing force vectors and structural components, in physics for resolving velocities and accelerations, and in construction for calculating roof angles and beam lengths. Any situation involving non-right triangles may require the Law of Cosines.