# Determining if a Point3D passed another

I have 2 points A and B in 3D space (say of type Point3D). B needs to travel towards A and then stop either when it reached or passed B. The direction between the two points is known (can be easily calculated), so velocity is easy to set. How do I determine when point A reached or "passed" (given the direction) point B?

## 1 Answer

The vector between A and B is B - A. The magnitude of this vector is the distance between these points. If point A is traveling along this vector then it has reached point B when the magnitude is 0 and it passes B when the vector components change signs (positive to negative, or negative to positive) as compared to the original B - A vector.

For example, in 2D A = (3,4) B = (4, 6) B-A = (1, 2)

Point A will have passed point B when the signs of the vector components of B - A have changed compare to the original B - A values.

Another solution would be to use the dot product of the original B - A vector and the current B - A vector. If the value is positive then A has not reached B yet. If the solution is 0, then A = B. If the solution is negative then A has passed B. Further, if you normalize these vectors before you take the dot product you will get either 1, 0, or -1.

If A is not traveling along this vector then there needs to be a plane that contains B that acts as the threshold. A will start on one side of this plane and when it passes to the other side of the plane it would be considered passed B. Beyond that there orientation would be completely arbitrary.