Introduction to Graphics Math

Dot Product

A: ()
B: ()

The dot product of two vectors is the sum of the products of each of their components. Keep in mind that the dot product yields a scalar value (a single number), rather than a vector. \[\textbf{A} \cdot \textbf{B}=A_{x} \cdot B_{x}+A_{y} \cdot B_{y}\] \[=(1.0) \cdot (-2.0)+(1.0) \cdot (3.0)\] \[=\underline{\underline{1.000}}\]

Things to try:

  • Move the vectors so they're pointing in roughly the same direction. When the vectors are less than 90 degrees apart, the dot product will be greater than 0.
  • Move the vectors so they're perpendicular to each other. When the the vectors are 90 degrees apart, the dot product is 0 (or very close to 0 when implemented with floating point numbers).
  • Move the vectors so they're roughly pointing away from each other. When the vectors are more than 90 degrees apart, the dot product will be less than 0.

One example of how this information could be used is when deciding whether to render certain faces of an object to the screen. The dot product of the direction of the face and the viewing direction can be used to make that decision. If the dot product is greater than 0, the face shouldn't be rendered because it is facing away from the viewer.

The dot product can be thought of as how much is one vector in line with another vector. Lighting and shading calculations often use the dot product to figure out how much light is being contributed to a given spot on an object. We're not going to get into that here. For more information search for diffuse or specular lighting calculations.

The dot product can also be used to find the angle between two vectors, and to project one vector onto another. We'll get into that below.