Dot Products

How to 3D

Chapter 4: Transformation Machinery

Dot Products

In the last chapter we learned that two vectors are added by summing up their individual components. Adding vectors \(\mathbf{u}\) and \(\mathbf{v}\) has this notation:

$$\begin{bmatrix} u_0 \\ u_1 \\ u_2 \end{bmatrix} + \begin{bmatrix} v_0 \\ v_1 \\ v_2 \end{bmatrix} = \begin{bmatrix} u_0 + v_0 \\ u_1 + v_1 \\ u_2 + v_2 \end{bmatrix}$$

Addition, subtraction, and division are all component-wise operations. Multiplication, on the other hand, has several possible definitions. We could multiply corresponding components together. We've also seen the cross product, which measures the dissimilarity between two vectors. The multiplication operation we consider now is the dot product, which measures the similarity between two vectors. We'll achieve a unified transformation system by recasting all the transformations as dot products.

To compute the dot product of two vectors, we multiply their associated components and then sum the products. Because corresponding components are multiplied together, the two operands must have the same number of dimensions. If \(\mathbf{u}\) and \(\mathbf{v}\) are 2-vectors, this is their dot product:

$$\mathbf{u} \cdot \mathbf{v} = \begin{bmatrix} u_0 \\ u_1 \end{bmatrix} \cdot \begin{bmatrix} v_0 \\ v_1 \end{bmatrix} = u_0 \times v_0 + u_1 \times v_1$$

If \(\mathbf{u}\) and \(\mathbf{v}\) are 3-vectors, this is their dot product:

$$\mathbf{u} \cdot \mathbf{v} = \begin{bmatrix} u_0 \\ u_1 \\ u_2 \end{bmatrix} \cdot \begin{bmatrix} v_0 \\ v_1 \\ v_2 \end{bmatrix} = u_0 \times v_0 + u_1 \times v_1 + u_2 \times v_2$$

The spatial significance of the dot product is not obvious from its equation. To help build your intuition, drag the four points on the grid below to draw these four 2-vectors:

$$\begin{bmatrix} 3 \\ 1 \end{bmatrix} \qquad \begin{bmatrix} 4 \\ 2 \end{bmatrix} \qquad \begin{bmatrix} -5 \\ -1 \end{bmatrix} \qquad \begin{bmatrix} 1 \\ -3 \end{bmatrix}$$

Observe that \(\mathbf{\begin{bmatrix}3 & 1\end{bmatrix}}\) and \(\mathbf{\begin{bmatrix}4 & 2\end{bmatrix}}\) point in roughly the same direction. The \(\mathbf{\begin{bmatrix}3 & 1\end{bmatrix}}\) and \(\mathbf{\begin{bmatrix}-5 & -1\end{bmatrix}}\) point in roughly opposite directions. What are their dot products?

What is the dot product when two vectors are perpendicular to each other?

Your answers offer a clue about the dot product's meaning. What can we say about the two vectors if we know only their dot product? Verify your hypothesis interactively by dragging these vector endpoints around and examining the dot product that is automatically computed:

When the two vectors point in the same general direction, the dot product is positive. When the two vectors point in opposite directions, the dot product is negative. When the two vectors are perpendicular, the dot product is 0. Thus, the sign of the dot product describes the alignment of two vectors. The magnitude of the dot product is proportional to the magnitude of the vectors.

Measuring alignment between vectors will be very important when we add lighting to our renderers. For now, however, we are only interested in the dot product as a machine for multiplying and summing.

Should you want more practice, this widget endlessly generates random 3-vectors and asks you for their dot product:

← Unifying TransformsScale with Dots →