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).
Explanation
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+b2−2abcosC
a, b — the two sides whose lengths you know
C — the angle between them, entered in degrees
c — the side you are after, the one opposite C
The pairing matters. C has to be the included angle, sitting between a and b and facing c. Feed in some other angle and you are solving a different triangle.
Example
Take a=5, b=7 and C=60∘. Since cos60∘=0.5,
c=52+72−2×5×7×0.5=25+49−35=39
so c≈6.2450.
Notes
Angles go in as degrees, not radians.
When C=90∘ the cosine term vanishes and the formula collapses to c=a2+b2, the Pythagorean theorem.
An obtuse C makes cosC negative, so −2abcosC adds to the total and c comes out longer than it would at a right angle. A sharper angle pulls c shorter.
Keep C strictly between 0∘ and 180∘. Within that range the expression under the square root is always positive, so a real third side always exists.