Cosine Rule Calculator

Given two sides and the included angle, find the third side (Law of Cosines).

📚 Confused about how this is calculated? Read the full The Formula That Contains the Pythagorean Theorem →

Mathematical Theory and Principles of the Cosine Rule (Law of Cosines)

The Cosine Rule, universally known as the Law of Cosines, is a profound trigonometric theorem that generalizes the Pythagorean theorem to any arbitrary planar triangle. While the Pythagorean theorem (c2 = a2 + b2) holds exclusively for right-angled triangles where the included angle is exactly 90° (cos(90°) = 0), the Cosine Rule incorporates a correction term −2ab cos(C) that accounts for non-orthogonal angular deviations.

The Cosine Rule is the indispensable mathematical tool for solving two fundamental geometric scenarios: (1) Side-Angle-Side (SAS) configurations, where two side lengths and the included angle are known and the third side is required, and (2) Side-Side-Side (SSS) configurations, where all three side lengths are known and the interior angles must be determined.

Fundamental Formulations of the Cosine Rule

1. Side-Solving Formulations (SAS Configuration):

a2 = b2 + c2 − 2bc cos(A) ⇒ a = √(b2 + c2 − 2bc cos(A))

b2 = a2 + c2 − 2ac cos(B) ⇒ b = √(a2 + c2 − 2ac cos(B))

c2 = a2 + b2 − 2ab cos(C) ⇒ c = √(a2 + b2 − 2ab cos(C))

2. Angle-Solving Formulations (SSS Configuration):

cos(A) = (b2 + c2a2) / (2bc) ⇒ A = arccos((b2 + c2a2) / (2bc))

cos(B) = (a2 + c2b2) / (2ac) ⇒ B = arccos((a2 + c2b2) / (2ac))

cos(C) = (a2 + b2c2) / (2ab) ⇒ C = arccos((a2 + b2c2) / (2ab))

3. Spherical Law of Cosines (for Planetary Geodesics and Great-Circle Distances):

cos(c) = cos(a) cos(b) + sin(a) sin(b) cos(C)

where a, b, c are angular arc distances across the spherical surface.

Structural Comparison: Cosine Rule vs Other Trigonometric Laws

Trigonometric Law Primary Target Cases Input Requirements Ambiguity / Edge Cases Key Advantages
Cosine Rule (Side Form) SAS Configurations Two sides and included angle None — output side is unique and strictly positive Direct computation of third side; handles acute, right, and obtuse angles
Cosine Rule (Angle Form) SSS Configurations Three side lengths (a, b, c) Requires valid triangle inequality (a+b > c) Arccos uniquely resolves angle in [0°, 180°] without sign ambiguity
Sine Rule (Law of Sines) AAS, ASA, SSA Configurations Two angles + side, or two sides + non-included angle Ambiguous Case (SSA) can yield 0, 1, or 2 triangles Faster computationally than Cosine Rule; directly yields circumradius R
Pythagorean Theorem Right-angled Triangles Only Two sides with known 90° right angle Fails for non-right triangles (angle ≠ 90°) Simplist formula (a2 + b2 = c2); zero trigonometric overhead
Spherical Cosine Rule Great-Circle Navigation Latitudes / Longitudes of two points Numerical loss of precision for very small distances (< 1 km) Standard formula for transcontinental flight path routing

Geometric Behavior and Angle Classification Mechanics

The algebraic sign of the numerator in the angle-solving Cosine Rule directly dictates whether an interior angle is acute, right, or obtuse:

  • Acute Angle (θ < 90°): If a2 + b2 > c2, the term (a2 + b2c2) is strictly positive, yielding cos(C) > 0 and C < 90°.
  • Right Angle (θ = 90°): If a2 + b2 = c2, the numerator equals zero, yielding cos(C) = 0 and C = 90°, naturally reducing to the classical Pythagorean theorem.
  • Obtuse Angle (θ > 90°): If a2 + b2 < c2, the numerator is strictly negative, yielding cos(C) < 0 and 90° < C < 180°. Because arccos is a strictly monotonic decreasing bijection over [−1, 1] → [180°, 0°], the Cosine Rule provides unambiguous angle identification without secondary quadrant checks.

Detailed Mathematical Derivation of the Law of Cosines

The Law of Cosines can be derived directly using Cartesian coordinates and the Pythagorean distance formula. Place triangle ABC in a 2D coordinate system such that vertex C is at the origin (0, 0), side a lies along the positive x-axis ending at vertex B(a, 0), and vertex A is positioned in the upper half-plane.

Using polar coordinate definitions, vertex A has coordinates (b cos(C), b sin(C)). Side c represents the distance between vertex A and vertex B(a, 0).

c2 = (xAxB)2 + (yAyB)2
c2 = (b cos(C) − a)2 + (b sin(C) − 0)2

Expanding the binomial expressions:

c2 = b2 cos2(C) − 2ab cos(C) + a2 + b2 sin2(C)
c2 = a2 + b2 (cos2(C) + sin2(C)) − 2ab cos(C)

Since the fundamental Pythagorean identity states cos2(C) + sin2(C) = 1, this simplifies directly to the Law of Cosines:

c2 = a2 + b2 − 2ab cos(C)

Step-by-Step Worked Mathematical Examples

Example 1: SAS Trajectory Vector Calculation in Maritime Navigation

A ship steams along heading vector a = 18.0 nautical miles, then turns at waypoint C with an interior angle of 115.0° onto heading vector b = 24.0 nautical miles. Compute the direct return distance c to the departure harbor.

  1. Apply the SAS Cosine Rule: c2 = a2 + b2 − 2ab cos(C).
  2. Square the given legs: 18.02 = 324.0, 24.02 = 576.0. Sum: 324.0 + 576.0 = 900.0.
  3. Compute the cosine term: cos(115.0°) ≈ −0.422618.
  4. Compute correction product: 2 × 18.0 × 24.0 × (−0.422618) = 864.0 × (−0.422618) ≈ −365.142.
  5. Calculate squared hypotenuse: c2 = 900.0 − (−365.142) = 900.0 + 365.142 = 1265.142.
  6. Extract square root: c = √1265.142 ≈ 35.569 nautical miles.

Example 2: SSS Angle Determination for Structural Truss Design

A structural steel roof truss has side lengths a = 7.0 m, b = 9.0 m, and c = 12.0 m. Determine the largest interior angle ∠C.

  1. Identify largest angle: Since side c = 12.0 m is the longest side, opposite angle ∠C is the largest angle.
  2. Apply SSS Cosine Rule: cos(C) = (a2 + b2c2) / (2ab).
  3. Evaluate numerator: 72 + 92 − 122 = 49 + 81 − 144 = 130 − 144 = −14.
  4. Evaluate denominator: 2 × 7 × 9 = 126.
  5. Compute ratio: cos(C) = −14 / 126 = −0.111111.
  6. Extract inverse cosine: C = arccos(−0.111111) ≈ 96.379° (1.6821 radians).
  7. Because cos(C) is negative, ∠C is an obtuse angle (> 90°).

Comprehensive Real-World Case Studies in Cosine Rule Mechanics

The Cosine Rule is ubiquitous across aerospace flight navigation, robotic manipulator inverse kinematics, civil structural truss analysis, and radar tracking. Consider an aerospace engineering scenario involving an uncrewed surveillance aircraft executing a tactical waypoint detour around severe weather convective cells.

The aircraft departs forward operating base Alpha and flies along leg b = 145.0 nautical miles (NM) to waypoint Charlie. At waypoint Charlie, radar shows the direct path to destination base Bravo is obstructed. The aircraft turns through an interior angle ∠C = 124.0° and flies leg a = 180.0 NM to reach destination Bravo.

Flight dispatchers must calculate: (1) the direct straight-line distance c from Alpha to Bravo to compute total flight detour mileage, (2) the departure heading angle ∠A, and (3) the fuel reserve consumption penalty.

Flight dynamics engineers apply the Side-Angle-Side (SAS) Cosine Rule:

c2 = a2 + b2 − 2ab cos(C)
a2 = 180.02 = 32,400.0 NM2
b2 = 145.02 = 21,025.0 NM2
a2 + b2 = 32,400.0 + 21,025.0 = 53,425.0 NM2
cos(124.0°) ≈ −0.559193
2ab cos(C) = 2 × 180.0 × 145.0 × (−0.559193) = 52,200.0 × (−0.559193) ≈ −29,189.87 NM2
c2 = 53,425.0 − (−29,189.87) = 53,425.0 + 29,189.87 = 82,614.87 NM2
c = √82,614.87 ≈ 287.428 NM

To determine departure turn angle ∠A, engineers apply the angle-solving Cosine Rule:

cos(A) = (b2 + c2a2) / (2bc)
Numerator = 21,025.0 + 82,614.87 − 32,400.0 = 71,239.87
Denominator = 2 × 145.0 × 287.428 = 83,354.12
cos(A) = 71,239.87 / 83,354.12 ≈ 0.854665 ⇒ ∠A = arccos(0.854665) ≈ 31.28°

The total flight detour distance is (145.0 + 180.0) − 287.428 = 325.0 − 287.428 = 37.572 NM extra distance, requiring an additional 148 kg of aviation jet fuel.

10-Point Protocol for Cosine Rule Analysis and Structural Rigidity

  1. Problem Pattern Identification: Identify if input matches SAS (two sides + included angle) or SSS (three sides).
  2. Triangle Inequality Validation: For SSS, verify a + b > c, a + c > b, and b + c > a.
  3. Angle Range Validation: For SAS, ensure the included angle satisfies 0° < θ < 180°.
  4. SAS Side Evaluation: Compute c = √(a2 + b2 − 2ab cos(C)).
  5. SSS Cosine Ratio Calculation: Calculate cos(A) = (b2 + c2a2) / (2bc).
  6. Domain Clamping Safeguard: In software code, clamp ratio to [−1.0, 1.0] before calling `acos()` to prevent floating-point domain errors.
  7. Angle Extraction: Compute A = arccos(cos(A)); arccos naturally resolves acute and obtuse angles without quadrant ambiguity.
  8. Remaining Angles Computation: Compute second angle via Cosine Rule or Sine Rule; calculate third angle via 180° − (A + B).
  9. Largest Angle Priority: In SSS solving, compute the largest angle first (opposite longest side) to determine if the triangle is obtuse.
  10. Area Cross-Verification: Verify computed values by comparing SAS area 0.5 ab sin(C) with Heron's formula area.

Frequently Asked Questions: Cosine Rule Principles and Mechanics

Why is the Cosine Rule called the generalized Pythagorean theorem?

When the included angle is exactly 90°, cos(90°) = 0. The correction term −2ab cos(C) vanishes completely, reducing the equation to c2 = a2 + b2, which is the exact Pythagorean theorem.

Why is the Cosine Rule immune to the "ambiguous case" that affects the Sine Rule?

The arccosine function has a unique 1-to-1 mapping across the entire interval [0°, 180°]. Positive cosine values correspond uniquely to acute angles (0° < θ < 90°) and negative cosine values correspond uniquely to obtuse angles (90° < θ < 180°). In contrast, the arcsine function cannot distinguish acute from obtuse angles.

How do you avoid floating-point errors when computing arccos in software?

Due to slight rounding errors in floating-point arithmetic (IEEE 754), evaluating (b2 + c2a2) / (2bc) can sometimes yield 1.0000000000000002. Passing this value to `acos()` triggers a domain error (`NaN`). Production software clamps the argument to max(−1.0, min(1.0, val)) before evaluation.

How does the Spherical Law of Cosines calculate distances on Earth?

By treating Earth as a sphere with radius R ≈ 6371 km, the angular distance σ between two points (lat1, lon1) and (lat2, lon2) is cos(σ) = sin(lat1) sin(lat2) + cos(lat1) cos(lat2) cos(Δlon). Multiplying σ (in radians) by R gives the great-circle surface distance.

Can the Cosine Rule be used to solve 3D vector angles?

Yes. The vector dot product u · v = ||u|| ||v|| cos(θ) is mathematically equivalent to the Law of Cosines applied to the vector triangle formed by u, v, and uv.

What is the Law of Cosines in robotic inverse kinematics?

In a two-link robotic arm with link lengths L1 and L2 reaching target coordinate (x, y), the distance from the shoulder base to the target is D = √(x2 + y2). The elbow interior joint angle θ2 is solved directly using the Cosine Rule: cos(θ2) = (x2 + y2L12L22) / (2L1L2).

Historical Foundations of the Cosine Rule and Metric Algebra

The geometric root of the Law of Cosines appears in Euclid's Elements (c. 300 BCE, Book II, Propositions 12 and 13). Euclid formulated the theorem geometrically without trigonometric terminology, stating that in obtuse-angled triangles, the square on the side subtending the obtuse angle is greater than the sum of the squares on the containing sides by twice the rectangle contained by one of the sides and the projection on it of the other.

In the tenth century, Persian astronomer Abu al-Wafa al-Buzjani developed early trigonometric expressions for spherical triangle solving. In the fifteenth century, Persian mathematician Jamshıd al-K&amacron;shı calculated comprehensive trigonometric tables and formulated the Law of Cosines in a form suitable for modern triangulation (frequently called Al-Kashi's Theorem in French mathematics). In 1748, Leonhard Euler published Introductio in analysin infinitorum, presenting the modern algebraic notation c2 = a2 + b2 − 2ab cos(C) and formalizing its analytical connection to the Pythagorean theorem.

Error Diagnostics and Numerical Stability Matrix

Error Scenario Underlying Mathematical Cause Failure Manifestation Corrective Implementation Protocol
Arc-Cosine Floating Domain Error (b2 + c2a2)/(2bc) evaluates to 1.0000000000000002 `acos()` function throws `NaN` / domain exception Clamp the cosine argument to the interval [−1.0, 1.0] before calling `acos()`
Degenerate Flat Triangle Side lengths satisfy a + b = c exactly cos(C) = −1.0, producing flat angle C = 180.0° with zero area Detect collinearity and flag as degenerate 1D straight line
Triangle Inequality Violation Input sides satisfy a + b < c (cannot close triangle) Cosine ratio exceeds 1.0 or −1.0 (e.g. cos = 1.45) Validate strict triangle inequality a + b > c before solving angles
Extreme Dynamic Range Squaring Side lengths exceed 10154 in 64-bit floating point a2 overflows to `+Infinity` prior to subtraction Normalize side lengths by dividing all sides by max(a, b, c) before squaring
Obtuse Angle Omission in Sine Rule Fallback Using Sine Rule after SAS without testing largest angle Obtuse angle misclassified as acute due to arcsine limitations Always use Law of Cosines to solve the largest angle first in SSS configurations

Technical Glossary of Cosine Rule Concepts

Law of Cosines:
The universal trigonometric theorem stating that c2 = a2 + b2 − 2ab cos(C), generalizing the Pythagorean theorem to all triangles.
Side-Angle-Side (SAS):
A geometric configuration where two side lengths and their included interior angle are known, solved uniquely via the Cosine Rule.
Side-Side-Side (SSS):
A geometric configuration where all three side lengths are known, solved for interior angles using inverse cosine formulations.
Al-Kashi's Theorem:
The historical designation for the Law of Cosines in tribute to the 15th-century Persian mathematician Jamshid al-Kashi.
Spherical Law of Cosines:
The spherical trigonometry identity cos(c) = cos(a)cos(b) + sin(a)sin(b)cos(C) used for great-circle geodesic routing.
Inverse Kinematics:
The mathematical process of calculating required robotic joint angles to position an end-effector at a desired spatial coordinate.
Vector Dot Product Equivalence:
The algebraic identity showing that u · v = ||u|| ||v|| cos(θ) represents the Law of Cosines in vector space.
Monotonic Bijection:
A mathematical property of arccos over [−1, 1] ensuring every cosine value maps to exactly one unique angle in [0°, 180°].

Advanced Inverse Kinematics and Multi-Body Dynamic Architectures

In industrial robotics automation, six-axis articulated robot arms, surgical robotic teleoperation, and computer animation inverse kinematics (IK), the Law of Cosines is executed continuously within high-frequency joint control loops (operating at 1 kHz to 10 kHz). Solving the elbow joint angle from end-effector target positions via the Cosine Rule executes in deterministic O(1) constant time, requiring minimal CPU cycle overhead.

Modern embedded motion controllers utilize fixed-point DSP math and hardware-accelerated square root / arccosine instruction sets to evaluate joint angles in microsecond timescales. To guarantee operational safety, motion planning algorithms incorporate numerical domain clamping ([−1.0, 1.0]) and singular boundary detection, preventing robotic arm kinematic lockup near workspace reach limits.

Software Verification and Monotonic Unit Testing Protocols

Deploying Cosine Rule engines into mission-critical aerospace flight control and structural analysis software requires comprehensive unit test coverage. Automated test suites evaluate boundary conditions, including right-angled triangles verifying exact equivalence with the Pythagorean theorem, degenerate flat triangles with angles of 0° and 180°, equilateral triangles with three 60° angles, and obtuse triangles with angles approaching 179.9°.

Continuous integration suites verify round-trip conversion invariance: solving for an unknown side via SAS, then solving for the included angle via SSS, must reproduce the initial angle within machine precision limits (|θinitial − θcomputed| < 10−13 degrees). Automated fuzz testing across extreme dynamic ranges validates that intermediate square calculations neither trigger arithmetic overflow nor produce domain exceptions in `acos()`.

Orbital Mechanics, Keplerian Elements, and True Anomaly Geometry

In celestial astrodynamics and spacecraft orbital trajectory design, the Law of Cosines plays a central role in relating a satellite's spatial position vector r to its orbital ellipse parameters. According to Johannes Kepler's First Law, planets and satellites follow elliptical trajectories with the central gravitational body (the Earth or Sun) located at one of the two foci (F1).

By applying the Law of Cosines to the triangle formed by the two foci F1, F2 (separated by focal distance 2c = 2ae) and the satellite position P, astrodynamicists derive the polar conic section equation r(ν) = a(1 − e2) / (1 + e cos(ν)), where a is the semi-major axis, e is orbital eccentricity, and ν is the true anomaly angle. This allows mission flight directors to calculate exact spacecraft orbital velocities, predict orbital decay lifetimes, and execute interplanetary Hohmann transfer maneuvers.

Continuum Mechanics and Stress Tensor Mohr's Circle Derivation

In geophysics and mechanical engineering, materials subject to multi-axial loading experience internal stress distributions characterized by the Cauchy stress tensor. When analyzing stress acting across an oblique plane oriented at angle θ, the normal stress σn and shear stress τ are derived by applying the Law of Cosines to a differential triangular Cauchy tetrahedron element.

This trigonometric derivation leads directly to Mohr's Circle: (σn − σavg)2 + τ2 = R2, where R = √(((σx − σy)/2)2 + τxy2). By identifying principal stress directions where shear stress vanishes, structural engineers determine maximum tensile stress failure planes, ensuring concrete skyscrapers and aircraft fuselages operate well within safe elastic stress limits.

Electromagnetic Vector Dipoles and Antenna Radiation Patterns

In telecommunications engineering and RF antenna design, the spatial electric field radiated by an electric dipole antenna of length L varies as a function of the observation angle θ measured from the antenna axis line. By applying the Law of Cosines to path difference triangles between differential current elements along the antenna conductor, RF engineers derive the classic dipole radiation intensity pattern: F(θ) = [cos((kL/2) cos(θ)) − cos(kL/2)] / sin(θ). This geometric formulation governs the radiation directivity, gain, and beam tilt of cellular 5G base station phased arrays.