Law of Cosines: Find the Third Side of a Triangle

Calculates the remaining side from two sides and the angle between them (in degrees) with the law of cosines c = √(a² + b² − 2ab·cos C).

The law of cosines gives you the third side of a triangle when you know two sides and the angle between them. It generalises the Pythagorean theorem, which only works for right triangles, to every triangle.

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

The pairing matters. CC has to be the included angle, sitting between aa and bb and facing cc. Feed in some other angle and you are solving a different triangle.

Example

Take a=5a = 5, b=7b = 7 and C=60C = 60^\circ. Since cos60=0.5\cos 60^\circ = 0.5,

c=52+722×5×7×0.5=25+4935=39c = \sqrt{5^2 + 7^2 - 2 \times 5 \times 7 \times 0.5} = \sqrt{25 + 49 - 35} = \sqrt{39}

so c6.2450c \approx 6.2450.

Notes