Law of Cosines Calculator
Solve any oblique triangle for missing sides, angles, perimeter, and area using the Law of Cosines. Supports SAS and SSS configurations with dynamic 2D geometric triangle plots.
If you have two angles (AAS/ASA) or two sides and a non-included angle (SSA), use our companion Law of Sines solver.
Geometry Plot & Oblique Triangle
c² = a² + b² − 2ab·cos(C)Step-by-Step Law of Cosines Derivation Formula: c² = a² + b² − 2ab·cos(C)
How to Solve a Triangle Using the Law of Cosines
To solve an oblique triangle using the Law of Cosines, choose the formula variant matching your known data. For SAS (two sides a, b and included angle C), compute the opposite side c = √[a² + b² - 2ab·cos(C)]. For SSS (three known sides), solve any angle by isolating the cosine: cos(A) = (b² + c² - a²) / (2bc) and applying arccos. Find the second angle via the Law of Sines/Cosines, then subtract from 180° for the third angle.
The Law of Cosines Formula & Generalized Pythagorean Theorem
The Law of Cosines (also known as the cosine rule) connects the three sides of any triangle with the cosine of one of its angles:
Solving Side-Angle-Side (SAS) Triangles
In an SAS triangle, you know two sides and the angle trapped between them:
- Step 1: Apply the Law of Cosines to find the third opposite side: $c = \sqrt{a^2 + b^2 - 2ab\cos(C)}$.
- Step 2: Use the Law of Cosines or Sines to find the smaller of the remaining two angles (always acute).
- Step 3: Find the final angle via $B = 180^\circ - A - C$.
Solving Side-Side-Side (SSS) Triangles
When all three side lengths $a, b, c$ are given, isolate the cosines:
cos(A) = (b² + c² − a²) / (2bc)
Tip: Always solve for the largest angle first (opposite the longest side). If $\cos(\text{Angle}) < 0$, the angle is obtuse; the remaining two angles are guaranteed to be acute.
Computing Area with Heron's Formula & Sine Area
Once the triangle is solved, the area can be computed using either method:
Fastest for SAS configurations.
Where semi-perimeter $s = (a+b+c)/2$.
Comparing Law of Sines vs Law of Cosines
The two laws complement each other perfectly:
- Law of Cosines: Handles SSS and SAS where no angle-opposite-side pair is known initially.
- Law of Sines: Handles AAS, ASA, and SSA where at least one matching angle-side pair is known.
Step-by-Step Worked Examples (SAS & SSS Cases)
Solve triangle with a = 8, b = 11, C = 37°.
1. c² = 8² + 11² − 2(8)(11) cos(37°) = 64 + 121 − 176(0.7986) = 185 − 140.56 = 44.44.
2. c = √44.44 ≈ 6.67.
3. cos(A) = (11² + 6.67² − 8²) / (2 × 11 × 6.67) = (121 + 44.44 − 64) / 146.74 = 101.44 / 146.74 ≈ 0.6913 → A = 46.26°.
4. B = 180° − 46.26° − 37° = 96.74°.
Common Pitfalls & Negative Cosine Evaluation
In $a^2 + b^2 - 2ab\cos(C)$, do NOT compute $(a^2 + b^2 - 2ab) \times \cos(C)$. Multiplication has higher precedence; compute $(2ab\cos C)$ first before subtracting from $(a^2 + b^2)$.
If an angle is obtuse ($C > 90^\circ$), $\cos(C)$ is negative. The $-2ab\cos(C)$ term becomes a positive addition: $c^2 = a^2 + b^2 + 2ab|\cos C|$.
Lead Developer & Founder of Basic Math Tools. Specializes in browser-native computational algorithms and applied mathematics.
Mathematics & curriculum specialists. Audited against standard algebraic and arithmetic principles.