Law of Cosines Calculator — Side & Angle Solver — Calculator
Solve triangles using the law of cosines. Find missing sides (SSS) or angles (SAS) with step-by-step work. Free, instant, and accurate.
The formula
c² = a² + b² − 2ab·cos(C)
- a, b, c
- Side lengths
- C
- Angle C
- cos(C)
- Cosine of angle C
How Law of Cosines Works
c² = a² + b² − 2ab·cos(C)
The law of cosines generalizes the Pythagorean theorem to any triangle. It relates the lengths of the sides of a triangle to the cosine of one of its angles. For a triangle with sides a, b, c and angle C opposite side c, the formula states that c² equals the sum of the squares of the other two sides minus twice their product times the cosine of the included angle. When C = 90°, cos(90°) = 0 and the formula reduces to c² = a² + b², which is the familiar Pythagorean theorem for right triangles.
- a, b, c
- Side lengths — The lengths of the three sides of the triangle, with c being the side opposite angle C.
- C
- Angle C — The angle opposite side c, measured in degrees. In SAS mode, this is the angle between sides a and b.
- cos(C)
- Cosine of angle C — The trigonometric cosine function evaluated at angle C, ranging from -1 to 1.
How to Use
- Select the mode: "Side (SSS)" when you know all three side lengths, or "Angle (SAS)" when you know two sides and the included angle.
- In SSS mode, enter the lengths of all three sides (a, b, c). The calculator finds each angle using the law of cosines step by step.
- In SAS mode, enter two side lengths (a, b) and the included angle (C) between them. The calculator finds the third side and the remaining angles.
- Review the work steps section to see each calculation step, including cosine evaluations and inverse cosine operations.
- Ensure your inputs satisfy the triangle inequality (SSS) or that the given angle is less than 180 degrees (SAS) for a valid triangle.
Quick Reference
| c² formula | c² = a² + b² − 2ab·cos(C) |
| cos(C) formula | cos(C) = (a² + b² − c²)/(2ab) |
| Right triangle | If C = 90°, cos(C) = 0, so c² = a² + b² |
| Obtuse angle | If C > 90°, cos(C) < 0, so c² > a² + b² |
Common Uses
- •Solving SSS triangles: finding all angles when only side lengths are known, which the law of sines alone cannot do
- •Solving SAS triangles: finding the third side and remaining angles when two sides and the included angle are known
- •Navigation and GPS: computing distances between points when direct measurement is impossible but distances from two reference points and the included angle are known
- •Physics and engineering: calculating resultant vectors using the parallelogram law, where the magnitude of the resultant depends on the angle between two vectors
- •Computer graphics: determining polygon geometry and performing collision detection in 3D space where triangle meshes are the fundamental building block
Understanding the Result
The law of cosines is one of the two fundamental tools (alongside the law of sines) for solving arbitrary triangles. It can be viewed as a generalization of the Pythagorean theorem that includes a correction term for non-right triangles. The formula c² = a² + b² - 2ab·cos(C) expresses the length of side c in terms of sides a, b and the included angle C between them. When angle C is 90 degrees, cos(90°) = 0 and the formula simplifies to c² = a² + b², which is the Pythagorean theorem. When angle C is acute (less than 90 degrees), cos(C) > 0 and the correction term is positive, making c² less than a² + b². When angle C is obtuse (greater than 90 degrees), cos(C) < 0 and the correction term becomes negative, making c² greater than a² + b². This behavior matches the geometric intuition: an obtuse angle "stretches" the opposite side. The law of cosines can be rearranged to solve for angles when all three sides are known: cos(C) = (a² + b² - c²)/(2ab). This rearrangement is the key to solving SSS triangles. The formula can be cyclically permuted for any vertex: a² = b² + c² - 2bc·cos(A) and b² = a² + c² - 2ac·cos(B). The law of cosines has a rich geometric interpretation. It can be derived by dropping an altitude from vertex A to side a, creating two right triangles, and applying the Pythagorean theorem to each. The distance from the foot of the altitude to vertex B is c·cos(B), and to vertex C is b·cos(C). These projections sum to the full side length a, giving the relationship a = b·cos(C) + c·cos(B), which is known as the projection formula and is equivalent to the law of cosines. Numerically, the law of cosines is well-behaved for most triangles but can be less accurate for very flat triangles (where angles are near 0 or 180 degrees) due to floating-point precision in the arccosine function. In such cases, the law of sines may give more accurate angle results after the first angle is determined.
Frequently Asked Questions
- When should I use the law of cosines instead of the law of sines?
- Use the law of cosines when you know all three sides (SSS) and need to find angles, or when you know two sides and the included angle (SAS) and need the third side. The law of sines alone cannot solve SSS triangles because it requires at least one angle. For SAS problems, you could use the law of sines after finding the third side, but the law of cosines directly computes it.
- How does the law of cosines relate to the Pythagorean theorem?
- The law of cosines is a generalization of the Pythagorean theorem. When the angle C is 90 degrees, cos(90°) = 0 and the law of cosines reduces to c² = a² + b². When C is acute (less than 90°), cos(C) > 0 and c² < a² + b². When C is obtuse (greater than 90°), cos(C) < 0 and c² > a² + b². The Pythagorean theorem is thus a special case of the law of cosines for right triangles.
- What happens if cos(C) is outside the range [-1, 1]?
- If the calculated cos(C) is outside the range [-1, 1] when using the SSS formula cos(C) = (a² + b² - c²)/(2ab), it usually means the triangle inequality is violated — the three side lengths cannot form a valid triangle. The calculator clamps values to [-1, 1] before applying arccosine to handle floating-point edge cases gracefully, but it also checks the triangle inequality at the start.
- Can I use the law of cosines to find all three angles from three sides?
- Yes, you can apply the law of cosines cyclically: cos(A) = (b² + c² - a²)/(2bc), cos(B) = (a² + c² - b²)/(2ac), and cos(C) = (a² + b² - c²)/(2ab). Compute each cosine and then apply arccosine to find each angle in degrees. The sum should equal 180 degrees as a verification step.
Cite this calculator
TheCalcUniverse. "Law of Cosines Calculator — Side & Angle Solver — Calculator." TheCalcUniverse, 2026, https://thecalcuniverse.com/math/law-of-cosines/. Accessed July 24, 2026.
Embed this calculator on your site
You may also like
-
Law of Sines
Apply the law of sines to solve triangles. Enter known side-angle pairs to find missing sides, angles, and the…
-
Trig Calculator
Calculate sine, cosine, tangent and their reciprocals for any angle. Also find angles from trig values with re…
-
Triangle Solver
Solve any triangle using SSS, SAS, or ASA input modes. Computes all sides, angles, area, and perimeter with dy…
-
Right Triangle
Solve right triangles using the Pythagorean theorem and SOH CAH TOA trigonometry. Find sides, angles, area, an…