The Law of Cosines

Every triangle's sides and angles are connected through the law of cosines. This relationship lets you find any unknown side if you know two sides and the included angle, or any unknown angle if you know all three sides.

cos(α) = (b² + c² − a²) ÷ (2 × b × c)

cos(β) = (a² + c² − b²) ÷ (2 × a × c)

cos(γ) = (a² + b² − c²) ÷ (2 × a × b)

  • a, b, c — The three sides of the triangle
  • α, β, γ — The angles opposite to sides a, b, c respectively

How to Use This Calculator

Begin by identifying which measurements you have. If you know two sides and the angle between them, enter those values. The calculator will apply the law of cosines to compute the third side.

Alternatively, if all three sides are known, input them to find all three angles. The tool rearranges the law of cosines formula algebraically, solving for the unknown quantities without requiring manual trigonometric calculations.

Example: A right triangle has sides of 3 and 4 units with a 90° angle between them. Entering a = 3, b = 4, and γ = 90° yields c = 5 (the classic Pythagorean triple). The calculator confirms this by recognizing that cos(90°) = 0, simplifying the law of cosines to the Pythagorean theorem.

When the Law of Cosines Applies

The law of cosines works for any triangle, regardless of shape or size. It's particularly valuable when:

  • You lack right angles: The Pythagorean theorem only works for right triangles, but the law of cosines applies universally.
  • You have two sides and an included angle (SAS): This is the most common real-world scenario in surveying and construction.
  • You have all three sides (SSS): Finding angles becomes straightforward algebra.
  • You have two sides and a non-included angle (SSA): The calculator handles ambiguous cases where two solutions may exist.

Common Pitfalls and Caveats

Keep these practical considerations in mind when solving triangles.

  1. Angle measurement consistency — Ensure your angles are in the same unit throughout—degrees or radians. Mixing them will produce incorrect results. Most calculators default to degrees, which is standard for applied problems.
  2. The ambiguous SSA case — When you provide two sides and a non-included angle, two valid triangles may exist. The calculator will identify this and show both solutions. Always verify which solution matches your physical constraints.
  3. Rounding in intermediate steps — If you manually calculate intermediate values, carry extra decimal places until the final answer. Rounding too early in cosine or inverse-cosine operations compounds errors significantly.
  4. Triangle inequality check — For any valid triangle, the sum of any two sides must exceed the third side. If your inputs violate this, no triangle exists. The calculator will alert you to impossible combinations.

Practical Applications

Engineers use this calculator when designing roof trusses, where two known beam lengths and their meeting angle determine the third beam. Surveyors employ it when measuring land parcels with irregular boundaries. Navigation professionals apply it to triangulation methods for pinpointing locations. In physics, it solves force vector problems where two forces at an angle result in a net force of unknown magnitude and direction.

The law of cosines is also foundational to understanding more advanced topics like the law of sines, spherical trigonometry, and coordinate geometry transformations.

Frequently Asked Questions

Can I find an angle if I only know the three side lengths?

Yes. Input all three sides and the calculator will determine all three angles using rearranged versions of the law of cosines. For each angle, the formula isolates the cosine of that angle, then takes the inverse cosine (arccos) to yield the angle in degrees. This method works perfectly for any valid triangle.

What happens if I enter impossible measurements?

If the values you enter violate the triangle inequality theorem—where the sum of any two sides must be greater than the third—no valid triangle can form. The calculator will detect this and inform you that the inputs are contradictory. Check your measurements before proceeding.

Why does a 3-4-5 triangle use the simpler Pythagorean theorem instead of the law of cosines?

The Pythagorean theorem is actually a special case of the law of cosines. When one angle is exactly 90°, the cosine of that angle equals zero, eliminating terms and reducing the law of cosines to a² + b² = c². Both methods give identical results; the calculator recognises this and applies the most efficient approach.

If I know only one side and one angle, can the calculator solve the triangle?

No, one side and one angle are insufficient. You need at least three independent pieces of information: either three sides, two sides plus an angle, or two angles plus a side. With fewer constraints, infinitely many triangles satisfy the conditions.

What's the difference between the law of cosines and the law of sines?

The law of cosines relates sides to angles when you know the included angle between two sides. The law of sines compares the ratio of a side to the sine of its opposite angle. Both are valid; you choose based on which measurements you have. The law of cosines is more direct when you have two sides and an included angle.

Can this calculator handle obtuse triangles?

Absolutely. Obtuse triangles (with one angle greater than 90°) are solved identically to acute triangles using the law of cosines. The formula accommodates negative cosine values, which naturally arise for angles beyond 90°. The calculator produces correct results regardless of whether the triangle is acute, right, or obtuse.

More math calculators (see all)