The law of cosines is a generalization of the Pythagorean theorem that works for any triangle, not just right triangles. It relates the lengths of all three sides of a triangle to the cosine of one of its angles. If you know two sides and the angle between them (SAS), you can find the third side. If you know all three sides (SSS), you can find any angle. The formula is credited to the 9th-century Persian mathematician al-Khwarizmi, though the geometric principle was known to Euclid. Surveyors, navigators, and engineers use it daily to solve triangles that the Pythagorean theorem cannot handle.
What This Calculator Does
The calculator offers two modes. SAS mode finds the third side when you enter two sides and the included angle. SSS mode finds all three angles when you enter three sides. In both cases, the calculator also computes the remaining angles, the area using Heron's formula, and the perimeter. A visual triangle diagram updates with your inputs.
For right triangles specifically, use our Pythagorean Theorem Calculator or Right Triangle Calculator. For general triangle calculations, try our Triangle Calculator.
Inputs Required
- SAS mode: Two sides (a, b) and the included angle C (between 0 and 180 degrees)
- SSS mode: Three sides (a, b, c) that satisfy the triangle inequality
Outputs Provided
- Missing side or angle: The primary value you are solving for
- All three angles: Complete angle set with verification that they sum to 180 degrees
- Area: Computed using Heron's formula
- Perimeter: Sum of all three sides
- Visual diagram: A scaled triangle showing the computed values
How the Calculation Works
Law of Cosines: c^2 = a^2 + b^2 - 2ab * cos(C)
Rearranged for angle: cos(C) = (a^2 + b^2 - c^2) / (2ab)
Angle: C = arccos((a^2 + b^2 - c^2) / (2ab))
Heron's formula: Area = sqrt(s(s-a)(s-b)(s-c)), s = (a+b+c)/2
For the SAS case, the calculator plugs the two known sides and the included angle directly into the law of cosines formula to get the third side. Once all three sides are known, it uses the rearranged law of cosines to find the other two angles. For the SSS case, it applies the rearranged formula three times to find all three angles. The area is computed independently using Heron's formula, which only requires the three side lengths. The triangle inequality (sum of any two sides must exceed the third) is checked before computing angles, because an invalid triangle would produce a cosine value outside the range -1 to 1.
How to Use the Calculator
- Choose SAS (find a side) or SSS (find angles) based on what you know
- For SAS: enter the two known sides and the angle between them in degrees
- For SSS: enter all three side lengths
- Read the missing side or angle, plus all other triangle properties
- Verify that the angles sum to 180 degrees as a sanity check
Example Calculations
A surveyor in Denver needs to find the distance across a lake. She measures two sides from a point on shore: 120 meters and 95 meters, with an included angle of 60 degrees between them.
- a = 120, b = 95, C = 60 degrees
- c^2 = 120^2 + 95^2 - 2(120)(95)cos(60deg)
- c^2 = 14400 + 9025 - 22800(0.5) = 12025
- c = 109.66 meters
In a second example, a student in Atlanta has a triangle with sides 7, 9, and 5 and needs to find the angle opposite the side of length 9.
- a = 7, b = 5, c = 9 (finding angle C opposite c)
- cos(C) = (7^2 + 5^2 - 9^2) / (2 x 7 x 5) = (49 + 25 - 81) / 70 = -7/70 = -0.1
- C = arccos(-0.1) = 95.74 degrees
Real-World Scenarios
Land Surveying in Rural Montana
A licensed land surveyor in Billings, Montana is determining property boundaries for a 40-acre parcel with irregular shape. The parcel has three known boundary lines: 620 feet, 485 feet, and 380 feet. The client needs to know the angles at each corner for the deed description. Using the SSS mode, the surveyor enters all three sides. The calculator finds angle A = 38.3 degrees (opposite the 380-foot side), angle B = 51.2 degrees (opposite the 485-foot side), and angle C = 90.5 degrees (opposite the 620-foot side). The surveyor verifies the angles sum to 180 degrees. The area computes to 93,420 square feet (about 2.15 acres for this triangular section). The Bureau of Land Management requires angle measurements to the nearest minute (1/60 of a degree) for official plat maps, so the surveyor converts 38.3 degrees to 38 degrees 18 minutes for the filing.
Navigation and GPS Triangulation at Sea
A merchant marine officer on a cargo ship in the North Atlantic needs to determine her position using bearings from two known landmarks. She measures the distance to lighthouse A as 12.4 nautical miles and lighthouse B as 9.8 nautical miles. The angle between the two bearings from her position is 42 degrees. Using the SAS mode, she enters a = 12.4, b = 9.8, C = 42 degrees. The calculator gives c = 8.35 nautical miles, which is the distance between the two lighthouses. She can now plot her exact position on the nautical chart by drawing arcs of 12.4 NM from lighthouse A and 9.8 NM from lighthouse B. This is a classic triangulation method that predates GPS and remains a backup navigation technique. The US Coast Guard Navigation Center publishes light lists with exact coordinates for all US lighthouses.
Roof Framing for a Custom Home in Phoenix
A custom home builder in Phoenix is framing a roof with a non-standard pitch. The roof has two rafters of different lengths: 14.5 feet and 12.75 feet, meeting at the ridge with an included angle of 118 degrees. Using the SAS mode, the builder enters a = 14.5, b = 12.75, C = 118 degrees. The calculator returns c = 23.18 feet, which is the span of the roof at the eaves. The other two angles are 27.7 degrees and 34.3 degrees, telling the builder the pitch angles for each side of the roof. The area of the triangle (the gable end) computes to 76.42 square feet, which the builder needs for ordering siding material. The International Residential Code requires roof pitches to be specified in inches of rise per foot of run, so the builder converts the angles to 6:12 and 7.5:12 pitches respectively.
Common Mistakes to Avoid
- Using degrees instead of radians (or vice versa): The law of cosines requires the angle in radians for mathematical computation, but most people work in degrees. This calculator handles the conversion internally, but if you are computing by hand, make sure your calculator is in degree mode
- Violating the triangle inequality: In SSS mode, the sum of any two sides must be greater than the third. If you enter sides 3, 4, and 8, no triangle exists. The calculator will show an error message. Always check this condition first
- Confusing the included angle: In SAS mode, the angle must be between the two known sides, not opposite one of them. If you have two sides and a non-included angle (SSA), you need the law of sines instead, and there may be two valid solutions (the ambiguous case)
- Forgetting that the law of cosines reduces to the Pythagorean theorem: When the included angle is 90 degrees, cos(90) = 0, and the formula becomes c^2 = a^2 + b^2. The law of cosines is the general case. If you have a right triangle, the Pythagorean theorem is simpler and more direct
Limitations of This Calculator
This calculator handles the two most common law of cosines cases: SAS (two sides and included angle) and SSS (three sides). It does not handle the SSA (ambiguous) case, which requires the law of sines and may produce two valid triangles. The calculator works in degrees only, not radians. The area calculation uses Heron's formula, which is exact but may lose precision for very thin triangles (where the semiperimeter is close to one of the sides). For triangles with sides differing by more than 6 orders of magnitude, floating-point precision may affect the angle calculations. The visual diagram is a simplified representation and may not be to exact scale for extreme triangle shapes.
Authoritative Research and Resources
- USGS: Triangulation in Surveying - The United States Geological Survey explains how triangulation using the law of cosines and law of sines forms the basis of classical geodetic surveying. The USGS maintains the National Spatial Reference System using these principles.
- OpenStax Precalculus: Law of Cosines - A freely accessible precaculus textbook covering the law of cosines with derivations, worked examples, and applications. Published by Rice University as part of the OpenStax initiative.
- NIST Digital Library of Mathematical Functions - The National Institute of Standards and Technology maintains this authoritative reference for special mathematical functions, including inverse trigonometric functions used in triangle solving.