CalcMountain

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

Last updated:

Formula

**Law of Cosines:** c² = a² + b² − 2ab × cos(C) Where: - a, b = two sides - c = third side (opposite angle C) - C = angle between sides a and b **All three forms (any side opposite any angle):** c² = a² + b² − 2ab × cos(C) a² = b² + c² − 2bc × cos(A) b² = a² + c² − 2ac × cos(B) **Worked example: SAS** Triangle with a = 5, b = 7, included angle C = 60°. Find c: c² = 25 + 49 − 2 × 5 × 7 × cos(60°) c² = 74 − 70 × 0.5 c² = 74 − 35 = 39 c = √39 ≈ 6.24 **Worked example: SSS** Triangle with a = 5, b = 7, c = 9. Find angles. cos(C) = (a² + b² − c²) / (2ab) = (25 + 49 − 81)/(70) = -7/70 = -0.1 C = arccos(-0.1) ≈ 95.74° By Law of Sines or repeat: cos(A) = (b² + c² − a²)/(2bc) = (49 + 81 − 25)/(126) = 105/126 ≈ 0.833 A = arccos(0.833) ≈ 33.56° B = 180° − A − C = 180° − 33.56° − 95.74° = 50.70°. Verify: arctan checks all match. **Relation to Pythagorean theorem:** If C = 90°: cos(C) = 0. c² = a² + b² − 0 = a² + b² Pythagorean is special case of Law of Cosines. **For angles 90°:** C < 90° (acute): cos(C) > 0, so c² < a² + b² (triangle less elongated). C = 90° (right): c² = a² + b². C > 90° (obtuse): cos(C) < 0, so c² > a² + b² (triangle more elongated). **Solving for angle (rearranged):** cos(C) = (a² + b² − c²) / (2ab) C = arccos((a² + b² − c²) / (2ab)) **Worked example: surveying** Two points A and B on opposite sides of a river. Surveyor stands at C and measures: distance from C to A = 200 m, from C to B = 150 m, angle at C = 75°. Width of river (distance A to B)? Side c (across river) = √(a² + b² − 2ab cos(C)): a = 200, b = 150, C = 75°. c² = 40,000 + 22,500 − 60,000 × cos(75°) c² = 62,500 − 60,000 × 0.2588 c² = 62,500 − 15,528 = 46,972 c ≈ 216.7 m. River is ~217 m wide at the measurement points. **Triangle area from SAS:** Area = (1/2) × a × b × sin(C) For our example: Area = 0.5 × 200 × 150 × sin(75°) = 15,000 × 0.966 ≈ 14,489 m². **Triangle area from SSS (Heron's formula):** s = (a + b + c) / 2 Area = √(s(s-a)(s-b)(s-c)) For a = 5, b = 7, c = 9: s = 21/2 = 10.5 Area = √(10.5 × 5.5 × 3.5 × 1.5) = √303.19 ≈ 17.41 **Common applications:** - **Surveying**: measuring distances across obstacles. - **Navigation**: triangulation with bearings. - **Astronomy**: stellar/planetary distances. - **Engineering**: truss member analysis. - **Robotics**: forward kinematics. - **CAD**: triangle mesh calculations. - **Game development**: NPC sight lines. - **GPS/GIS**: distance calculations. **Triangle inequality:** For any triangle: each side < sum of other two. If a + b ≤ c (or any permutation), the "triangle" is degenerate (line) or impossible. Check before applying Law of Cosines: ensure given sides satisfy triangle inequality. **Numerical accuracy:** For very acute or obtuse triangles, Law of Cosines can lose precision (subtraction of nearly equal values). Alternative formulations exist for high-precision work. **Inverse: finding angle from sides:** cos(C) = (a² + b² − c²) / (2ab) If cos(C) = 1: C = 0° (degenerate). If cos(C) = -1: C = 180° (degenerate, straight line). If 0 < cos(C) < 1: 0° < C < 90° (acute). If cos(C) = 0: C = 90° (right). If -1 < cos(C) < 0: 90° < C < 180° (obtuse). **Vector form:** For vectors u and v: u · v = |u| |v| cos(C). If u, v are sides of triangle from common vertex: third side w = u - v. |w|² = |u|² + |v|² - 2 u · v = |u|² + |v|² - 2|u||v|cos(C). Same as Law of Cosines, derived from vector dot product. **Common applications:** - **Surveying**: triangulating land boundaries. - **Navigation**: ship positioning from bearings. - **Aviation**: aircraft heading and ground course. - **Astronomy**: parallax calculations. - **Robotics**: arm joint angles from end-effector position. - **Civil engineering**: bridge and truss design. - **Architecture**: roof angles, rafters. - **Sports**: angles in pool/billiards, ball trajectory. **Software:** - **Excel**: combine with COS, ACOS functions. - **Python**: math.acos((a**2 + b**2 - c**2) / (2*a*b)) - **MATLAB**: built-in trig functions. - **CAD**: parametric triangle solving. - **Geometric calculators**: dedicated triangle solvers. **SSS vs SAS:** SSS (3 sides): Always solvable if triangle inequality holds. Unique triangle. SAS (2 sides + included angle): Always solvable. Unique triangle. Both give unique triangle, no ambiguity (unlike SSA). **SSA ambiguity:** For SSA (2 sides + non-included angle): 0, 1, or 2 triangles possible — "ambiguous case". Need Law of Sines and additional logic. **Worked example: angle wedge in machinery** Truss analysis: two members 4 m and 3 m meet at 110° angle. Third member length? c² = 16 + 9 − 2 × 4 × 3 × cos(110°) c² = 25 − 24 × (-0.342) c² = 25 + 8.21 = 33.21 c ≈ 5.76 m If C is obtuse (>90°), c > √(a²+b²) (more than Pythagorean would give). **Pitfalls:** - **Wrong angle/side correspondence**: angle C must be opposite side c. - **Confusing radians and degrees**: most calculators expect radians for trig. - **Numerical precision**: very small angles give precision issues. - **Triangle inequality**: must hold for valid triangle. - **Confusing SSS with SAS**: different input requirements. - **Negative cosine**: angle > 90° gives cos < 0 (obtuse triangle).

How to use this calculator

  1. Choose SSS (3 sides) or SAS (2 sides + angle).
  2. For SSS: enter a, b, c. Calculator returns all three angles.
  3. For SAS: enter a, b, included angle C. Calculator returns side c and remaining angles.
  4. Angles in degrees (convert if needed for trig functions).
  5. Check triangle inequality: each side < sum of others.
  6. 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

SponsoredShop Top Deals on AmazonSupport CalcMountain — browse top-rated products at no extra cost to you.

Related Calculators