Law of Cosines Calculator

Enter sides a and b and the included angle γ (SAS). The calculator finds the third side c = √(a² + b² − 2ab·cos γ). With 3, 4 and 90° you get 5 — the same 3-4-5 as Pythagoras. With 7, 8 and 120° you get 13. Degrees or radians. This is not an angle from three sides (SSS), and not the ambiguous SSA case.

Input data

Result

Enter sides a, b and angle γ.

γ is the included angle between a and b (SAS), not an angle opposite c under SSS labeling. You need a > 0, b > 0. Area from three sides is on Heron’s formula.

How it works

How c is computed for a = 3, b = 4, γ = 90°
a²+b²25
cos 90°0
c5

The law of cosines generalizes the Pythagorean theorem to an arbitrary included angle. When you know sides a and b and the included angle γ (SAS), the third side opposite γ is c = √(a² + b² − 2ab·cos(γ)). The calculator uses the numbers you enter and the angle-unit switch. In degrees the calculator computes cos(γ·π/180); in radians it uses cos(γ) with no conversion.

At γ = 90° the cosine vanishes and the formula recovers Pythagoras: c² = a² + b². So 3, 4 and 90° give c = 5. An acute angle (e.g. 60°) shortens c versus √(a² + b²); an obtuse angle (e.g. 120°) lengthens c because cosine is negative. With 5, 5 and 60° you get an equilateral triangle, and the calculator shows c = 5.

Domain: a > 0, b > 0, and γ ∈ (0, π) — any other angle gives an error message. The radicand must be non-negative. Period and comma in the fields are equivalent. An empty field leaves the result blank.

A standard derivation places a along an axis, puts the tip of b at (b cos γ, b sin γ), and reads c from the distance formula. Equivalently, the dot product a·b = |a||b|cos γ. Euclid’s Elements II.12–13 treat obtuse and acute cases; the modern trigonometric statement is textbook standard (often called Al-Kashi’s theorem).

The result panel also shows c², cos γ, sin γ, area (½)ab|sin γ|, perimeter, and angle kind. The diagram draws the SAS triangle with side c highlighted. This calculator does not solve SSA or find an angle from three sides — only c from a, b, and γ.

Mathematical model: the law of cosines (Al-Kashi / Euclid II.12–13 in trigonometric form). Not a custom index — just side c from SAS.

Formula

c² = a² + b² − 2ab · cos(γ), then c = √(a² + b² − 2ab · cos(γ)).

Symbols: a, b — sides adjacent to the angle; γ — included angle; c — side opposite γ. In degrees: cos(γ°·π/180). In radians: cos(γ) with no conversion.

Model: law of cosines (Al-Kashi; Euclid II.12–13 in trigonometric form). At γ = 90° you recover the Pythagorean theorem.

Theory, projection, and Euclid

Definition

The law of cosines relates the three sides of a triangle to the cosine of one angle. With sides a, b and included angle γ (opposite side c), c² = a² + b² − 2ab cos γ, hence c = √(a² + b² − 2ab cos γ) when the radicand is nonnegative. This calculator computes side c from SAS data: fields a, b and angle γ (degrees or radians), matching calculator-twierdzenie-cosinusow-bok.js: radicand = a·a + b·b − 2·a·b·cos(rad).

When γ = 90°, cos γ = 0 and the formula reduces to Pythagoras: c² = a² + b². When γ < 90°, cos γ > 0 and c² < a² + b²; when γ > 90°, cos γ < 0 and c² > a² + b². The panel also shows cos γ, sin γ, and area (1/2)ab|sin γ|.

Practical domain: a > 0, b > 0, γ ∈ (0, π). A negative radicand means no real side c for those inputs.

Historical and conceptual context

The law of cosines generalizes Pythagoras to an arbitrary angle. Euclidean precursors appear in Elements II.12–13 (acute and obtuse cases separately); the modern cosine form is standard trigonometry (MathWorld — Law of Cosines; Wikipedia — Law of cosines; CRC / Zwillinger).

Conceptually it is the Euclidean metric identity in a triangle: the dot product of sides yields a·b cos γ. This page solves the “side opposite the angle” variant (SAS → third side), not the inverse “angle from three sides” (SSS → arccos).

In navigation and surveying the law links lengths to bearings; in school it bridges geometry and trigonometry.

Formal properties

Domain: a > 0, b > 0, γ ∈ (0, π); a real result needs a² + b² − 2ab cos γ ≥ 0. Codomain: c ≥ 0.

Identities: c² = a² + b² − 2ab cos γ; and cyclic permutations. At γ = π/2: c² = a² + b². SAS area: Δ = (1/2)ab|sin γ|.

Continuity: c(γ) is continuous on (0, π) for fixed a, b > 0. Symmetry: a and b enter symmetrically.

Vector form: if the side vectors from the γ-vertex are u and v, then |u − v|² = |u|² + |v|² − 2 u·v = a² + b² − 2ab cos γ with a = |u|, b = |v|. That matches the coordinate derivation.

Area Δ = (1/2)ab|sin γ| links SAS to altitude; as γ → 0 or γ → π the area vanishes and c tends to |a−b| or a+b respectively. The calculator shows sin and cos beside c so the sign of cosine (acuteness) is visible.

Degree/radian conversion happens before cos. Comma and period parse identically in a, b, and γ fields.

Full derivation

Step 1. Place angle γ at the origin; side a along the x-axis, side b at angle γ. Endpoint of b: (b cos γ, b sin γ); endpoint of a: (a, 0).

Step 2. Distance between endpoints: c² = (b cos γ − a)² + (b sin γ)² = a² + b² − 2ab cos γ.

Step 3. Take c = √(radicand) when radicand ≥ 0. In the calculator: √ after a sign check.

Step 4. Case γ = π/2: cos = 0 ⇒ Pythagoras. Case a = b, γ = π/3: c = a (equilateral).

Worked checks: a = 3, b = 4, γ = 90° → c = 5 (Pythagoras); a = b = 5, γ = 60° → c = 5 (equilateral); a = 7, b = 8, γ = 120° → c = 13. Together they probe cos γ = 0, cos γ > 0, and cos γ < 0 inside c = √(a²+b²−2ab cos γ).

Special cases

a = 3, b = 4, γ = 90°: c = 5 (3-4-5). a = b = 5, γ = 60°: c = 5 (equilateral). a = 7, b = 8, γ = 60°: c = √57 ≈ 7.549834.

a = 7, b = 8, γ = 120°: cos 120° = −1/2, c = 13. a = 9, b = 12, γ = 90°: c = 15.

When the radicand is negative, the page reports that no real c exists instead of treating NaN as a valid OK result.

Numerical and computational notes

The angle is converted to radians before cos. Float64 is enough for school sides; near γ ≈ 0, cancellation toward |a−b| can be sensitive, but typical examples (45°–120°) are stable.

Examples cover 3-4-5, equilateral, and obtuse cases. The SVG scales sides; drawing scale does not change c. A comma and a period are equivalent.

The inverse law cos γ = (a² + b² − c²)/(2ab) recovers an angle from SSS; this page does not take that as the primary result, but the identity is algebraically equivalent after squaring c. If |cos γ| > 1, SSS data do not form a real triangle — analogous to a negative SAS radicand.

Examples 3-4-5 and c = 13 at 120° illustrate opposite cosine signs. An angle γ outside (0, π) is rejected with an error message, even when the radicand would stay non-negative (for example γ = 270° or −60°).

Sides a and b must use a common length unit; c inherits that unit. Degrees and radians apply only to γ. The SVG scales the drawing independently of the numeric result.

Related concepts and authorities

Related: law of sines a/sin A = 2R, Pythagoras, third angle γ = 180° − α − β when angles are known.

Authorities: MathWorld — Law of Cosines; Wikipedia — Law of cosines; Euclid II.12–13; CRC / Zwillinger. The calculator computes c = √(a²+b²−2ab cos γ).

How to use

  1. Enter side a (e.g. 3) and side b (e.g. 4) — both positive lengths.
  2. Enter the included angle γ (e.g. 90) and choose Degrees or Radians.
  3. Click Calculate or wait for the live result. 3, 4 and 90° give 5. 5, 5 and 60° also give 5.
  4. Check the panel: c², cos γ, area, perimeter, and the triangle diagram with side c.
  5. When you know one side and two angles, go to the law of sines. Area from three sides — Heron.

Symbol glossary

c = √(a² + b² − 2ab cos γ). With 3, 4 and 90° side c is 5. With 5, 5 and 60° it is also 5.

c
Side opposite angle γ. Primary result. 3-4-90 gives 5. 7-8-60 gives ≈ 7.549834.
a, b
Sides adjacent to the angle (a > 0, b > 0). Form fields Side a and Side b.
γ
Included angle between a and b. Degrees or radians per the switch. Field twierdzenie-cosinusow-bok-c.
cos γ
Correction term in the formula. At 90° it is 0 (Pythagoras). For an obtuse angle it is negative.

Examples

Example 1

  • a = 3, b = 4, γ = 90°

5

What is c for a=3, b=4, γ=90°? 5 (Pythagoras).

Example 2

  • a = 5, b = 5, γ = 60°

5

What is c for a=5, b=5, γ=60°? 5 (equilateral).

Example 3

  • a = 7, b = 8, γ = 60°

7.549834

What is c for a=7, b=8, γ=60°? ≈ 7.549834.

Example 4

  • a = 7, b = 8, γ = 120°

13

What is c for a=7, b=8, γ=120°? 13.

Example 5

  • a = 5, b = 5, γ ≈ π/3 rad

5

What do a=5, b=5, γ≈π/3 rad give? 5 (same as 60°).

Example 6

  • a = 6, b = 6, γ = 60°

6

What is c for a=6, b=6, γ=60°? 6 (equilateral).

Example 7

  • a = 10, b = 4, γ = 45°

≈ 7.70918

What is c for a=10, b=4, γ=45°? ≈ 7.70918.

Example 8

  • a = 9, b = 12, γ = 90°

15

What is c for a=9, b=12, γ=90°? 15 (9-12-15).

Related calculators

Common questions

What does this calculator compute?

The missing side c opposite angle γ when you know sides a and b and the included angle γ between them (SAS). Formula: c = √(a² + b² − 2ab·cos(γ)). For a = 3, b = 4 and γ = 90° the result is 5. This page does not solve SSA or find an angle from three sides.

How do I switch the angle between degrees and radians?

In “Angle in”, choose Degrees (°) or Radians. Degrees: the calculator multiplies γ by π/180 before cosine. Radians: cosine uses γ with no conversion. Example 5: a = 5, b = 5, γ ≈ π/3 rad gives the same c as 60°.

How does the law of cosines recover Pythagoras?

When γ = 90° (π/2 rad), cos γ = 0, so the −2ab·cos(γ) term vanishes and you are left with c² = a² + b². For 3, 4 and 90° the calculator returns c = 5 — the same 3-4-5 triangle.

Which angle do I enter?

The included angle γ between sides a and b (the third field). That is the angle at the common vertex of those sides, not an “opposite c” angle under another SSS labeling. The field is labeled “Angle γ”.

What is the domain for a, b, and γ?

You need a > 0 and b > 0. The angle γ must lie in (0, π). At γ = 0 or π the figure collapses to a segment, and an angle outside that range is not a triangle angle — the calculator then reports an error. The expression under the square root must be non-negative — otherwise a real side c does not exist.

What happens with an empty field or a ≤ 0?

An empty a, b, or angle leaves the result blank. A side ≤ 0 is rejected with a message — side length in this model must be positive.

Does an obtuse angle lengthen side c?

Yes. For γ > 90° cosine is negative, so −2ab·cos(γ) adds to a² + b² and c is longer than for an acute angle with the same a, b. For 7, 8 and 120° the result is 13; for 7, 8 and 60° ≈ 7.549834.

Does this solve the ambiguous SSA case?

No. This page uses two sides and the included angle (SAS). SSA, where two sides and a non-included angle can yield two triangles, is not here. The ratio a/sin α = b/sin β is on the law of sines page.

Do the currency and unit settings in the page header affect the result?

No. The result depends only on a, b, the angle, and the degrees/radians switch in the form. The currency and unit settings in the page header do not affect this result.

Where do I compute area from three sides or a side from two angles?

Area from three sides is on Heron’s formula. A side from one side and two angles is on the law of sines. Pythagoras is nearby when the angle is right and you know the two legs.

Why do 5, 5 and 60° give exactly 5?

On paper cos 60° = 1/2 exactly, so c = 5. In floating-point arithmetic cos(60·π/180) returns 0.5000000000000001, so the raw square root is 4.999999999999999. The calculator rounds the result to six decimal places and drops trailing zeros, so you see 5.

Where does c² = a² + b² − 2ab·cos(γ) come from?

From projecting one side onto the other and applying Pythagoras in right triangles, or from the distance formula / dot product in coordinates. Euclid II.12–13 covers obtuse and acute cases; the modern trigonometric form is Al-Kashi’s theorem in standard trig texts.

How do I find a side with the law of cosines?

With two sides a, b and included angle γ: c = √(a² + b² − 2ab·cos γ). For 3, 4 and 90°, c = 5; for 7, 8 and 120°, c = 13.

What is c for a=5, b=7, γ=60°?

√39 ≈ 6.244998. Formula: c = √(25 + 49 − 2·5·7·cos 60°) = √(74 − 35) = √39.

Does this find an angle from three sides?

No. Here you only get side c from SAS. The SSS angle is γ = arccos((a² + b² − c²)/(2ab)) — a separate rearrange, not on this page.

How does this differ from the law of sines?

Here two sides and the included angle give the third side. The law of sines links a side to the sine of the opposite angle (a/sin α = b/sin β) and covers AAS/ASA cases.

What is c for a=7, b=8, γ=120°?

13. That is the fourth example on this page: an obtuse angle lengthens c versus the 60° version.

The result is c = √(a² + b² − 2ab cos γ): for a = 3, b = 4 and 90° the side is 5. At a right angle the formula recovers Pythagoras.

Knowledge sources

The formula, derivation, and history below come from recognized sources.

Page updated November 3, 2026.