# dot product

## Vector formulation

The law of cosines is equivalent to the formula
in the theory of vectors, which expresses the dot product of two vectors in terms of their respective lengths and the angle they enclose.

Fig. 10 — Vector triangle

Proof of equivalence. Referring to Figure 10, note that
and so we may calculate:
The law of cosines formulated in this notation states:
which is equivalent to the above formula from the theory of vectors.

1. $A\cdot B=|A\|B|\cos \theta$ (by definition of dot product)

If you think of the length of the 3 vectors |A|,|B| and |B-A| as the lengths of the sides of a triangle, you can apply the law of cosines here too (To visualize this, draw the 2 vectors A and B onto a graph, now the vector from A to B will be given by B-A. The triangle formed by these 3 vectors is applied to the law of cosines for a triangle)
$C^2 = A^2 + B^2 - 2|A||B|\cos \theta$
In this case, we substitute: |B-A| for c, |A| for a, |B| for b
and we obtain:

2.  $|B-A|^2 = |A|^2 + |B|^2 - 2 |A||B|\cos(\theta)$ (by law of cosines)

Remember now, that Theta is the angle between the 2 vectors A, B.
Notice the common term |A||B|cos(Theta) in both equations. We now equate equation (1) and (2), and obtain

$A\cdot B = (-(|B-A|^2) + |A|^2 + |B|^2) / 2$
and hence
$A\cdot B =\frac{1}{2} (-((B_x^2 - 2A_x B_x + A_x^2) + (B_y^2 - 2A_y B_y + A_y^2) + (B_z^2 - 2A_zB_z + A_z^2)) + A_x^2 + A_y^2 + A_z^2 + B_x^2 + B_y^2 + B_z^2)$
(by pythagorean length of a vector) and thus
$A\cdot B = A_xB_x + A_yB_y + A_zB_z$