Dot Product
The dot product is an operation to find the similarity of two vectors.
In general it is defined as
The result is always a single number. Visually that equation means taking , squashing it onto and then multiplying the length of the squashed vector with the length of .

In code this would look like the following.
Vector greenVector = new Vector(4,0,2);
Vector orangeVector = new Vector(1,0,2);
double dotProduct = greenVector.dot(orangeVector);
You may be able to tell already that the dot product conveys information about the similarity between two vectors. The result can be any number when used on any vector. This can be somewhat hindering because how may one judge the similiarity if it can be any number. For example the dot product is a very large number when the two vectors point into almost the same direction ( is small) but have massively different lengths. The key is how we define "similarity". Most of the times the length of the vector is not relevant as we keep a length of 1 for most vectors when doing math around the origin. Therefore "similarity" for us essentially means we only care about the angle between two unit vectors. This also simplifies the equation to
The cosinus is always between -1 and 1 and for that reason the dot product will also be in this range. Here are some quick look-ups (angle in degree):
0
1
identical
90
0
form a 90 degree angle (orthogonal to each other)
180
-1
exactly opposite of each other

Last updated