Math

Law of Cosines Calculator

Settings
Reset
Share
Save
Embed
Report a bug

Share calculator

Add our free calculator to your website

Please enter a valid URL. Only HTTPS URLs are supported.


Use as default values for the embed calculator what is currently in input fields of the calculator on the page.


Input border focus color, switchbox checked color, select item hover color etc.


Please agree to the Terms of Use.

Preview

Save calculator

Calculator Settings

Please enter a value within the allowed range.

Please enter a value within the allowed range.

Please enter a value within the allowed range.

Please enter a value within the allowed range.

Share calculator

What is a law of cosines calculator?

The law of cosines calculator solves a triangle when you know two of its sides and the angle between them (the “side-angle-side” case). You enter side aa, side bb, and the included angle CC, and the calculator returns the length of the third side cc along with the two remaining angles AA and BB.

The law of cosines is a generalization of the Pythagorean theorem. When the included angle is exactly 90°90° the cosine term vanishes and the formula collapses back to c2=a2+b2c^2 = a^2 + b^2, the familiar relation for a right triangle.

How does it work?

The third side comes directly from the law of cosines:

c2=a2+b22abcosCc^2 = a^2 + b^2 - 2ab\cos C

Taking the square root gives cc:

c=a2+b22abcosCc = \sqrt{a^2 + b^2 - 2ab\cos C}

Once all three sides are known, the angle opposite side aa is recovered by rearranging the same law:

A=arccos(b2+c2a22bc)A = \arccos\left(\frac{b^2 + c^2 - a^2}{2bc}\right)

Because the three interior angles of any triangle sum to 180°180°, the last angle follows immediately:

B=180°ACB = 180° - A - C

The included angle CC must lie strictly between 0° and 180°180°, and both given sides must be positive, for the triangle to exist.

Worked examples

Right triangle. With a=3a = 3, b=4b = 4, and C=90°C = 90°, the cosine term drops out, so c=32+42=25=5c = \sqrt{3^2 + 4^2} = \sqrt{25} = 5. The remaining angles are A36.8699°A \approx 36.8699° and B53.1301°B \approx 53.1301°, recovering the classic 3-4-5 triangle.

Oblique triangle. With a=5a = 5, b=7b = 7, and C=60°C = 60°, we get c=52+72257cos60°=25+4935=396.2450c = \sqrt{5^2 + 7^2 - 2 \cdot 5 \cdot 7 \cdot \cos 60°} = \sqrt{25 + 49 - 35} = \sqrt{39} \approx 6.2450.

Practical notes

The law of cosines is most useful when the law of sines cannot start a solution — specifically in the side-angle-side and side-side-side cases, where no side and its opposite angle are known together. Surveyors, navigators, and engineers rely on it to compute distances across a baseline when only two legs and the angle between them can be measured.

If instead you know two angles and a side, or two sides and a non-included angle, the law of sines is the more direct tool. For the special right-triangle case you can also use the hypotenuse calculator, and to evaluate the cosine of the included angle on its own, see the trigonometry calculator.

Report a bug

This field is required.