Law of Cosines Calculator: SSS & SAS Triangle Solver

Solve any triangle from three sides (SSS) or two sides and the included angle (SAS) using the law of cosines — get every side, angle, and the area.

Loading calculator…

Law of cosines formulas

The law of cosines relates a triangle's three sides to one of its angles — it works for ANY triangle, not just right triangles:

a2=b2+c22bccosAb2=a2+c22accosBc2=a2+b22abcosCa^2 = b^2+c^2-2bc\cos A \qquad b^2 = a^2+c^2-2ac\cos B \qquad c^2 = a^2+b^2-2ab\cos C

This calculator solves it both ways:

KnownSolve forFormula
Three sides (SSS)Any angleA=cos1 ⁣(b2+c2a22bc)A = \cos^{-1}\!\left(\dfrac{b^2+c^2-a^2}{2bc}\right)
Two sides + included angle (SAS)The third sidec=a2+b22abcosCc = \sqrt{a^2+b^2-2ab\cos C}
Tip: The angle in the SAS formula must be the one BETWEEN the two known sides — CC sits between aa and bb, opposite the side cc being solved. A non-included angle is a different problem (SSA), solved with the law of sines instead.

Solving SSS (three sides)

Example: sides a = 7, b = 8, c = 9

cosA=82+92722(8)(9)=961440.6667A48.19°\cos A = \frac{8^2+9^2-7^2}{2(8)(9)} = \frac{96}{144} \approx 0.6667 \qquad A \approx 48.19°

The same formula, rotated to each side, gives B58.41°B \approx 58.41° and C73.40°C \approx 73.40° (summing to 180°, as every triangle's angles must). With all three sides already known, Heron's formula gives the area directly: K26.83K \approx 26.83.

Solving SAS (two sides + included angle)

Example: sides a = 5, b = 7, included angle C = 60°

c=52+722(5)(7)cos60°=7470(0.5)=396.245c = \sqrt{5^2+7^2-2(5)(7)\cos 60°} = \sqrt{74-70(0.5)} = \sqrt{39} \approx 6.245

Once cc is known, the remaining two angles follow from the law of cosines again (or the law of sines, now that a side/angle pair exists), and the area comes from K=12absinC=12(5)(7)sin60°15.16K = \tfrac{1}{2}ab\sin C = \tfrac{1}{2}(5)(7)\sin 60° \approx 15.16.

Tip: A SAS included angle of exactly 90° makes cosC=0\cos C = 0, and the formula collapses to the plain Pythagorean theorem — try a = 3, b = 4, C = 90° and check that c comes out to exactly 5.

Common mistakes

  • Using a non-included angle in the SAS formula. If the angle isn't the one between the two given sides, the law of cosines as written doesn't apply — that's the SSA case instead, handled by the law of sines (and possibly two solutions).
  • Dropping the minus sign. Forgetting the 2bccosA-2bc\cos A term (or its sign) is the single most common algebra slip with this formula.
  • Entering side lengths that fail the triangle inequality. Each side must be shorter than the sum of the other two — sides like 1, 1, 10 can't close into a triangle at all.

Where this shows up

  • Surveying and navigation: finding a distance across an obstacle by measuring two legs and the angle between them.
  • Physics: combining two vectors at an arbitrary angle — the resultant's magnitude is exactly a law-of-cosines problem.
  • Engineering and construction: any layout problem with a known angle that isn't 90°, where the plain Pythagorean theorem doesn't apply.

The law of cosines is the direct generalization of the Pythagorean theorem to any triangle, and it shares the same underlying idea as the right triangle calculator's side-solving — just without requiring a 90° angle. Paired with the law of sines and the triangle angle-sum rule, it's one of the core tools for solving any triangle from partial information.

Frequently asked questions

What is the law of cosines?
A relationship between a triangle's three sides and one of its angles: a2=b2+c22bccosAa^2 = b^2+c^2-2bc\cos A (and the two sibling versions for bb and cc). It generalizes the Pythagorean theorem to triangles that aren't right triangles.
When do I use the law of cosines instead of the law of sines?
Use the law of cosines when you know all three sides (SSS) or two sides and the angle between them (SAS) — neither case gives you a side/angle pair to set up a law-of-sines ratio. The law of sines instead handles ASA/AAS/SSA.
How do I find an angle from three known sides (SSS)?
Rearrange the formula to solve for the angle: A=cos1 ⁣(b2+c2a22bc)A = \cos^{-1}\!\left(\frac{b^2+c^2-a^2}{2bc}\right). For sides 7, 8, 9 this gives A48.19°A \approx 48.19°; the other two angles follow the same way, and the third can also just be 180°180° - the other two.
How do I find the third side from two sides and the included angle (SAS)?
Use c=a2+b22abcosCc = \sqrt{a^2+b^2-2ab\cos C}, where CC is the angle BETWEEN the two known sides aa and bb. For a=5a=5, b=7b=7, C=60°C=60°: c=25+4970(0.5)=396.245c = \sqrt{25+49-70(0.5)} = \sqrt{39} \approx 6.245.
Why must the angle be the one BETWEEN the two given sides?
The law of cosines derivation drops a perpendicular from the vertex between the two known sides — it only works when that vertex's angle is the one you plug in. Using a non-included angle with two sides is a different case (SSA), which the law of sines handles instead (and which can have zero, one, or two solutions).
Why do some three side lengths not form a triangle at all?
The triangle inequality: each side must be shorter than the sum of the other two. Sides 1, 1, and 10 fail this (10 ≥ 1+1), so no such triangle exists — the calculator flags it as invalid rather than returning a nonsensical angle.
How is the area found once the triangle is solved?
With all three sides known (SSS), Heron's formula gives the area directly from the sides and the semi-perimeter. With SAS, the simpler K=12absinCK = \tfrac{1}{2}ab\sin C uses the two given sides and their included angle.
Is the law of cosines related to the Pythagorean theorem?
Yes — it's the general case. When the angle is exactly 90°, cos90°=0\cos 90° = 0, and a2=b2+c22bccosAa^2=b^2+c^2-2bc\cos A collapses to a2=b2+c2a^2=b^2+c^2, exactly the Pythagorean theorem.

Related calculators