Law of Cosines Calculator
Free law of cosines calculator: enter two sides and the included angle to find the third side, area, and perimeter, with full worked steps.
Law of Cosines Calculator
Background.
The law of cosines calculator solves the single most common oblique-triangle question there is: given two sides and the angle wedged between them, what is the length of the third side? Enter side a = 5, side b = 7, and an included angle of 60°, and the calculator returns c = √39 ≈ 6.245 in one step, along with the triangle's area and perimeter, using the formula c² = a² + b² − 2ab·cos(C) — the generalization of the Pythagorean theorem to triangles that don't have a right angle.
That generalization is exactly the reason the law of cosines matters. The Pythagorean theorem, a² + b² = c², only applies when the angle between a and b happens to be exactly 90°, which is a special case rather than the general rule. Most real triangles — a plot of land, a surveying triangle, a truss in a roof, a triangle formed by three cell towers — do not have a convenient right angle sitting inside them. The law of cosines removes that restriction entirely: subtract 2ab·cos(C) from a² + b², and the formula works for every triangle, acute, right, or obtuse, collapsing back to the familiar a² + b² = c² only when C happens to be 90° and cos(C) happens to be 0. This calculator makes that relationship visible directly — its worked example below can be re-run with the angle set to exactly 90° to reproduce the Pythagorean theorem's own 3-4-5 triangle, side for side.
This tool deliberately does one thing rather than several. Quanta already has a full triangle solver that handles SSS, SAS, and ASA input and returns every side, every angle, the area, and the perimeter in one pass — the right tool when you want the entire triangle solved regardless of which three measurements you started with. This calculator is narrower on purpose: it is the law of cosines itself, applied to the specific and extremely common "two sides and the angle between them" (SAS) case, returning the missing side directly along with the two quantities — area and perimeter — that fall out of the same three known inputs without any further trigonometry. If you need the two remaining angles as well, or you are working from three known sides instead and need to find an angle, the full triangle solver is the better tool, and it is linked from this page.
The angle you enter must be the included angle — the one sitting between the two sides you know, not the angle opposite either of them. Mixing that up is the single most common error when applying the law of cosines by hand, and it produces a triangle that looks plausible but is actually wrong, because the formula genuinely requires the angle between a and b, not some other angle in the figure. The calculator also enforces that the angle is strictly between 0° and 180°, since a 0° or 180° angle would collapse the triangle into a straight line with no interior area at all — a degenerate case rather than a genuine triangle.
What is law of cosines calculator?
The law of cosines is a formula relating the three sides of any plane triangle to the cosine of one of its angles: c² = a² + b² − 2ab·cos(C), where C is the angle opposite side c and is wedged directly between sides a and b. It generalizes the Pythagorean theorem, which is the special case where C = 90°: since cos(90°) = 0, the last term vanishes entirely and the formula reduces to c² = a² + b². For any other angle, the correction term 2ab·cos(C) accounts for how much the triangle deviates from having a right angle at C — subtracting when C is acute (cos C positive, making c shorter than the right-angle case) and adding when C is obtuse (cos C negative, making c longer). The relationship was known geometrically to Euclid, who proved both the obtuse and acute cases (Elements, Book II, Propositions 12 and 13) using areas of rectangles rather than trigonometric notation, centuries before the cosine function was formalized. Today the law of cosines is one of the two workhorse formulas of triangle trigonometry, alongside the law of sines, and it is the standard tool whenever a problem gives you two sides and the angle between them (SAS) and asks for the third side, or gives you all three sides (SSS) and asks for any angle.
How to use this calculator.
- Identify which angle is the included angle — the one physically between the two sides you know, not opposite either of them.
- Enter side a and side b, the two known sides.
- Enter the included angle C in degrees. It must be strictly between 0° and 180°.
- Read the primary result, side c — the missing side opposite the included angle.
- Read the area and perimeter outputs if you need them; both are fully determined by the same three inputs, no extra data required.
- If your included angle is exactly 90°, the result should match the Pythagorean theorem exactly — try the pythagorean calculator with the same two legs as a cross-check.
- If you know three sides instead of two sides and an angle, or you need every angle of the triangle as well as the side, use the triangle solver instead — this calculator is intentionally limited to the two-sides-and-included-angle case.
The formula.
The law of cosines can be derived by placing the included angle C at the origin of a coordinate system, with side b running along the positive x-axis. That puts one vertex at the origin, the vertex at the far end of side b at (b, 0), and the vertex at the far end of side a at (a·cos C, a·sin C), since side a makes angle C with side b. The unknown side c is exactly the distance between the two non-origin vertices, so by the standard distance formula, c² = (b − a·cos C)² + (a·sin C)². Expanding the first term gives b² − 2ab·cos C + a²cos²C, and adding a²sin²C to it gives a²cos²C + a²sin²C = a² (using the Pythagorean identity sin²C + cos²C = 1). Collecting everything: c² = a² + b² − 2ab·cos C — the law of cosines, derived purely from coordinates and the distance formula.
Once c is known, the perimeter is simply a + b + c, no further trigonometry required. The area does not even need c: with two sides and the angle between them already known, the area is (1/2)·a·b·sin(C) directly, the standard SAS area formula (the height of the triangle, dropped from the vertex where a and b meet down to the line containing side... more precisely, b·sin C is the height relative to base a, so (1/2)·base·height = (1/2)·a·(b sin C)).
The special case worth remembering is C = 90°: cos(90°) = 0, so the correction term 2ab·cos(C) disappears entirely and c² = a² + b² — exactly the Pythagorean theorem. That is not a coincidence or an approximation; the Pythagorean theorem is a strict special case of the law of cosines, true only when the included angle happens to be a right angle. For any acute included angle, cos(C) is positive, so c comes out shorter than the Pythagorean value with the same a and b. For any obtuse included angle, cos(C) is negative, so subtracting a negative term adds to the total, and c comes out longer.
A worked example.
Two sides of a triangle measure 5 and 7 units, with an included angle of exactly 60° between them. Since cos(60°) = 0.5 exactly, the law of cosines gives c² = 5² + 7² − 2·5·7·0.5 = 25 + 49 − 35 = 39, so c = √39 ≈ 6.245 units. The area follows from the same three known values: (1/2)·5·7·sin(60°) = 17.5 × (√3/2) ≈ 15.155 square units. The perimeter is 5 + 7 + √39 ≈ 18.245 units. As a sanity check on the special case: if the included angle had been 90° instead of 60° with sides 3 and 4, cos(90°) = 0 makes the formula collapse to c² = 3² + 4² = 25, so c = 5 — exactly the Pythagorean theorem's classic 3-4-5 triangle, area 6, perimeter 12. That check is one of this page's automated test cases, and it is a fast way to confirm the formula is behaving correctly for the right-angle boundary case.
Frequently asked questions.
What is the law of cosines?
How is the law of cosines related to the Pythagorean theorem?
Why doesn't this calculator have an SSS mode for finding an angle from three sides?
What is the "included angle" and why does it have to be between the two known sides?
What happens with an obtuse included angle?
Why must the included angle be strictly between 0° and 180°?
Where does the law of cosines come from?
References& sources.
- [1]Weisstein, Eric W. "Law of Cosines." MathWorld — Wolfram Research.
- [2]Euclid, Elements, Book II, Proposition 12 — the geometric law of cosines for obtuse triangles (Heath translation, Cambridge University Press, 1908).
- [3]Euclid, Elements, Book II, Proposition 13 — the geometric law of cosines for acute triangles.
- [4]NIST Digital Library of Mathematical Functions, §4.21 Identities, eq. 4.21.12 — the Pythagorean identity sin²z + cos²z = 1 used in the coordinate-geometry derivation of the law of cosines.
- [5]Coxeter, H. S. M. Introduction to Geometry, 2nd edition. Wiley, 1969 — classic reference covering the law of cosines, the law of sines, and their relationship to the Pythagorean theorem.
In this category
Embed
Quanta Pro
Paid features are coming later.
- All 313 calculators remain free
- No billing is enabled