terican

Last verified · v1.0

Calculator · math

Law Of Cosines Triangle Calculator

Solve any triangle using the law of cosines. Enter two sides and an included angle (SAS) to find the third side, or all three sides (SSS) to find a missing angle.

FreeInstantNo signupOpen source

Inputs

Computed Value (side length or angle in degrees)

Explain my result

0/3 free

Get a plain-English breakdown of your result with practical next steps.

Computed Value (side length or angle in degrees)

The formula

How the
result is
computed.

Understanding the Law of Cosines

The law of cosines is a foundational trigonometric relationship that generalizes the Pythagorean theorem to any triangle — scalene, isosceles, acute, or obtuse. This cosine triangle calculator solves two classic triangle problems: finding a missing side when two sides and the included angle are known (SAS mode), and finding a missing angle when all three sides are known (SSS mode).

The Core Formula

The law of cosines takes two equivalent forms depending on the unknown quantity:

  • Solving for side c (SAS): c² = a² + b² − 2ab · cos(C)
  • Solving for angle C (SSS): C = arccos((a² + b² − c²) / (2ab))

In both expressions, a, b, and c represent the three side lengths of the triangle, and C is the interior angle opposite side c. According to Khan Academy's law of cosines tutorial and the Texas A&M University Mathematics curriculum (Section 8.5), this formula is the authoritative standard for non-right triangle computation in trigonometry.

Variable Definitions

  • a — Length of the first side. Must be a strictly positive real number.
  • b — Length of the second side. Must be a strictly positive real number.
  • c — Length of the third side, opposite angle C. Required in SSS (angle-solving) mode only. Must satisfy the triangle inequality: |a − b| < c < a + b.
  • Angle C — The interior angle between sides a and b, measured in degrees. Required in SAS (side-solving) mode only. Must fall strictly between 0° and 180°.

Mathematical Derivation

The law of cosines derives from the Pythagorean theorem applied to a triangle with an altitude dropped from vertex C perpendicular to side c. This altitude h creates two right triangles. Applying the Pythagorean theorem to each and combining results using the identity sin²(x) + cos²(x) = 1 yields c² = a² + b² − 2ab·cos(C) directly. When C = 90°, cos(90°) = 0, and the formula reduces to c² = a² + b² — the Pythagorean theorem exactly — confirming it as a special case of the more general law.

Worked Examples

Example 1: SAS — Finding a Missing Side

A land surveyor measures two boundary fences from a corner post: a = 120 m, b = 95 m, with an included angle of C = 47°. Applying the SAS formula: c² = 120² + 95² − 2(120)(95) · cos(47°) = 14400 + 9025 − 22800 · 0.6820 ≈ 23425 − 15550 = 7875. Therefore c ≈ 88.7 m.

Example 2: SSS — Finding a Missing Angle

A triangular plot of land has measured sides of a = 200 ft, b = 175 ft, and c = 150 ft. Applying the SSS formula: C = arccos((200² + 175² − 150²) / (2 · 200 · 175)) = arccos((40000 + 30625 − 22500) / 70000) = arccos(48125 / 70000) = arccos(0.6875) ≈ 46.6°.

Law of Cosines vs. Law of Sines: Choosing the Right Tool

The law of cosines applies specifically in two scenarios: (1) SAS — two sides and their included angle are known, and (2) SSS — all three sides are known. The law of sines is more efficient for AAS and ASA configurations. For SSS problems, the law of cosines delivers a direct, unambiguous solution and avoids the ambiguous-case complications that can arise when applying the law of sines to side-side-angle configurations.

Real-World Applications

  • Surveying: Calculating distances across terrain where direct measurement is impractical.
  • Navigation: Determining a vessel's position from two reference bearings and the angle between them.
  • Structural engineering: Verifying diagonal bracing lengths in non-rectangular frames and trusses.
  • Physics: Computing resultant vector magnitudes when two forces act at an oblique angle.
  • Computer graphics: Calculating polygon edge angles for 3D mesh rendering pipelines.

Input Constraints and Validation

All side lengths must be strictly positive. In SSS mode, the three sides must satisfy the triangle inequality; if the quantity (a² + b² − c²) / (2ab) falls outside the interval [−1, 1], no valid triangle exists with those dimensions. In SAS mode, angle C must be strictly between 0° and 180°; at either boundary the triangle degenerates to a line segment with zero area and no computable geometry.

Reference

Frequently asked questions

What is the law of cosines and when should it be used?
The law of cosines — c² = a² + b² − 2ab·cos(C) — relates the three side lengths of any triangle to one of its interior angles. It applies whenever two sides and the included angle are known (SAS), or when all three sides are known (SSS). Unlike the Pythagorean theorem, it works for all triangle types: acute, right, and obtuse, making it the universal tool for non-right triangle problems.
How do I find a missing side using the law of cosines (SAS)?
Select SAS mode, then enter the two known side lengths (a and b) plus the measure of the included angle C in degrees. The calculator evaluates c² = a² + b² − 2ab·cos(C) and returns the positive square root as side c. For example, with a = 10, b = 8, and C = 60°, the result is c = √(100 + 64 − 80·0.5) = √84 ≈ 9.17 units. Angle C must be strictly between 0° and 180°.
How do I find a missing angle using the law of cosines (SSS)?
Select SSS mode and enter all three side lengths: a, b, and c. The calculator applies C = arccos((a² + b² − c²) / (2ab)) and returns angle C in degrees. For example, with sides a = 5, b = 7, and c = 8, the result is C = arccos((25 + 49 − 64) / 70) = arccos(10/70) ≈ 81.8°. All three side lengths must satisfy the triangle inequality, meaning each side must be less than the sum of the other two.
What is the difference between the law of sines and the law of cosines?
The law of sines (a/sin A = b/sin B = c/sin C) is most efficient for AAS and ASA configurations, where a known angle is paired directly with its opposite side. The law of cosines handles SAS and SSS cases and avoids the ambiguous-case problem that emerges with the law of sines when two sides and a non-included angle are given. For any SSS problem, the law of cosines provides a single, unambiguous solution with no additional case analysis required.
Can the law of cosines be used for right triangles?
Yes, the law of cosines works perfectly for right triangles. When angle C equals exactly 90°, cos(90°) = 0, so the expression c² = a² + b² − 2ab·cos(C) reduces directly to c² = a² + b², which is the Pythagorean theorem. This demonstrates that the Pythagorean theorem is simply a special case of the more general law of cosines. For right triangles both formulas yield identical results, but the law of cosines handles all triangle types without exception.
What are common real-world applications of the law of cosines?
The law of cosines appears across numerous fields: surveyors use it to measure inaccessible boundary distances across terrain; navigators apply it to locate positions from two known bearing lines; structural engineers rely on it to calculate brace lengths in non-rectangular frames; physicists use it to find resultant magnitudes when force vectors act at oblique angles; and computer graphics engines employ it when computing polygon edge angles and 3D mesh geometry. Any discipline involving non-right triangles depends on this formula.