Law of Cosines Calculator
Solve SAS (two sides + the included angle) or SSS (three sides) with c² = a² + b² − 2ab·cos C — plus area, perimeter, inradius, circumradius and a scaled diagram.
What is the law of cosines?
The law of cosines — sometimes called the cosine rule — is the generalisation of the Pythagorean theorem to every triangle, not just right ones. For any triangle with sides a, b, c and the angle C opposite side c:
Law of Cosines — solving for sides a, b, and c
Law of Cosines — solving for angles A, B, and C
Triangle characteristics from the solved sides
It handles the two cases where the law of sines can't get started: SAS (you know two sides and the angle between them, and want the third side), and SSS (you know all three sides and want the angles). Once one angle is out, the other two follow from a second application of the same rule and the 180° angle-sum rule.
Law of cosines, case by case
SAS — two sides and the angle between them
When you know two sides and the angle they form at their common vertex, the law of cosines gives you the third side in a single step. Square the two known sides, subtract 2ab · cos C, and take the square root.
SSS — three sides
When all three sides are known, rearrange the law of cosines to solve for each angle. Apply it twice (once for A, once for B) and close the triangle with the angle-sum rule. The triangle inequality is checked first so impossible inputs are caught immediately.
Reading a negative cosine
arccos returns values from 0° to 180°, so a positive cosine gives an acute angle and a negative cosine gives an obtuse one. In SSS this is how you spot an obtuse triangle without any extra work — the biggest side always sits opposite the biggest angle, and its cosine sign tells you whether that angle is under or over 90°.
The Pythagorean special case
Set C = 90° in the law of cosines. cos 90° = 0, so the −2ab · cos C term drops out and you're left with c² = a² + b² — exactly the Pythagorean theorem. That's the sanity check: any law-of-cosines answer on a right triangle should reduce to Pythagoras.
Law of sines vs. law of cosines — when to use which
| You know… | Use | Why |
|---|---|---|
| Two sides + included angle (SAS) | Law of cosines | Direct formula for the third side; no matched side–angle pair for the sine ratio. |
| Three sides (SSS) | Law of cosines | Rearranged form gives each angle from its opposite side and the two adjacent ones. |
| Two angles + included side (ASA) | Law of sines (see Law of Sines Calculator) | Third angle from angle-sum; then a/sin A = b/sin B ratios. |
| Two angles + non-included side (AAS) | Law of sines | The known side is opposite one of the known angles. |
| Two sides + non-included angle (SSA) | Law of sines (ambiguous) | Handled with explicit no / one / two triangle classification. |
| One angle = 90° | Right-triangle trig (Right Triangle Calculator) | Faster with sine/cosine/tangent and the Pythagorean theorem. |
Proofs
Four independent ways to arrive at c² = a² + b² − 2ab · cos C. Each starts from a different piece of geometry, and they all reduce to the same identity — a useful reminder that the law of cosines is a genuine theorem of Euclidean geometry, not just a convenient formula.
(a) Trigonometric proof — drop an altitude
Drop the altitude h from vertex A onto side a (= BC), meeting it at foot F. This splits the triangle into two right triangles sharing the leg h.
Apply the Pythagorean theorem to the right triangle ABF:
The Pythagorean identity sin²C + cos²C = 1 collapses the two trig terms into a single b². The proof works unchanged when C is obtuse — the foot F just lands outside segment BC and the sign takes care of itself.
(b) Distance-formula proof — place the triangle in coordinates
Put vertex C at the origin and side a along the positive x-axis, so B = (a, 0). Vertex A sits at angle C from the x-axis at distance b, so A = (b · cos C, b · sin C).
The side c is the distance from A to B:
Same identity, no picture-drawing needed — just the distance formula and sin² + cos² = 1.
(c) Ptolemy's theorem — via a cyclic quadrilateral
Inscribe triangle ABC in its circumscribed circle. Reflect vertex A across the perpendicular bisector of BC to get a fourth point A′ on the circle, forming the cyclic quadrilateral A′BAC. By construction A′C = c and A′B = b, so the diagonals are the chord AA′ and the side BC = a.
Ptolemy's theorem for a cyclic quadrilateral says the product of the diagonals equals the sum of the products of opposite sides. Applying the extended law of sines (AA′ = 2R · sin ∠ABA′) and expanding ∠ABA′ = ∠ABC + ∠A′BC gives, after simplifying with sin(x + y) = sin x cos y + cos x sin y:
Ptolemy's theorem is itself a corollary of the inscribed-angle theorem, so this route grounds the law of cosines directly in circle geometry.
(d) Vector / dot-product proof
Treat the sides as vectors from vertex C: let a point to B and b point to A. Then the side c runs from A to B, so as vectors c = a − b.
Take the dot product of c with itself:
Since |a| = a, |b| = b and |c| = c are the side lengths, that's exactly c² = a² + b² − 2ab · cos C. The −2ab · cos C term is literally the dot product of the two side vectors meeting at C.
Where you'll actually use it
Surveying and triangulation. Land surveyors frequently know the distance to two landmarks and the angle between the sight lines but not the distance between the landmarks themselves. That's a textbook SAS setup — the law of cosines gives the missing distance in one calculation without planting a physical baseline between the two points.
Navigation. If a ship or aircraft knows its distances to two known reference stations and the angle between them, it can compute the direct distance between the stations or triangulate its own position from three ranges. GPS receivers do a three-dimensional version of exactly this every time they fix a position from satellite ranges.
Resultant forces in physics. Two forces acting at a common point form the two sides of a parallelogram; the resultant is the diagonal. The law of cosines gives its magnitude directly from |F₁|, |F₂| and the angle between them — no vector decomposition required. The same trick handles velocities, momenta and any other vector quantities that combine head-to-tail.
Worked examples
SAS worked example — a = 8 cm, b = 11 cm, C = 37°
SSS worked example — a = 7, b = 9, c = 12
What this tool does for you
- Solves both SAS (two sides + included angle) and SSS (three sides) using c² = a² + b² − 2ab·cos C and its rearranged form.
- Returns every derived value in one pass: all three sides, all three angles, area (Heron's formula), perimeter, semiperimeter, inradius r = Area/s and circumradius R = abc/(4·Area).
- Checks the triangle inequality on SSS input and rejects impossible side triples with a clear explanation instead of returning NaN.
- Draws the solved triangle to scale from the computed side lengths with vertices, sides and angles all labelled.
- Accepts degrees or radians for angle input, and a display-only length-unit selector (mm, cm, m, km, in, ft, yd, mi) so results are labelled correctly.
- Configurable significant figures (3 – 8) so short-form and high-precision answers can be produced from the same input.
- Prints personalised step-by-step working with your own numbers substituted into the formula — handy for showing your work on homework.
- Copy result / download PNG / download PDF / print, using the shared result actions available across the site.
Frequently asked questions
+What is the law of cosines?
The law of cosines relates the three sides of any triangle to the cosine of one of its angles: c² = a² + b² − 2ab · cos C. Rearranged, it also lets you recover any angle from all three sides: cos C = (a² + b² − c²) / (2ab). It works for every triangle — acute, right or obtuse — and reduces to the Pythagorean theorem when the included angle is exactly 90°.
+When should I use the law of cosines instead of the law of sines?
Reach for the law of cosines when your known values do not pair a side with its opposite angle — that's SAS (two sides plus the angle between them) and SSS (all three sides). The law of sines needs a matched side–angle pair to anchor the ratio, so it can't get started in those cases. Use the law of sines for ASA, AAS and the SSA ambiguous case instead.
+How does the law of cosines relate to the Pythagorean theorem?
It's a direct generalisation. When C = 90°, cos C = 0 and the −2ab · cos C term vanishes, leaving c² = a² + b² — exactly Pythagoras. For C < 90° the extra term is subtracted and c is shorter than the Pythagorean prediction; for C > 90° cos C is negative, the extra term adds, and c is longer. The law of cosines simply corrects Pythagoras by an amount that depends on how far the included angle is from a right angle.
+What does a negative cosine result mean?
It means the angle is obtuse — larger than 90°. arccos maps positive cosines to acute angles (0–90°) and negative cosines to obtuse angles (90°–180°), so seeing cos A = −0.42 tells you A ≈ 114.8°. There is no ambiguity in the SSS or SAS cases: each side gives one and only one angle, so the sign of the cosine is enough to identify obtuse triangles.
+Why is my SSS triangle rejected as invalid?
Because the three lengths violate the triangle inequality: the sum of the two shorter sides must be strictly greater than the longest side. If side c ≥ a + b, the two shorter sides can't close the gap to form a triangle — no set of angles will work. The calculator checks this before running arccos so you get a clear message instead of a NaN.
+Where does the −2ab · cos C term come from?
From the vector identity |c|² = |b − a|² = |b|² − 2 a · b + |a|², where a · b = |a| |b| cos C is the dot product of the two side vectors meeting at C. Written with side lengths, that's c² = a² + b² − 2ab cos C. The proofs section on this page walks through the same result three other ways — dropping an altitude, placing the triangle in coordinates and using Ptolemy on a cyclic quadrilateral.