What the law of cosines calculator solves
The law of cosines, also called the cosine rule, relates the three sides of a triangle to one of its angles. It works for every Euclidean planar triangle (acute, right, or obtuse), which makes it the standard tool when the sine rule or the Pythagorean theorem cannot be applied directly.
The calculator supports two measurement sets:
| Task | You enter | You get |
|---|---|---|
| SAS: find side c | Sides and and the included angle | The third side |
| SSS: find angle C | Sides , , and | The interior angle |
SAS means "side, angle, side": the angle sits between the two known sides. SSS means all three sides are known. If you only know two sides and an angle that is not between them (SSA), or you know two angles and one side (ASA or AAS), this calculator does not apply. Those cases are usually handled with the law of sines.
The cosine law formula
Label the triangle so that each lowercase side is opposite the uppercase angle with the same letter: side is opposite angle , side is opposite , and side is opposite . Angle is therefore the angle between sides and . With that convention, the cosine law formula is:
The same rule holds for each side, by cycling the letters:
Think of it as the Pythagorean theorem with a correction term. When , , the correction vanishes, and the rule becomes . For other angles the term adjusts the result:
- If is acute, , so is shorter than it would be in the right-angle case.
- If is obtuse, , so is longer.
This holds with and held fixed, and it is a quick way to sanity-check any answer.
Rearranging for an angle (SSS)
When all three sides are known, solve the formula for the cosine and take the inverse cosine:
The other two angles follow the same pattern:
Inverse cosine returns values from to , so it correctly yields obtuse interior angles. This is a real advantage over the sine rule, where cannot distinguish an acute angle from its obtuse supplement.
How to use the calculator
- Pick the task in "Solve for." Choose "SAS — find side c" if you know two sides and the included angle, or "SSS — find angle C" if you know all three sides. SAS is the default.
- Choose the angle unit. Degrees (°) is the default; Radians (rad) is also available. Switching units converts the current included-angle value, so you do not need to redo the conversion yourself. The relationships are radians degrees and degrees radians .
- Enter the sides. Type values or use the sliders. Side and side are always active. Side is active only in SSS. Every side must be a finite length from to .
- Enter the included angle (SAS only). It must be at least degrees and at most degrees, or at least radians and strictly below . A straight angle is not a triangle and is rejected.
- Read the result. Simple mode shows "Side c" for SAS or "Angle C" for SSS. Switch to Advanced to also see angles and , the area, and the perimeter.
- Open "Worked steps" to see the formula, your values substituted into it, and the result. Advanced mode adds detail for the remaining outputs.
Keep your units consistent
All sides must use the same length unit, whether centimeters, meters, feet, or anything else. The calculator does no length conversion. Lengths and perimeter are labeled "units" and area is labeled "units²," so read them in whichever unit you entered. Mixing, say, meters for and centimeters for will give a meaningless answer.
Check the opposite-side convention
The most common input mistake is matching a side to the wrong angle. Angle must be the angle between sides and , and side must be the side across from . If your diagram uses different letters, relabel it before entering values. The triangle diagram in the calculator labels vertices , , and and the opposite sides, and it marks as the given included angle in SAS or the solved angle in SSS, so you can compare it with your own sketch.
Example triangles
The "Example triangles" menu loads ready-made cases:
| Menu item | Loads |
|---|---|
| Custom triangle | Manual entry |
| 3–4–5 right triangle | SAS, degrees, , , |
| Equilateral SSS | SSS, degrees, |
| Obtuse SSS | SSS, degrees, , , |
Reset returns the calculator to Simple mode, degrees, and the default SAS values (, , ).
Worked example 1: SAS, finding a side
Suppose , , and the included angle is .
Step 1: write the formula.
Step 2: substitute.
Step 3: evaluate. Since :
Step 4: take the positive square root.
This is the classic 3–4–5 right triangle. In Advanced mode the calculator also reports , , area units², and perimeter units.
The area comes from the SAS area formula:
A note on numerical stability
The expression can lose precision when and are nearly equal and is tiny, because two large, almost identical quantities get subtracted. To reduce this cancellation, the calculator internally computes the algebraically equivalent form:
The answer is mathematically the same. The worked steps still display the standard cosine-rule form, which is the one to use by hand.
Worked example 2: SSS, finding an angle
Take the obtuse triangle with , , and . The longest side is , so the angle opposite it, , should be the largest, and likely obtuse.
Step 1: write the rearranged formula.
Step 2: substitute.
Step 3: simplify.
Step 4: apply inverse cosine.
The negative cosine is the signal of an obtuse angle. If the numerator is negative, the angle opposite is greater than ; if it is zero, the angle is exactly ; if positive, the angle is acute.
Other angles follow with the cyclic formulas. Internally the calculator uses equivalent angle formulas based on atan2, which are more stable for extreme shapes, while the displayed steps use the standard cosine-rule expressions.
Two more SSS checks
- 3–4–5 in radians. For , , , we get , so . In radian mode the calculator shows this as
1.570796 rad, which is . - Equilateral triangle. For , , so every angle is . The perimeter is and the area is .
Area and perimeter
In Advanced mode the calculator reports both.
Perimeter is simply the sum of the sides:
Area depends on the task. For SAS:
For SSS, the calculator uses a numerically stable rearrangement of Heron's formula:
Both approaches give the same mathematical area. For the equilateral example, and .
When a triangle is invalid
Not every set of three lengths forms a triangle. For positive sides, each pair must sum to more than the third side. Equivalently:
If equality holds, the three points lie on a straight line and the triangle is degenerate, with zero area. For example, , , gives , so the sides are collinear and the calculator rejects them.
The calculator also applies a stability check. Sort the sides from longest to shortest as . The triangle is rejected when:
This excludes some nearly collinear triangles that would technically have a positive area in exact arithmetic but cannot be solved reliably in floating-point arithmetic.
When any active input is invalid, the calculator:
- shows an error on the offending field,
- replaces visible results with an em dash (—),
- clears the worked steps,
- replaces the diagram with a request for valid measurements, and
- disables Copy and Print.
Very thin triangles
A valid triangle whose smallest angle is strictly below gets the note "A very thin triangle." This is a sensitivity warning, not an error. Tiny rounding differences in the measured sides can shift a very small angle by a large relative amount. For instance, with and , the calculator returns and shows the advisory. If your inputs come from physical measurements, treat results for such triangles with extra caution.
Reading the output
- Precision. Results display up to seven significant digits. Nonzero values with magnitude below , or at least , switch to scientific notation. Intermediate steps are rounded only for display; the calculator carries unrounded values forward, so the final answer is not degraded by rounding in the steps.
- Angle units. Angle outputs follow the unit you selected.
- Sanity checks. The longest side is always opposite the largest angle. The three interior angles sum to (or radians). An acute included angle in SAS yields a shorter opposite side than the right-angle case, and an obtuse one yields a longer side.
- Copy and Print. Copy saves a summary of the active inputs and visible results. Export/Print opens your browser's print dialog, where you can choose "Save as PDF."
- Diagram. The scaled triangle updates as you change measurements. Zoom and reset view affect only the drawing, never the calculation.
When to use the cosine rule instead of other methods
| Situation | Best tool |
|---|---|
| Right triangle, two sides known | Pythagorean theorem (a special case of the cosine rule) |
| Two sides and the included angle (SAS) | Law of cosines |
| Three sides (SSS) | Law of cosines |
| Two angles and a side (ASA, AAS) | Law of sines (outside this calculator) |
| Two sides and a non-included angle (SSA) | Law of sines, with care for the ambiguous case (outside this calculator) |
A common workflow is to use the cosine rule first to find one side or angle, then finish the remaining angles with either the cosine rule again or the sine rule.
Frequently asked questions
What is the law of cosines?
It is a formula that connects the three sides of a triangle with one angle: . It generalizes the Pythagorean theorem to triangles that do not have a right angle.
Is the law of cosines the same as the cosine rule?
Yes. "Law of cosines," "cosine law," and "cosine rule" all name the same relationship. A cos rule calculator and a law of cosine solver both do what this tool does.
Can I use this as a law of cosines SSS calculator?
Yes. Select "SSS — find angle C," enter all three sides, and the calculator returns angle . Advanced mode adds angles and , plus the area and perimeter.
Does the calculator show steps?
Yes. "Worked steps" is available in both Simple and Advanced modes. It shows the applicable cosine rule, your values substituted into it, and the result. Advanced mode adds detail for the other outputs.
Can the calculator handle radians?
Yes. Set the angle unit to Radians (rad). Angle inputs and angle outputs then use radians, and switching units converts the current included-angle value automatically.
Why does it say my triangle is invalid?
Either the sides fail the triangle inequality (), the sides are collinear or so nearly collinear that they fall inside the calculator's stability check, or a value is outside the accepted range. Check the field error for details.
What is the difference between the law of cosines and the law of sines?
The law of cosines uses SAS or SSS information. The law of sines is typically used with ASA, AAS, or SSA information. For SSS, the cosine rule is the right choice because it returns obtuse angles unambiguously.
Can the law of cosines find an obtuse angle?
Yes. A negative value of means the angle opposite is obtuse, and inverse cosine returns it directly. In the –– example, .
Does the calculator work for triangles on a sphere?
No. It solves Euclidean planar triangles only.
Read the formula definitions, supported input ranges, and limitations before using this estimate.