This is an example of the Pythagorean Theorem. The path that is created is a right triangle. If you square the legs, their sum is equal to the square of the hypotenuse. The hypotenuse is the distance d in this problem.
The distance d could be described as:
