Unit 2 · Length, angle and the dot product

Bonus lesson · Available to read

Bonus: proving the law of cosines

Why c² = a² + b² − 2ab cos θ holds in any triangle, and how it gives a · b = ‖a‖ ‖b‖ cos θ.

The previous lesson stated that a · b = ‖a‖ ‖b‖ cos θ follows from the law of cosines. This bonus lesson proves that law and then shows how it turns into the dot product formula.

Take any triangle with vertices A, B and C. Let θ be the angle at C, let a = |CB| and b = |CA| be the two sides that meet there, and let c = |AB| be the side opposite θ. The law of cosines says

c² = a² + b² − 2ab cos θ.

When θ = 90°, cos θ = 0 and the formula reduces to Pythagoras' theorem, c² = a² + b². The extra term −2ab cos θ corrects Pythagoras for angles that are not right angles.

Proof. Drop a perpendicular from B to the line through C and A, and call its foot H. In the right triangle CHB, the side along the base is CH = a cos θ and the height is BH = a sin θ. The rest of the base is HA = b − a cos θ.

Triangle CBA with angle θ at C, sides a and b meeting there and side c opposite. A dashed perpendicular from B meets the base at H, splitting it into a cos θ and b − a cos θ, with height a sin θ.

Now apply Pythagoras to the right triangle BHA:

c² = (a sin θ)² + (b − a cos θ)²
c² = a² sin²θ + b² − 2ab cos θ + a² cos²θ
c² = a² (sin²θ + cos²θ) + b² − 2ab cos θ
c² = a² + b² − 2ab cos θ,

using the identity sin²θ + cos²θ = 1. If θ is obtuse, H lands outside the segment CA, beyond C. Then cos θ is negative, a cos θ is a signed length, and the same algebra goes through unchanged.

From the law of cosines to the dot product. Put the vertex C at the origin and let a and b be the vectors along the two sides, so their lengths are ‖a‖ and ‖b‖. The third side runs from the tip of b to the tip of a, which is the vector a − b. Expanding its squared length with the dot product gives

‖a − b‖² = (a − b) · (a − b) = ‖a‖² + ‖b‖² − 2 a · b.

Vectors a and b from a common point with angle θ between them, and the dashed vector a − b joining their tips, with the equations showing a · b = ‖a‖ ‖b‖ cos θ.

The law of cosines says the same squared length equals ‖a‖² + ‖b‖² − 2 ‖a‖ ‖b‖ cos θ. The two expressions agree term by term except for the last one, so those must be equal too:

a · b = ‖a‖ ‖b‖ cos θ.

← Back to Dot product: the meaning

The takeaway

c² = a² + b² − 2ab cos θ; written with vectors, it gives a · b = ‖a‖ ‖b‖ cos θ.

Practice

0 of 4 attempted

  1. 1Calculate

    Two sides of a triangle, a = 3 and b = 5, meet at an angle of 60°. Find the third side c.

    Saved in this browser

  2. 2Multiple choice

    What does the law of cosines reduce to when θ = 90°?

  3. 3Recall

    In the proof, why is HA = b − a cos θ?

    Saved in this browser

  4. 4Apply

    Explain in one sentence why a · b must equal ‖a‖ ‖b‖ cos θ.

    Saved in this browser