Quick Distance comparison:
In this tutorial, we will learn how to quickly find out the shortest distance comparison. We add a new character to the previous example Blinky (B). The goal is to find out If Inky(I) is closer to Pacman(P) or Blinky(B).
Using the vector length calculation, we are going to compare the length of the vector with the length of vector
Applying Pythagoras theorem to calculate the length, we have
where Compare means we are trying to find out if |BP| is bigger or |IP| is bigger.
Eliminating the square root on both sides by squaring, we have:
Rewriting these in the original form:
This factor is faster computationally to compare the lengths, rather than the vectors themselves.