Skip to content
Calculator Collection

Law of Cosines Calculator

Finds the third side of a triangle when two sides and the included angle are known, using c = √(a² + b² − 2ab·cos(C)). Essential for solving oblique (non-right) triangles in surveying, navigation, structural engineering, and computer graphics.

Last updated: May 2026

Fill in the required fields to see your result.

Compare with similar

About this calculator

The Law of Cosines generalizes the Pythagorean theorem to any triangle, not just right triangles. The formula for the unknown side opposite the included angle is c = √(a² + b² − 2ab·cos(C)), where a and b are the two known sides and C is the angle between them (the included angle). The angle must be converted from degrees to radians (radians = degrees × π / 180) for the cosine calculation in any programming language or calculator working in radians. Variables: side_a, side_b (two known sides in consistent linear units), angle_c (the included angle, in degrees, between 0° and 180° exclusive for a valid triangle). When C = 90°, cos(90°) = 0 and the formula reduces exactly to the Pythagorean theorem c = √(a² + b²). For C < 90° (acute), cos(C) > 0 and c is shorter than the Pythagorean prediction — the triangle 'closes up'. For C > 90° (obtuse), cos(C) < 0 and the −2ab·cos(C) term becomes positive, making c larger than the Pythagorean prediction — the triangle 'opens up'. Edge cases: at exactly C = 0° (sides overlap), c = |a − b| (a degenerate triangle along a line); at C = 180° (sides point in opposite directions), c = a + b (a fully extended line segment). The formula is indispensable for SAS (side-angle-side) problems and can be rearranged to solve SSS (side-side-side) problems for any angle: cos(C) = (a² + b² − c²) / (2ab), giving C = arccos((a² + b² − c²) / (2ab)).

How to use

Example 1: side a = 7 units, side b = 10 units, included angle C = 60°. Step 1: square the sides — a² = 49, b² = 100. Step 2: compute the cosine term — 2 × 7 × 10 × cos(60°) = 140 × 0.5 = 70. Step 3: substitute — c = √(49 + 100 − 70) = √79 ≈ 8.888 units. Verify: with C = 60° (acute), c should be less than the Pythagorean estimate √(49 + 100) = √149 ≈ 12.2 — confirmed, 8.89 < 12.2. Example 2: a = 5 m, b = 8 m, angle C = 120° (obtuse). Step 1: a² + b² = 25 + 64 = 89. Step 2: 2ab × cos(120°) = 2 × 5 × 8 × (−0.5) = −40. Step 3: c = √(89 − (−40)) = √129 ≈ 11.36 m. Verify: with C > 90°, c should be larger than the Pythagorean estimate √89 ≈ 9.43 — confirmed, 11.36 > 9.43.

Frequently asked questions

What is the Law of Cosines and when should I use it?

The Law of Cosines states c = √(a² + b² − 2ab·cos(C)) and applies to any triangle, with or without a right angle. The Pythagorean theorem is a special case valid only for right triangles (where C = 90° and the cosine term vanishes). Use the Law of Cosines whenever you have two sides and the included angle (SAS) and need the third side, or when you have all three sides (SSS) and need to find an angle. It is the correct choice for oblique triangles encountered in navigation, land surveying, structural design, and 3D computer graphics. Together with the Law of Sines, it lets you solve any triangle given a complete set of independent measurements.

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

The Pythagorean theorem is actually a special case of the Law of Cosines. When the included angle C equals 90°, cos(90°) = 0, so the term −2ab·cos(C) drops out entirely, leaving c² = a² + b². For angles less than 90° (acute), cos(C) is positive, meaning the third side c is shorter than the Pythagorean prediction — the triangle 'closes up'. For angles greater than 90° (obtuse), cos(C) is negative, so the third side is longer than the Pythagorean value. This makes the Law of Cosines a powerful generalization that smoothly interpolates between all three triangle types — acute, right, and obtuse — through one unified formula.

Can the Law of Cosines be used to find an angle if all three sides are known?

Yes. Rearranging the formula gives cos(C) = (a² + b² − c²) / (2ab), from which C = arccos((a² + b² − c²) / (2ab)). If all three sides are known, you can find any of the three angles by selecting the right combination of sides — to find angle A opposite side a, use cos(A) = (b² + c² − a²) / (2bc). Apply this version when you have an SSS triangle (all three sides) and need any of the angles. It is commonly needed in structural engineering and 3D graphics to compute the orientation of surfaces, in navigation to find bearings from known waypoint distances, and in robotics inverse kinematics.

What are common mistakes when using the Law of Cosines?

Using an angle other than the included angle (the angle between the two known sides) gives a wrong result — make sure C is sandwiched between sides a and b. Forgetting to set the trig function to degree mode interprets the angle as radians and gives wildly wrong cosines. Confusing the formula's sides: the unknown c is opposite the known angle C, so always pair the angle with the side opposite to it. Forgetting to take the square root at the end returns c² instead of c. For the SSS angle-finding variant, putting sides in the wrong order in the formula gives a different angle than intended. Floating-point precision issues can produce a cosine value slightly outside [−1, 1] for nearly degenerate triangles; clamp the argument of arccos before computing.

When should I NOT use the Law of Cosines?

For right triangles where one angle is already 90°, the Pythagorean theorem is simpler and equivalent. When you know two angles and a side (AAS or ASA), the Law of Sines is more efficient — a/sin(A) = b/sin(B) = c/sin(C). For SSA (side-side-angle, the 'ambiguous case'), neither law alone resolves the two-triangle ambiguity without additional info. Spherical triangles on a sphere's surface use a different Law of Cosines that involves the radius and great-circle arcs, not flat-plane sides. Hyperbolic triangles in non-Euclidean geometry use yet another variant. For very flat (nearly degenerate) triangles where one angle is close to 180°, floating-point precision can break — sanity-check with the Triangle Inequality (sum of any two sides must exceed the third). Finally, when only two sides are known and no angle is given, you do not have enough information to solve the triangle uniquely.

Sources & references