Dot Product

Formula

Description:

The dot product may be defined algebraically or geometrically. In our example, we will be defining it algebraically. It is important to remember that in order to calculate the Dot Product of two vectors, those vectors must be equivalent in dimensional components. This means you are unable to calculate the dot product of vectors A = ( x , y ) and B = ( x , y, z ). Vector A is a 2 - Dimensional vector ( x , y ) while Vector B is a 3 - Dimensional Vector ( x , y , z ). 

However, it is possible to calculate the Dot Product of C and D if vector C = ( x , y ) and D = ( x , y ) as they both are 2 - Dimensional ( x , y ).

The two target vectors can have as many dimensional components as desired (as long as they are equivalent to one another in component length).

Algebraic Steps:

Step 1: Multiply each of the corresponding components (example: C.x * D.x)

Step 2: Add all of the products

Step 3: The resulting value from the sum of all products is the Dot Product.

Examples:

Vector A = ( 0 , 1 )

Vector X = ( 1 , 0 )

We first Multiply the corresponding components:

A.x * X.x = 0 * 1 = 0

A.y *  X.y  = 1 * 0 = 0

We then get the sum of the products: 0 + 0 = 0

The Dot Product of Vector A and Vector X = 0

Vector B = ( 0.5 , 0.5 )

Vector X = ( 1 , 0 )

We first Multiply the corresponding components:

B.x * X.x = 0.5 * 1 = 0.5

B.y * X.y = 0.5 * 0 = 0

We then get the sum of the products: 0.5 + 0 = 0.5

The Dot Product of Vector B and Vector X = 0.5

GLSL Example

Coded in Shadertoy

Coded in Shadertoy