Law of Cosines Calculator
Solve law cosines problems step-by-step with our free calculator. See formulas, worked examples, and clear explanations.
Reviewed for accuracy by Manoj Kumar, Mathematics Educator
Law of Cosines Calculator
Calculator
Adjust values & calculateEnter your values below. Every result is computed in your browser โ no data is sent to any server.
Formula: c2 = a2 + b2 - 2ab cos(C)
Worked example โ c = 6.2450 | A = 43.897 deg | B = 76.103 deg | Area = 15.1554
Formula
c2 = a2 + b2 - 2ab cos(C)
The law of cosines relates the three sides of a triangle to the cosine of one angle. Rearranged to find an angle: cos(C) = (a2 + b2 - c2) / (2ab). It generalizes the Pythagorean theorem to all triangles.
Worked Examples
Example 1: Finding a Side (SAS)
Problem:Triangle has sides a = 5, b = 7, and included angle C = 60 degrees. Find side c.
Solution:c2 = a2 + b2 - 2ab cos(C) c2 = 25 + 49 - 2(5)(7)cos(60) c2 = 74 - 70(0.5) = 74 - 35 = 39 c = sqrt(39) = 6.244998 Finding angle A: cos(A) = (b2+c2-a2)/(2bc) = (49+39-25)/(2(7)(6.245)) = 63/87.43 = 0.72058 A = arccos(0.72058) = 43.897 degrees B = 180 - 43.897 - 60 = 76.103 degrees
Result:c = 6.2450 | A = 43.897 deg | B = 76.103 deg | Area = 15.1554
Example 2: Finding Angles (SSS)
Problem:Triangle has sides a = 8, b = 6, c = 10. Find all angles.
Solution:cos(C) = (a2+b2-c2)/(2ab) = (64+36-100)/(2(8)(6)) = 0/96 = 0 C = arccos(0) = 90 degrees (right triangle!) cos(A) = (b2+c2-a2)/(2bc) = (36+100-64)/(2(6)(10)) = 72/120 = 0.6 A = arccos(0.6) = 53.130 degrees B = 180 - 90 - 53.130 = 36.870 degrees
Result:A = 53.130 deg | B = 36.870 deg | C = 90 deg | Right triangle
Frequently Asked Questions
What is the law of cosines?
The law of cosines is a fundamental theorem in trigonometry that relates the lengths of the sides of any triangle to the cosine of one of its angles. The formula states c2 = a2 + b2 - 2ab cos(C), where a, b, and c are the three sides and C is the angle opposite side c. It can be rearranged to find any side or any angle. When C = 90 degrees, cos(C) = 0, and the formula simplifies to the Pythagorean theorem c2 = a2 + b2. Thus, the law of cosines is a generalization of the Pythagorean theorem that works for all triangles, not just right triangles. It is one of the most important tools in trigonometry alongside the law of sines.
When should you use the law of cosines instead of the law of sines?
Use the law of cosines in two specific situations: when you know two sides and the included angle (SAS) and need to find the third side, or when you know all three sides (SSS) and need to find an angle. The law of sines is better when you know a side and its opposite angle plus one other piece of information (ASA or AAS). A key advantage of the law of cosines for the SSS case is that it avoids the ambiguous case problem that can occur with the law of sines (where an angle could be acute or obtuse). The law of cosines always gives a unique, unambiguous result for an angle when all three sides are known. In practice, many problems can be solved with either law, but choosing the right one simplifies the calculation.
How do you solve a triangle using the law of cosines?
To solve a triangle completely means finding all three sides and all three angles. For SAS (two sides and included angle known): use c2 = a2 + b2 - 2ab cos(C) to find the third side, then use the law of cosines again or the law of sines to find the remaining angles. For SSS (all sides known): rearrange to cos(C) = (a2 + b2 - c2)/(2ab) to find each angle. Always verify that your three angles sum to 180 degrees as a check. When finding angles from the SSS case, it is best practice to find the largest angle first (opposite the longest side) using the law of cosines, because the law of cosines unambiguously determines whether the angle is acute or obtuse. Then find the remaining angles using either law.
How is the law of cosines derived?
The law of cosines can be derived using coordinate geometry. Place triangle ABC with vertex C at the origin and side b along the positive x-axis. Then A is at coordinates (b, 0) and B is at (a cos(C), a sin(C)). The distance from A to B (which is side c) is found using the distance formula: c2 = (a cos(C) - b)2 + (a sin(C))2. Expanding: c2 = a2 cos2(C) - 2ab cos(C) + b2 + a2 sin2(C). Since cos2(C) + sin2(C) = 1, this simplifies to c2 = a2 + b2 - 2ab cos(C). An alternative derivation uses the vector dot product: if vectors represent two sides, their difference gives the third side, and expanding the dot product of that difference yields the law of cosines.
What real-world problems use the law of cosines?
The law of cosines has extensive real-world applications. In surveying and land measurement, it calculates distances between points when direct measurement is impossible. In navigation, it determines the distance between two locations given bearings and a known baseline. In physics, it resolves force vectors when two forces act at an angle and you need the resultant magnitude. In astronomy, it helps calculate distances between celestial objects. In construction, it verifies that structures are square and calculates diagonal measurements. In GPS technology, trilateration algorithms use the law of cosines to determine position from satellite distances. Even in sports analytics, it calculates angles and distances for trajectory analysis in golf, baseball, and other projectile sports.
Can the law of cosines produce negative values?
The expression a2 + b2 - 2ab cos(C) can approach zero but never becomes negative for a valid triangle, because the result represents c2 (a squared length). However, the cosine term itself can be negative: when angle C is obtuse (greater than 90 degrees), cos(C) is negative, making -2ab cos(C) positive. This means c2 = a2 + b2 + |2ab cos(C)|, resulting in c being longer than the Pythagorean distance. When angle C equals exactly 90 degrees, the cosine term vanishes and the formula becomes the Pythagorean theorem. When rearranging to find an angle, cos(C) = (a2+b2-c2)/(2ab), a negative result for cos(C) means the angle is obtuse, which is perfectly valid and indicates the triangle has one angle greater than 90 degrees.
How does the law of cosines relate to the Pythagorean theorem?
The Pythagorean theorem is a special case of the law of cosines. The law of cosines states c2 = a2 + b2 - 2ab cos(C). When angle C is exactly 90 degrees, cos(90) = 0, so the term -2ab cos(C) vanishes entirely, leaving c2 = a2 + b2, which is the Pythagorean theorem. This means the Pythagorean theorem only works for right triangles, while the law of cosines works for all triangles. The extra term -2ab cos(C) acts as a correction factor: for acute angles (C less than 90), it subtracts from a2+b2 making c shorter; for obtuse angles (C greater than 90), it adds to a2+b2 making c longer. This beautiful generalization was known to ancient mathematicians and provides a unified framework for relating sides and angles in any triangle.
What is the ambiguous case and does it affect the law of cosines?
The ambiguous case (also called the SSA case) occurs when you know two sides and a non-included angle, which can sometimes yield zero, one, or two valid triangles. This ambiguity is a well-known problem with the law of sines but does NOT affect the law of cosines in its standard applications. When you use the law of cosines with SAS data (two sides and the included angle), the result is always unique. When finding angles from SSS data, the law of cosines is also unambiguous because cos(C) = (a2+b2-c2)/(2ab) gives exactly one angle in the range [0, 180] degrees. This is a significant advantage of the law of cosines over the law of sines for solving triangles: it never produces ambiguous results in its standard use cases.
How accurate is the law of cosines for very small or very large angles?
The law of cosines can suffer from numerical precision issues in certain extreme cases. When angle C is very close to 0 degrees, cos(C) is approximately 1, and c2 = a2 + b2 - 2ab becomes (a-b)2, which is correct but may lose precision due to catastrophic cancellation when a and b are nearly equal. Similarly, for angles near 180 degrees, precision issues can arise. For angles close to 90 degrees, the formula works excellently. In computational applications with very narrow or very flat triangles, alternative formulations like the haversine formula or the use of the law of cosines in a rearranged form can improve numerical stability. For Law of Cosines Calculator and typical practical applications with angles between 10 and 170 degrees, standard floating-point arithmetic provides more than adequate precision.
Can the law of cosines be used in three-dimensional space?
Yes, the law of cosines applies to any triangle regardless of its orientation in space, including triangles in three dimensions. If you know the 3D coordinates of three points, you can calculate the side lengths using the 3D distance formula, then apply the law of cosines to find the angles. The law of cosines also generalizes to dot products in linear algebra: for vectors u and v, the angle between them satisfies cos(theta) = (u dot v)/(|u||v|), which is derived from the law of cosines applied to the triangle formed by the vectors. In spherical trigonometry (triangles on the surface of a sphere), there is a spherical law of cosines: cos(c) = cos(a)cos(b) + sin(a)sin(b)cos(C), which is used in navigation and astronomy for calculations on the Earth's surface.
References
Reviewed for accuracy by Manoj Kumar, Mathematics Educator ยท Editorial policy
Related Calculators
๐ก๏ธCharles's Law
Calculate temperature and volume changes
โณQueue Wait Time (Little's Law)
Calculate queue wait times and required capacity using queueing theory
โณQueue Wait Time Little's Law Estimator
Calculate queue wait times and capacity needs using Little's Law and queueing theory (M/M/c)
๐งฎLaw of Sines Calculator
Calculate law of sines with inputs, formulas, and instant results.
๐งฎLaw of Tangents Calculator
Calculate law of tangents with inputs, formulas, and instant results.
๐งฎAnnulus Area Calculator
Calculate annulus area with inputs, formulas, and instant results.
๐งฎArea Calculator
Calculate area with inputs, formulas, and instant results.
๐งฎArea of a Rectangle Calculator
Calculate the area, perimeter, and diagonal of a rectangle. Find missing sides from known area. Convert between metric and imperial area units.