Law of Cosines Calculator
Enter three sides (SSS) or two sides and the included angle (SAS) to solve the triangle. Finds all angles, area, and perimeter using the law of cosines: c^2 = a^2 + b^2 - 2ab cos(C).
The Law of Cosines generalizes the Pythagorean theorem to any triangle — not just right triangles. The formula c² = a² + b² − 2ab × cos(C) relates the three sides of any triangle to the cosine of one angle. When C = 90°, cos(C) = 0, and the equation reduces to the familiar c² = a² + b² — the Pythagorean theorem is a special case.
This single law solves two important triangle problems: - **SSS (Side-Side-Side)**: given three sides, find all three angles. - **SAS (Side-Angle-Side)**: given two sides and the included angle, find the third side (and remaining angles).
Together with the Law of Sines (which handles ASA, AAS, and SSA cases), these two laws solve any triangle — a complete set of tools for trigonometry.
The Law of Cosines has been known for thousands of years, with origins in Greek geometry. Euclid's Elements (Book II, Proposition 12) gives a geometric version. Modern algebraic form was developed in the 15th-16th centuries.
Applications appear throughout science and engineering: - **Surveying**: measuring distances between inaccessible points. - **Navigation**: triangulating positions from known landmarks. - **Astronomy**: stellar distances using parallax and known angles. - **Engineering**: truss analysis, mechanical linkages. - **Computer graphics**: triangle mesh calculations. - **Game development**: collision detection, line-of-sight.
Common applications: surveying, navigation, robotics (forward/inverse kinematics), structural engineering (truss analysis), computer graphics, and any problem involving triangle geometry beyond right triangles.
Inputs
Results
Side a
7
Side b
8
Side c
10
Angle A
44.0486°
Angle B
52.6168°
Angle C
83.3346°
Area
27.8107 sq units
Perimeter
25
Formula
How to use this calculator
- Choose SSS (3 sides) or SAS (2 sides + angle).
- For SSS: enter a, b, c. Calculator returns all three angles.
- For SAS: enter a, b, included angle C. Calculator returns side c and remaining angles.
- Angles in degrees (convert if needed for trig functions).
- Check triangle inequality: each side < sum of others.
- Area from SAS: (1/2) × a × b × sin(C); from SSS: Heron's formula.
Worked examples
Survey distance
**Scenario:** Need distance across pond. Two stakes 100 m and 150 m from observation point, angle between sight lines 65°. **Calculation:** Distance² = 100² + 150² - 2 × 100 × 150 × cos(65°) = 10000 + 22500 - 30000 × 0.4226 = 32500 - 12677 = 19823. Distance ≈ 140.8 m. **Result:** ~141 m across pond. Surveyor avoids needing to measure directly across. Classic triangulation. Add cross-check: angle at each stake using Law of Sines.
Truss analysis
**Scenario:** Two truss members 4 m and 5 m meet at 70° angle. What length is the third member? **Calculation:** c² = 16 + 25 - 2 × 4 × 5 × cos(70°) = 41 - 40 × 0.342 = 41 - 13.68 = 27.32. c = √27.32 ≈ 5.23 m. **Result:** Third member ~5.23 m. Common in roof and bridge design. Engineers calculate forces in each member from external loads, considering geometry calculated via Law of Cosines.
Find largest angle
**Scenario:** Triangle with sides 8, 12, 16. Find largest angle. **Calculation:** Largest angle opposite longest side (16). cos(C) = (8² + 12² - 16²)/(2×8×12) = (64 + 144 - 256)/192 = -48/192 = -0.25. C = arccos(-0.25) ≈ 104.5°. **Result:** Largest angle ~104.5° (obtuse). Triangle is obtuse because 16² > 8² + 12² (256 > 208). If 16² = 8² + 12² (i.e., 208), would be right; less, would be acute.
When to use this calculator
**Use Law of Cosines for:**
- **SSS problems**: when you know all three sides. - **SAS problems**: when you know two sides and the included angle. - **Surveying**: measuring inaccessible distances. - **Navigation**: triangulation of position. - **Engineering**: truss and structural analysis. - **CAD design**: triangle mesh calculations. - **Astronomy**: stellar distances using parallax angles. - **Robotics**: forward kinematics.
**Law of Cosines vs Law of Sines:**
| Known | Use | |---|---| | 3 sides (SSS) | Law of Cosines | | 2 sides + included angle (SAS) | Law of Cosines | | 2 angles + any side (ASA, AAS) | Law of Sines | | 2 sides + non-included angle (SSA) | Law of Sines (with ambiguity check) |
**When Pythagorean theorem applies:**
Only for right triangles (one angle = 90°). Law of Cosines is generalization to any triangle.
**Triangle inequality:**
Always check: each side < sum of others. If not, "triangle" is impossible or degenerate.
For a = 3, b = 4, c = 8: 3 + 4 = 7 < 8. Impossible.
**Common applications:**
- **Forest surveying**: distances around obstacles. - **Hiking**: triangulation from peaks. - **GPS**: trilateration from satellites. - **Robotics**: arm positions from joint angles. - **Computer graphics**: 3D triangle properties. - **Music**: chord intervals. - **Architecture**: roof rafter calculations.
**Calculating area:**
From SAS: A = (1/2) × a × b × sin(C). From SSS: Heron's formula A = √(s(s-a)(s-b)(s-c)), s = (a+b+c)/2. From angles + 1 side: Law of Sines + Law of Cosines.
**Programming (Python):**
For SAS (given a, b, C in degrees, find c): c = math.sqrt(a*a + b*b - 2*a*b*math.cos(math.radians(C)))
For SSS (given a, b, c, find angle C in degrees): C = math.degrees(math.acos((a*a + b*b - c*c) / (2*a*b)))
**Software:**
- **Calculators**: most scientific calculators with trig functions. - **Excel**: combine SQRT, COS, ACOS, RADIANS, DEGREES. - **Python**: math module functions. - **MATLAB**: built-in trigonometry. - **CAD software**: parametric triangle solvers.
**Pitfalls:**
- **Wrong angle/side pairing**: ensure C is opposite c. - **Degree vs radian confusion**: programming languages use radians. - **Triangle inequality**: must hold. - **Numerical precision**: subtraction near-equal values amplifies errors. - **Acute vs obtuse**: sign of cosine indicates. - **Ambiguous case (SSA)**: use Law of Sines + additional logic.
**Connection to dot product:**
For vectors u, v from same vertex: c² = |u - v|² = |u|² + |v|² - 2 u·v = |u|² + |v|² - 2|u||v|cos(C)
So Law of Cosines is essentially vector dot product applied to triangle sides.
**For obtuse triangles:**
If c is longest side and c² > a² + b²: triangle is obtuse (C > 90°). If c² = a² + b²: right triangle (C = 90°). If c² < a² + b²: acute triangle (C < 90°).
Quick test from sides only.
**Educational connection:**
Law of Cosines bridges Pythagorean theorem (right triangles) to general trigonometry. Important in algebra II, geometry, trigonometry, calculus, and physics. Foundation for vector dot products in linear algebra.
**Common mistakes:**
- **Using on wrong triangle type**: don't apply Law of Sines techniques here. - **Computing wrong angle**: ensure formula gives the angle opposite the side you're computing. - **Squaring errors**: easy to miss the square term. - **Sign of cosine**: angle > 90° gives negative cosine (subtraction becomes addition in formula).
Common mistakes to avoid
- Confusing the side opposite the angle (must be paired correctly).
- Forgetting to take the square root at the end.
- Mixing degrees and radians in trig functions.
- Applying Pythagorean theorem to non-right triangles.
- Forgetting to check triangle inequality.
- Sign errors: cosine of obtuse angle is negative.
- Confusing SSS (Law of Cosines) with SSA (Law of Sines, ambiguous).
- Using radians vs degrees inconsistently.
Frequently Asked Questions
Sources & further reading
Related Calculators
Law of Sines Calculator
Solve a triangle using the law of sines for AAS (two angles + non-included side) or ASA (two angles + included side) cases.
Triangle Calculator
Calculate triangle area, perimeter, and angles from three side lengths using Heron's formula and the law of cosines.
Pythagorean Theorem Calculator
Find the missing side of a right triangle using a² + b² = c².