This may seem a bit of an esoteric sort of topic but actually its damned useful in games.
One issue that crops up time and time again in games is the need to find out whether the vector that your ship/man/object/thing is moving along comes too close to / collides with another ship/man/object/thing ("the Possible Collision Object") in the game. This is a key navigational issue because frequently you will want to avoid collisions and plot a "safe" course.
One way to check this is demonstrated by the attached example code. The function (which, as you will see, works in 3D) returns the distance from your man to the point on his trajectory vector which is closest to the Possible Collision Object.
Its then a simple matter of normalising the trajectory vector, scaling it by the distance and adding it to your man's X, Y and Z position to get the X, Y and Z position of the closest point.
The distance between the Possible Collision Object and the closest point is then easy to solve.
Incidentally, whilst the attached function works in 3D, as the example program uses a 2D display, if you wanted to run the whole thing in full 3D you'd need to change the lines:
set vector2 1, x_pos - 500, y_pos - 400
set vector2 2, 500, 400
normalize vector2 1, 1
scale vector2 1, 1, distance#
add vector2 2, 1, 2
into 3D. The way to do this would be to make 2D vector types numbered 1 and 2 into 3D vector types.
Toodles
Philip
What do you mean, bears aren't supposed to wear hats and a tie? P1.3ghz / 384 megs / GeForce MX 5200 128meg / WinXP home