From my earliest days of graphics programming I’ve often overlooked the powers of the dot product. Often presented as a way to find the angle between two vectors, I believe the latter is an understatement as it can be used for so much more. A primitive to more complex calculations and models.

When I first encountered it was in the form of,

the left part of the equation is the “a dot b”, where we multiply each component of the vectors and then sum the results of the products. This translates to

It’s relatively simple and you can extend this to n-dimensions (in the latter examples we’re in the 3rd dimension). From a high level, dot product leads to a scalar. The higher this scalar, the more the two vectors are alike.

# Dot Product Identities for Vectors’ Relationship Classification

Dot product comes with a lot of identities which can be proven but I’ll not do this here. For example:

This is a very important identity not only form a geometric sense but also when working complex equations where we need to simplify or get rid of certain parts of them. If we know certain components of that equation to be orthogonal, then we can introduce the dot product to eliminate the vectors that would be perpendicular to the introduced one. The other reason the orthogonality is proven is quickly worked out here:

When we do flat shading for example, we will determine if a surface is lighted up or not just by checking if the surface’s normal is parallel to the direction of the light. Of course you can continue and achieve smooth shading by using a more continuous relationship between the normal and light directions angle as a variable in the light intensity.

The dot product can often times also be reduced when we have more information about the vectors. For example if the vectors are normalized then we know that their magnitude is one:

You can see how the equation can be simplified. A lot of times in the rendering pipeline we have such data. This **hints** at which version of the dot product to use.

Will update this post with more usages of the dot product and maybe delve into various graphical examples that heavily rely on dot products.

# Dot Product’s Applications in Geometry

Going back to our equation

The right side of it introduces a very important geometrical component between these two vectors, which is the **angle**. This is key because it opens up a whole world of information. Angle between two vectors can be used from collision detection and bounce ratio on surface to ray-tracing and calculating reflection/refractions and so much more. So to find the angle between to vectors, we can rework the equation to look like:

This works in 2D and 3D as we can just project the 3d vectors on a place to work the angles between them.

and in a more applicable case for lighting:

Even in the most complex applications with AI or shaders such as Ambient Occlusion, you can distill the equation to a few primitives, of which the dot product permeates.