Dot Products
Earlier you learned that two vectors are added by summing up their individual components:
Component-wise subtraction, multiplication, and division are defined similarly.
Vectors support operations beyond standard arithmetic. One very important operation is the dot product. To compute the dot product of two vectors, you multiply their associated components and then sum the products. Because their components are multiplied together, the two operands must have the same number of dimensions. Consider this dot product of 2-vectors \(\mathbf{u}\) and \(\mathbf{v}\):
Consider this dot product of 3-vectors \(\mathbf{u}\) and \(\mathbf{v}\):
The computational significance of the dot product is not obvious from its equation. To help build your intuition, drag three of the points on the grid below to draw these three 2-vectors:
Then compute these two dot products:
Observe that the first and second vectors point in roughly the same direction. The first and third vectors point in roughly opposite directions. What happens to the dot product when two vectors are perpendicular to each other? Add this vector to the grid using the fourth point:
It is perpendicular to the first. Compute the dot product between them:
Your three answers offer a clue about the dot product's meaning. 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, we are more 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: