Ekuation

method

Law of Cosines Calculator

Apply the Law of Cosines (c\u00B2 = a\u00B2 + b\u00B2 \u2212 2ab\u00B7cos C) to solve triangles from SSS or SAS inputs. Step-by-step solution with all derived properties.

Back to Triangle Calculator

Solve Mode

Select the combination of known values

Details: 3 sides

Known Values

Enter all three side lengths

Side opposite to angle A

Side opposite to angle B

Side opposite to angle C

Triangle Solver Tips

Click to show tips

Try an Example

Pick a scenario to see how the calculator works, then adjust the values

Find Angles from Three Sides (SSS)

A triangular park has paths of 120 m, 90 m, and 150 m. Find the angle at each corner.

Key values: a = 120 m · b = 90 m · c = 150 m

Find Third Side from Two Sides and Included Angle (SAS)

Two roads diverge at 55° — one is 8 km, the other is 12 km. What is the straight-line distance between their ends?

Key values: a = 8 km · b = 12 km · C = 55°

Documentation

The Law of Cosines

The law of cosines generalizes the Pythagorean theorem to any triangle:

c2=a2+b22abcos(C)c^2 = a^2 + b^2 - 2ab\cos(C)

When C=90°C = 90°, the cosine term vanishes (cos90°=0\cos 90° = 0) and you recover c2=a2+b2c^2 = a^2 + b^2. The law of cosines handles what the Pythagorean theorem cannot: oblique (non-right) triangles.

By symmetry, equivalent forms exist for each side:

a2=b2+c22bccos(A)a^2 = b^2 + c^2 - 2bc\cos(A)
b2=a2+c22accos(B)b^2 = a^2 + c^2 - 2ac\cos(B)

SSS Case: Three Sides Known

Rearrange the formula to find an angle when all three sides are known:

cos(C)=a2+b2c22ab\cos(C) = \frac{a^2 + b^2 - c^2}{2ab}

Example: Triangle with sides a = 5, b = 7, c = 8:

cos(C)=25+49642×5×7=1070=17\cos(C) = \frac{25 + 49 - 64}{2 \times 5 \times 7} = \frac{10}{70} = \frac{1}{7}
C=arccos ⁣(17)81.79°C = \arccos\!\left(\frac{1}{7}\right) \approx 81.79°

Strategy: In SSS problems, find the largest angle first (opposite the longest side). If it turns out to be obtuse, the other two angles must be acute, which avoids the ambiguous case when using the law of sines afterward.


SAS Case: Two Sides and Included Angle

Given sides aa and bb with included angle CC, find the third side directly:

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

Example: Sides 10 and 12, included angle 50°:

c=100+144240cos(50°)=244154.389.79.47c = \sqrt{100 + 144 - 240\cos(50°)} = \sqrt{244 - 154.3} \approx \sqrt{89.7} \approx 9.47

Law of Cosines vs. Law of Sines

SituationUse
SSS (three sides)Law of Cosines
SAS (two sides + included angle)Law of Cosines
ASA / AAS (two angles + one side)Law of Sines
SSA (two sides + non-included angle)Law of Sines (ambiguous case!)

The law of cosines never produces an ambiguous case. The inverse cosine function returns a unique angle in [0°,180°][0°, 180°], which is exactly the valid range for triangle angles. The law of sines can give two possible angles (the “ambiguous case”) because sinθ=sin(180°θ)\sin\theta = \sin(180° - \theta).


Geometric Derivation

Place the triangle with vertex C at the origin and side bb along the x-axis. Then vertex A is at (b,0)(b, 0) and vertex B is at (acosC,  asinC)(a\cos C, \; a\sin C). The distance formula gives:

c2=(acosCb)2+(asinC)2=a22abcosC+b2c^2 = (a\cos C - b)^2 + (a\sin C)^2 = a^2 - 2ab\cos C + b^2

which is exactly the law of cosines. This coordinate proof shows it is simply the distance formula applied to a triangle.


Frequently Asked Questions

What is the law of cosines?

The law of cosines states that c2=a2+b22abcos(C)c^2 = a^2 + b^2 - 2ab\cos(C), where CC is the angle opposite side cc. It generalizes the Pythagorean theorem to all triangles. When C=90°C = 90°, the cosine term vanishes and the formula reduces to c2=a2+b2c^2 = a^2 + b^2.

When do I use the law of cosines instead of the law of sines?

Use the law of cosines for SSS (three sides known) and SAS (two sides and the included angle). Use the law of sines for ASA, AAS, and SSA cases. The law of cosines never produces an ambiguous case, making it the safer choice when applicable.

How do I find an angle using the law of cosines?

Rearrange to cos(C)=a2+b2c22ab\cos(C) = \frac{a^2 + b^2 - c^2}{2ab}, then take the inverse cosine. For example, with sides 5, 7, and 8: cos(C)=25+496470=17\cos(C) = \frac{25 + 49 - 64}{70} = \frac{1}{7}, so C=arccos(1/7)81.79°C = \arccos(1/7) \approx 81.79°.

Why doesn't the law of cosines have an ambiguous case?

The inverse cosine function returns a unique angle in [0°,180°][0°, 180°], which is exactly the valid range for triangle angles. The law of sines can give two possible angles because sinθ=sin(180°θ)\sin\theta = \sin(180° - \theta), but cosine does not have this ambiguity.

How is the law of cosines derived?

Place vertex C at the origin with side bb along the x-axis. Vertex B is at (acosC,asinC)(a\cos C, a\sin C). Applying the distance formula gives c2=(acosCb)2+(asinC)2=a22abcosC+b2c^2 = (a\cos C - b)^2 + (a\sin C)^2 = a^2 - 2ab\cos C + b^2, which is the law of cosines.

More Math Calculators

Explore the category

Calculator Search

Search and find calculators