Law of Cosines Calculator
Solve law cosines problems step-by-step with our free calculator. See formulas, worked examples, and clear explanations.
Reviewed by Manoj Kumar, Mathematics Educator
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)\nc2 = 25 + 49 - 2(5)(7)cos(60)\nc2 = 74 - 70(0.5) = 74 - 35 = 39\nc = sqrt(39) = 6.244998\n\nFinding angle A: cos(A) = (b2+c2-a2)/(2bc) = (49+39-25)/(2(7)(6.245)) = 63/87.43 = 0.72058\nA = arccos(0.72058) = 43.897 degrees\nB = 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\nC = arccos(0) = 90 degrees (right triangle!)\n\ncos(A) = (b2+c2-a2)/(2bc) = (36+100-64)/(2(6)(10)) = 72/120 = 0.6\nA = arccos(0.6) = 53.130 degrees\nB = 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.
References
Reviewed by Manoj Kumar, Mathematics Educator ยท Editorial policy