Law of cosines in this visualization
Take a triangle with sides and and the angle between them. These three fix the third side , and the law of cosines says how: . The last term corrects the Pythagorean theorem. When is a right angle, and the law is the Pythagorean theorem itself. When is acute, and is less than . When it is obtuse, and is more. In the picture the correction is the two yellow rectangles beside .
Why: the squares cut by the altitudes
Drop the altitude from to the line and carry it on through the square on . It meets the line at , and , the projection of on . So the rectangle by has area , and the one by has area for the same reason. Every one of the six rectangles is a side times the projection of a neighbouring side on it: the product of the two sides at that corner times the cosine of the angle there. So the two rectangles beside a corner have the same area, even when they differ in shape (3 by 2 and 4 by 1.5 at the start). Add the first two equations above and subtract the third: . This is the area argument behind Euclid’s Elements II.12 and II.13, with signed areas so that one argument covers every case.
Obtuse angles: negative pieces
When is obtuse, the altitudes from and land on the sides extended beyond . The projection now points away from , so as a signed length it is . The rectangle by reaches past the square on , and the piece by is the part outside, counted as negative. The three equations still hold, so the law still holds, and the negative makes larger than . This is what a negative cosine is for: one formula, no separate case. The same happens at any obtuse corner. If is obtuse, the two dotted pieces are negative, and the law about is unchanged.
Two ways to use it
Given two sides and the angle between them, the law gives the third side: with 3, 4 and 60°, , so . Read backwards, it gives an angle from three sides: . For the sides 3, 5 and 7, , so . The sign of alone tells whether is acute, right or obtuse, which extends the converse of the Pythagorean theorem.
Things to notice
- There is one law for each corner: and . Each uses the angle between the two sides on the right.
- With vectors from to and from to , the side is the length of , and the law reads : the dot product is .
Controls
- Drag A to turn angle C; pulling it toward or away from C changes b. Drag B along CB to change a. The sides catch on whole numbers and the angle on 30°, 45°, 60°, 90°, 120°, 135° and 150°.
- The fields take fractions and roots such as √2 for the sides, and degrees for the angle; the keys set 60°, 90° and 120°. Projections draws the feet of the altitudes from A and B and the projections b cos C and a cos C.
- With the keyboard, Tab to A and use the arrow keys to turn the angle, with Shift for 10° and Page Up or Page Down for the next special angle. Tab to B and use left and right to change a.