Law Of Cosines Interactive Calculator

The Law of Cosines is a fundamental trigonometric relationship that extends the Pythagorean theorem to non-right triangles, enabling engineers, surveyors, and designers to solve for unknown sides or angles in any triangle configuration. This calculator provides instant solutions for all triangle elements using the cosine law, supporting structural analysis, navigation systems, force vector resolution, and spatial geometry applications. Whether you're determining mechanical linkage dimensions, calculating GPS triangulation coordinates, or analyzing truss member forces, this tool delivers precise results across multiple calculation modes.

📐 Browse all free engineering calculators

Triangle Diagram

Law Of Cosines Interactive Calculator Technical Diagram

Law of Cosines Interactive Calculator

Core Equations

Law of Cosines - Side Form

c² = a² + b² - 2ab·cos(C)

a² = b² + c² - 2bc·cos(A)

b² = a² + c² - 2ac·cos(B)

Where:
a, b, c = side lengths of the triangle (any consistent units)
A = angle opposite side a (degrees or radians)
B = angle opposite side b (degrees or radians)
C = angle opposite side c (degrees or radians)

Law of Cosines - Angle Form

cos(C) = (a² + b² - c²) / (2ab)

cos(A) = (b² + c² - a²) / (2bc)

cos(B) = (a² + c² - b²) / (2ac)

Application: Use these forms when all three sides are known and you need to find any angle. The arccosine function recovers the angle from the cosine ratio.

Triangle Area - Heron's Formula

Area = √[s(s-a)(s-b)(s-c)]

Where:
s = semi-perimeter = (a + b + c) / 2 (units)
This formula calculates area using only the three side lengths, without requiring any angle measurements.

Theory & Engineering Applications

Mathematical Foundation and Derivation

The Law of Cosines represents a generalization of the Pythagorean theorem that applies to all triangles, not just right triangles. When angle C equals 90°, cos(90°) = 0, and the equation c² = a² + b² - 2ab·cos(C) reduces to c² = a² + b², the familiar Pythagorean relationship. The law emerges from vector analysis by considering a triangle as two vectors joined at an angle, where the third side represents their vector sum. Using the dot product formula and the magnitude of vector differences yields the cosine law relationship directly.

The critical insight that distinguishes expert application from textbook knowledge is understanding when numerical instability occurs in the angle-solving form. When computing cos(θ) = (a² + b² - c²)/(2ab) for very acute angles approaching 0°, the numerator approaches zero as (a² + b² - c²) becomes small, while the denominator remains finite. This creates a loss of precision in floating-point arithmetic. For angles less than approximately 10°, calculating the complementary angle using the Law of Sines and then subtracting from 180° often provides superior numerical accuracy. Similarly, for obtuse angles greater than 170°, the cosine approaches -1 and suffers similar precision degradation.

Coordinate System Derivation

Placing vertex C at the origin with side b along the positive x-axis, vertex B has coordinates (a, 0). Vertex A lies at position (b·cos(C), b·sin(C)) based on the angle C. The distance from A to B equals side c, computed using the distance formula: c² = (b·cos(C) - a)² + (b·sin(C) - 0)² = b²·cos²(C) - 2ab·cos(C) + a² + b²·sin²(C). Using the identity cos²(C) + sin²(C) = 1, this simplifies to c² = a² + b² - 2ab·cos(C), proving the Law of Cosines through coordinate geometry.

Surveying and Geodetic Applications

Land surveyors use the Law of Cosines extensively when triangulating property boundaries where terrain or obstacles prevent direct measurement of all sides. Given two measured distances from a known baseline and the angle between them, the law computes the third distance without physical measurement. In geodetic surveying for large-scale mapping projects, spherical trigonometry employs a modified cosine law accounting for Earth's curvature. For triangles on a sphere of radius R, the spherical law of cosines states: cos(c/R) = cos(a/R)·cos(b/R) + sin(a/R)·sin(b/R)·cos(C), where a, b, c represent arc lengths. This becomes essential for GPS coordinate transformations and navigation over distances exceeding 30 kilometers where flat-Earth approximations introduce unacceptable error.

Mechanical Linkage Analysis

Four-bar mechanisms, universal in automotive suspensions, industrial robotics, and mechanical presses, form closed-loop chains where the Law of Cosines determines link positions throughout the motion cycle. Consider a four-bar linkage with fixed frame length L₁, input crank L₂, coupler L₃, and output rocker L₄. As the crank rotates through angle θ, the diagonal connecting the free ends of the crank and rocker forms a virtual triangle with the coupler. Applying the cosine law to this triangle: d² = L₂² + L₄² - 2L₂L₄·cos(θ), where d is the diagonal length. A second triangle formed by the frame, diagonal, and coupler gives: L₃² = L₁² + d² - 2L₁d·cos(φ), where φ is the angle between the frame and diagonal. Solving these coupled equations determines all link angles for any input position, essential for mechanism synthesis and kinematic simulation.

Force Vector Resolution in Structural Analysis

When analyzing forces acting at angles in truss structures or cable systems, engineers decompose force vectors using the Law of Cosines. If two forces F₁ and F₂ act at angle θ between them, the magnitude of their resultant force F_R follows: F_R² = F₁² + F₂² - 2F₁F₂·cos(180° - θ) = F₁² + F₂² + 2F₁F₂·cos(θ), since cos(180° - θ) = -cos(θ). This differs from simple Pythagorean addition unless θ = 90°. For a cable-stayed bridge with two support cables at angles θ₁ and θ₂ from vertical, each carrying tension T, the horizontal force component on the deck equals T·sin(θ₁) + T·sin(θ₂), while the vertical component is T·cos(θ₁) + T·cos(θ₂). The resultant magnitude requires cosine law calculation when these components act at a non-right angle.

Navigation and GPS Triangulation

GPS receivers determine position by measuring distances (pseudoranges) to multiple satellites with known positions. With three satellites, the receiver location forms a triangle with two satellites, using the third to verify altitude. The Law of Cosines calculates the angle at the receiver between two satellites given their positions and the measured distances. Modern GPS systems use at least four satellites for three-dimensional positioning, but the fundamental two-dimensional solution relies on cosine law triangulation. The accuracy limitations stem from atmospheric signal delay, multipath reflections, and satellite geometry—when satellites cluster in one region of the sky (poor dilution of precision), small ranging errors amplify through the cosine law calculation, degrading position accuracy from 5 meters to potentially 50+ meters.

Worked Example: Mechanical Linkage Design

Problem: Design a windshield wiper mechanism using a four-bar linkage. The fixed pivot points are 287.5 mm apart (frame length L₁). The motor drives a 65 mm crank (L₂) that must produce a 105° sweep angle at the output rocker (L₄ = 142 mm). Calculate the required coupler length L₃ and verify the mechanism can achieve the desired motion without lock-up.

Solution:

Step 1: At the start position (crank angle θ = 0°), calculate the diagonal distance d₁ between the crank and rocker endpoints:
d₁² = L₂² + L₁² - 2L₂L₁·cos(θ)
d₁² = 65² + 287.5² - 2(65)(287.5)·cos(0°)
d₁² = 4225 + 82656.25 - 37375·(1)
d₁² = 49506.25
d₁ = 222.50 mm

Step 2: The rocker must sweep 105°, so at maximum extension, the rocker angle is 105°. Calculate the new diagonal d₂:
d₂² = L₂² + L₁² - 2L₂L₁·cos(105°)
d₂² = 65² + 287.5² - 2(65)(287.5)·cos(105°)
d₂² = 4225 + 82656.25 - 37375·(-0.2588)
d₂² = 86881.25 + 9674.65
d₂² = 96555.90
d₂ = 310.73 mm

Step 3: For the mechanism to function, the coupler L₃ must form valid triangles with both diagonal configurations. Using the triangle formed by frame, rocker, and diagonal at start position:
L₃² = d₁² + L₄² - 2d₁L₄·cos(α₁)
where α₁ is the angle between rocker and diagonal. We can find this using the frame-rocker-diagonal triangle:
cos(α₁) = (L₁² + L₄² - d₁²) / (2L₁L₄)
cos(α₁) = (287.5² + 142² - 222.50²) / (2·287.5·142)
cos(α₁) = (82656.25 + 20164 - 49506.25) / 81650
cos(α₁) = 53314 / 81650 = 0.6527
α₁ = 49.26°

Step 4: Now calculate L₃ using the diagonal-rocker-coupler triangle:
L₃² = d₁² + L₄² - 2d₁L₄·cos(α₁)
L₃² = 222.50² + 142² - 2(222.50)(142)·cos(49.26°)
L₃² = 49506.25 + 20164 - 63190·(0.6527)
L₃² = 69670.25 - 41248.29
L₃² = 28421.96
L₃ = 168.59 mm

Step 5: Verify at maximum rocker angle (105° position). The angle between rocker and diagonal becomes:
cos(α₂) = (L₁² + L₄² - d₂²) / (2L₁L₄)
cos(α₂) = (82656.25 + 20164 - 96555.90) / 81650
cos(α₂) = 6264.35 / 81650 = 0.0767
α₂ = 85.60°

The large angle change from 49.26° to 85.60° confirms significant rocker motion.

Step 6: Check triangle inequality to ensure no lock-up. The coupler must satisfy:
|d₂ - L₄| < L₃ < d₂ + L₄
|310.73 - 142| < 168.59 < 310.73 + 142
168.73 < 168.59 < 452.73

This inequality FAILS at the lower bound by 0.14 mm, indicating the mechanism approaches a near-locked position. Increasing L₃ to 170 mm would provide a 1.3 mm safety margin and ensure smooth operation throughout the sweep range.

Final Answer: The required coupler length is L₃ = 170 mm (adjusted from calculated 168.59 mm to prevent lock-up). This four-bar linkage will produce the desired 105° wiper sweep with the motor driving the 65 mm crank through continuous rotation while the 142 mm output rocker oscillates the wiper blade.

This example demonstrates how the Law of Cosines enables complete kinematic analysis of mechanical systems, predicting positions throughout the motion cycle and identifying potential geometric singularities before physical prototyping. For more advanced engineering calculations, visit our complete calculator collection.

Practical Applications

Scenario: Residential Property Boundary Dispute

Jennifer, a land surveyor, investigates a fence line dispute between two homeowners who disagree about the exact corner location of their properties. The original survey from 1974 shows distances of 43.7 meters and 38.2 meters from two established benchmarks, with an angle of 127.3° between the sight lines. However, dense vegetation prevents direct measurement of the distance between benchmarks. Jennifer uses the Law of Cosines to calculate this third distance as 73.84 meters, then verifies by clearing a sight line and measuring 73.81 meters with her total station—well within the ±0.05 meter survey tolerance. This calculation not only resolves the boundary question but saves three hours of brush clearing that would have been needed to measure all distances directly. The verified corner stake is placed, legally documenting the property line for future reference.

Scenario: Robotics Competition Team Design

Marcus leads a high school robotics team building a competition robot with an extending arm mechanism. The design uses a four-bar linkage where a servo motor rotates a 12 cm input arm through 180°, connected to an 18 cm coupler link, with a 15 cm output arm that must reach game pieces positioned 35-52 cm from the robot's pivot point. The frame distance between pivot points measures 22 cm. Marcus uses the Law of Cosines calculator in reverse mode—inputting the desired reach distances and working backward to verify the geometry actually produces those positions. He discovers that at maximum servo rotation (180°), the mechanism reaches only 48.3 cm, falling 3.7 cm short of the required 52 cm reach. By increasing the coupler length to 19.5 cm, recalculation shows the maximum reach extends to 52.4 cm while maintaining the minimum reach at 35.2 cm, meeting all competition requirements. This mathematical verification before fabrication saves the team from building an inadequate mechanism and having to redesign during the critical week before competition.

Scenario: Marine Navigation During Coastal Fog

Captain Elena commands a fishing vessel returning to port in dense fog with GPS temporarily unavailable due to equipment failure. Using radar, she identifies two coastal navigation markers—a lighthouse and a prominent rocky point—at distances of 3.7 nautical miles and 2.9 nautical miles respectively. Her radar also shows these landmarks positioned at a relative bearing difference of 68° from her current position. Knowing the lighthouse and rocky point are 4.2 nautical miles apart according to her chart, she uses the Law of Cosines to verify her radar measurements form a valid triangle: calculated distance = 3.52 nautical miles versus charted 4.2 nautical miles. This 0.68 nautical mile discrepancy alerts her to a radar calibration error, likely from salt spray accumulation on the antenna. After cleaning the antenna and recalibrating, new measurements show 3.6 nm, 2.8 nm, with calculated landmark spacing of 4.17 nm—matching the chart within acceptable 0.03 nm tolerance. With her position now verified through triangulation, Elena safely navigates the remaining 8 nautical miles to port despite continued zero visibility conditions, demonstrating how the Law of Cosines serves as a critical navigation safety verification tool.

Frequently Asked Questions

▼ When should I use the Law of Cosines instead of the Pythagorean theorem?

▼ Why does my calculator give an error when solving for an angle with certain side lengths?

▼ How accurate is the Law of Cosines for very small or very large angles?

▼ Can I use the Law of Cosines for three-dimensional problems?

▼ What's the relationship between the Law of Cosines and the dot product formula in vector analysis?

▼ How do I choose between using Law of Cosines and Law of Sines for a particular triangle problem?

Free Engineering Calculators

Explore our complete library of free engineering and physics calculators.

Browse All Calculators →

About the Author

Robbie Dickson — Chief Engineer & Founder, FIRGELLI Automations

Robbie Dickson brings over two decades of engineering expertise to FIRGELLI Automations. With a distinguished career at Rolls-Royce, BMW, and Ford, he has deep expertise in mechanical systems, actuator technology, and precision engineering.

Wikipedia · Full Bio

Share This Article
Tags