Report

Help us improve this tool

Law of Cosines Calculator

Solve any triangle using the Law of Cosines (SSS, SAS, SSA). Calculate unknown side lengths, angles, triangle area, perimeter, and step-by-step formulas.

O M T

Understanding the Law of Cosines

The Law of Cosines (also called the cosine rule or generalized Pythagorean theorem) is a fundamental theorem in trigonometry that relates the lengths of the sides of any arbitrary triangle to the cosine of one of its interior angles. While the standard Pythagorean theorem only applies to right triangles, the Law of Cosines solves oblique (non-right) triangles.

Use this calculator to find missing side lengths, determine interior angles, or verify triangle geometry alongside our Triangle Calculator and Right Triangle Calculator.

The Law of Cosines Formulas

In any triangle with side lengths \(a\), \(b\), and \(c\), and opposite interior angles \(\alpha\) (at vertex \(A\)), \(\beta\) (at vertex \(B\)), and \(\gamma\) (at vertex \(C\)):

$$c^2 = a^2 + b^2 - 2ab \cos(\gamma)$$

$$b^2 = a^2 + c^2 - 2ac \cos(\beta)$$

$$a^2 = b^2 + c^2 - 2bc \cos(\alpha)$$

Solving Triangle Configurations

1. Two Sides and Included Angle (SAS)

When you know two sides (e.g., \(a\) and \(b\)) and the angle between them (\(\gamma\)):

  1. Compute the opposite third side: \(c = \sqrt{a^2 + b^2 - 2ab \cos(\gamma)}\).
  2. Compute a second angle using the Law of Cosines: \(\cos(\alpha) = \frac{b^2 + c^2 - a^2}{2bc}\).
  3. Calculate the third angle using triangle angle sum: \(\beta = 180^\circ - \alpha - \gamma\).

2. Three Sides (SSS)

When all three side lengths (\(a\), \(b\), and \(c\)) are known and satisfy the triangle inequality (\(a + b > c\), \(a + c > b\), and \(b + c > a\)):

$$\alpha = \arccos\left(\frac{b^2 + c^2 - a^2}{2bc}\right)$$

$$\beta = \arccos\left(\frac{a^2 + c^2 - b^2}{2ac}\right)$$

$$\gamma = \arccos\left(\frac{a^2 + b^2 - c^2}{2ab}\right)$$

Worked Example: Solving an SAS Triangle

Suppose a triangle has side \(a = 5\text{ cm}\), side \(b = 7\text{ cm}\), and included angle \(\gamma = 60^\circ\).

  1. Evaluate \(\cos(60^\circ) = 0.5\).
  2. Apply the cosine rule: \(c^2 = 5^2 + 7^2 - 2(5)(7)(0.5) = 25 + 49 - 35 = 39\).
  3. Find side \(c\): \(c = \sqrt{39} \approx 6.245\text{ cm}\).
  4. Find angle \(\alpha\): \(\cos(\alpha) = \frac{7^2 + 39 - 5^2}{2(7)(6.245)} = \frac{49 + 39 - 25}{87.43} = \frac{63}{87.43} \approx 0.7206 \implies \alpha \approx 43.9^\circ\).
  5. Find angle \(\beta\): \(\beta = 180^\circ - 60^\circ - 43.9^\circ = 76.1^\circ\).

Frequently Asked Questions

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

Use the Law of Cosines when given SAS (two sides and the included angle) or SSS (three side lengths). Use the Law of Sines when given AAS/ASA (two angles and one side) or SSA with known opposite pairs.

What happens if the Law of Cosines produces a cosine value outside [-1, 1]?

If the computed cosine value is strictly greater than 1 or less than -1, no Euclidean triangle can exist with those side lengths because the triangle inequality is violated.

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

When the angle is a right angle (\(\gamma = 90^\circ\)), \(\cos(90^\circ) = 0\). The formula \(c^2 = a^2 + b^2 - 2ab(0)\) reduces directly to \(c^2 = a^2 + b^2\).