The law of cosines is Pythagoras stretched to fit every triangle
Pythagoras's theorem works only when a triangle has a right angle. The law of cosines fixes that by adding a correction term that depends on the angle between two sides, and it becomes Pythagoras again when that angle is exactly square. In France it carries the name of a fifteenth-century Persian astronomer.
The rule links a triangle's three sides to the cosine of one angle. That makes it the tool of choice when you know all three sides and want an angle, or know two sides and the angle between them and want the third. It can also find a side when the known angle sits opposite one of the given sides, but then the answer may be two triangles, one or none, the same ambiguity that plagues the side-side-angle case in geometry. Computers struggle with very thin, sharp triangles: rounding errors can even produce a cosine slightly larger than one.
The idea is ancient, though not in its modern dress. Book II of Euclid's Elements, compiled around 300 BC, contains equivalent theorems stated in terms of rectangle areas, with obtuse and acute triangles handled in two separate propositions. Sine and cosine themselves were developed centuries later in India. Heron of Alexandria proved the converses, and astronomers such as al-Bīrūnī later applied the acute case to celestial problems.
Persian mathematicians turned it into a working method. Naṣīr al-Dīn al-Ṭūsī, around 1250, solved for a missing side by dropping a perpendicular and combining the law of sines with Pythagoras. Jamshīd al-Kāshī, whose trigonometric tables were the most accurate of his day, folded that procedure into a single recipe in his Key of Arithmetic of 1427. That is why French textbooks sometimes call it the théorème d'Al-Kashi.
Europe met the method through Regiomontanus's survey On Triangles of All Kinds in 1464. François Viète first wrote it with algebraic symbols in the sixteenth century, and the compact form taught today settled only in the early nineteenth.
Source: Law of cosines