About the Law of Cosines Calculator
Right-angled triangles can be solved with the Pythagorean theorem and basic trigonometry, but most triangles in surveying, navigation, engineering and physics have no right angle. The law of cosines extends Pythagoras to every triangle, and it is the tool to reach for when you know two sides and the angle between them, or all three sides and no angles.
This calculator handles both cases. In SAS mode it finds the third side, keeping an exact radical such as when one exists, then the two remaining angles. In SSS mode it checks that the sides can form a triangle and finds all three angles. In both modes it finishes with the area.
What is the law of cosines?
In a triangle with sides , and opposite angles , and , the law of cosines states . The same relationship holds for each side with its opposite angle.
When , and the formula reduces to , the Pythagorean theorem. The extra term corrects for the angle: it shrinks when is acute and lengthens it when is obtuse, because the cosine of an obtuse angle is negative.
How to use the Law of Cosines Calculator
- Choose SAS (two sides and the included angle) or SSS (three sides).
- Enter sides and .
- In SAS mode, enter the included angle in degrees; in SSS mode, enter the third side .
- Press Solve triangle to see the missing side or angles, then the area.
- Check the result: the angles should add to 180° and the largest angle should face the longest side.
Formulas
Law of cosines
Solved for an angle
Angle sum
Area (SAS)
Worked example: a = 5, b = 7, C = 60°
The example has , and an included angle . Since , the formula gives , so .
The engine then finds angle from the rearranged law of cosines, about , and angle from the angle sum, about . The area is .
The solution below is generated by the same engine that powers the calculator above.
Final answer
c = √39 ≈ 6.244997998; A ≈ 43.897886°, B ≈ 76.102114°
How we read your problem
SAS: find the third side and the remaining angles
Step-by-step solution
Substitute into c² = a² + b² − 2ab·cos C
Take the square root
Find angle A with the law of cosines rearranged
Angles of a triangle add to 180°
Area from two sides and the included angle
Formulas used
Law of cosines
Solved for an angle
Area
The triangle has sides a = 5, b = 7, c ≈ 6.244998 and angles A ≈ 43.897886°, B ≈ 76.102114°, C ≈ 60°. It is an acute scalene triangle with area ≈ 15.155445 and perimeter ≈ 18.244998.
Verification
- A + B + C = 180°.
- Heron's formula gives the same area: 15.155445.
- Law of sines ratios: a/sin A ≈ 7.2111026, b/sin B ≈ 7.2111026, c/sin C ≈ 7.2111026.
Detailed explanation
Solving SAS triangles
With two sides and the angle between them, the law of cosines gives the third side directly. Only one triangle is possible, so there is no ambiguity. With all three sides known, the rearranged formula gives each angle in turn. The calculator uses the law of cosines rather than the law of sines for the second angle because the cosine formula cannot confuse an acute angle with its obtuse supplement.
Obtuse included angles work the same way. For , and , , so and , longer than either given side as expected.
Solving SSS triangles
Three lengths form a triangle only if each pair adds to more than the third, the triangle inequality. The calculator checks this first: sides 1, 2 and 5 are rejected because . For valid sides it computes angle , then angle , both from the rearranged formula, and finds from the angle sum. Enter the longest side as and the first angle found tells you whether the triangle is acute, right or obtuse: sides 3, 4 and 5 give .
Law of cosines or law of sines?
Use the law of cosines for SAS and SSS, where no side-angle pair is known. Use the law of sines for ASA, AAS and SSA, where at least one side is known together with its opposite angle. The SSA case can have two solutions; the law of cosines cases never do, which makes them the more reliable starting point when you have a choice.
Common mistakes
- Using an angle that is not between the two given sides in SAS mode.
- Forgetting the factor of 2 in .
- Leaving a calculator in radian mode when the angle is in degrees.
- Subtracting before multiplying by , which breaks the order of operations.
- Skipping the triangle inequality check and getting an impossible cosine greater than 1.
Tips
- Label the triangle so the unknown side is and the known angle is .
- The largest angle is always opposite the longest side; use this to check your answer.
- Keep exact values such as until the final step to avoid rounding drift.
- Use the unit circle calculator to recall exact cosines of special angles.
- For right triangles, the distance formula and Pythagoras are quicker.
Frequently asked questions
When should I use the law of cosines?
When you know two sides and the included angle (SAS) or all three sides (SSS). In these cases no side is known with its opposite angle, so the law of sines cannot start.
How do you find an angle with the law of cosines?
Rearrange it to cos C = (a² + b² − c²) / (2ab), substitute the three sides and take the inverse cosine.
How is the law of cosines related to the Pythagorean theorem?
When the angle C is 90°, cos C is 0 and the formula becomes c² = a² + b². The law of cosines is the general version for any triangle.
What if my three sides do not form a triangle?
The calculator checks the triangle inequality and reports an error if one side is at least as long as the other two combined, as with sides 1, 2 and 5.
Are the triangle results exact or rounded?
When the third side is a square root it is shown exactly, such as √39 or 2√19, together with a decimal. Angles are given in decimal degrees.
How is the area calculated?
With the formula area = ½ab sin C, using two sides and the angle between them. In SSS mode the angle is found first.
Can the law of cosines give two triangles?
No. SAS and SSS data always determine a single triangle. The ambiguous case with two possible triangles only arises with SSA data and the law of sines.
Solve your triangle
Enter two sides and an angle, or three sides, above to find every missing measurement and the area.