Law of Cosines Calculator – Solve SSS and SAS Triangles
The Law of Cosines is one of the two fundamental relationships in triangle trigonometry, alongside the Law of Sines. Where the Pythagorean theorem works only for right triangles, the Law of Cosines applies to any triangle, making it the go-to formula for surveyors, engineers, physicists, and students tackling oblique triangles.
The Core Formula
The Law of Cosines has three symmetric forms, one for each pair of opposite sides and angles:
c² = a² + b² − 2ab·cos(C)b² = a² + c² − 2ac·cos(B)a² = b² + c² − 2bc·cos(A)
In each case, the side on the left is the one opposite the angle on the right. Rearranging any form isolates the cosine and lets you compute an unknown angle from three known sides.
Two Solve Modes
SSS (Side–Side–Side)
When all three side lengths are known, rearrange the formula to find each angle:
A = arccos((b² + c² − a²) / (2bc))
This mode is unambiguous — any set of three positive sides satisfying the triangle inequality produces exactly one triangle. The calculator verifies the triangle inequality before computing and flags degenerate inputs immediately.
SAS (Side–Angle–Side)
When two sides and the included angle (the angle between those two sides) are known, the formula computes the missing third side directly:
c = √(a² + b² − 2ab·cos(C))
Once the third side is found, the remaining angles follow by applying the rearranged formula twice more. Like SSS, SAS always yields a unique triangle with no ambiguity — unlike the SSA case handled by the Law of Sines.
Secondary Outputs
After the triangle is fully solved, the calculator provides:
- Perimeter — the sum of all three sides.
- Area — computed using Heron's formula:
s = (a+b+c)/2; Area = √(s(s−a)(s−b)(s−c)) - Triangle type — classified as Acute (all angles less than 90°), Right (one angle exactly 90°), or Obtuse (one angle greater than 90°).
- Angle sum verification — confirms A + B + C = 180° (or π radians) to catch any floating-point drift.
Connection to the Pythagorean Theorem
The Pythagorean theorem is a special case of the Law of Cosines. When angle C is exactly 90°, cos(90°) = 0, so the entire −2ab·cos(C) term vanishes, leaving c² = a² + b². For acute triangles the cosine is positive, so the missing side is shorter than the Pythagorean prediction; for obtuse triangles the cosine is negative, so it is longer.
Angle Units and Precision
All internal calculations run in radians for numerical accuracy. The calculator converts degrees to radians at the input boundary and back to degrees at the output boundary, so you can work in whichever unit is natural for your application. The arccos argument is clamped to [−1, 1] to handle minor floating-point rounding that could otherwise produce a domain error.
Decimal precision is adjustable from 0 to 10 places. For engineering or surveying work, 4–6 places is typical. For classroom exercises, 2–3 places is usually sufficient.
Practical Applications
The Law of Cosines appears across many real-world domains:
- Land surveying — computing plot dimensions when three boundary markers are measured but the angles between them are unknown.
- Structural engineering — finding the length of a diagonal brace given two frame members and the angle at their joint.
- Navigation — calculating the distance between two waypoints when the bearing and distances from a reference point are known.
- Physics — resolving the magnitude of a resultant force vector when two forces and the angle between them are given.
- Robotics — kinematics calculations for two-link manipulator arms where joint angles define end-effector position.
- Pre-calculus education — solving oblique triangles in the standard curriculum when right-triangle methods are insufficient.
Validation and Error Handling
The calculator enforces all geometric constraints before computing. For SSS mode it checks that every side is positive and that the triangle inequality holds. For SAS mode it verifies that both sides are positive and the included angle lies strictly between 0° and 180°. If any constraint is violated, a clear error message describes which input is out of range.