Closest distance from 3D point to vector line

First let's have a look at my little drawing:

I have an origin point p1 defined by x, y and z co-ordinates, and a vector v given by x, y and z magnitude.

I also have an arbitrary point, p2, given by x, y and z co-ordinates, in the direction of the vector v from the origin point.

I need to calculate the closest distance d from the point p2 to the line determined by the vector v. Put simply, I have no idea how to do this.

• A quick Google search gives tons of results for this. – Nathan Reed Jul 5 '14 at 17:27
• – Anko Jul 5 '14 at 17:28
• In the time it took to create that drawing you'd have had your answer with basic searches on your own and moved beyond it to other, more fun aspects of your game! – Patrick Hughes Jul 5 '14 at 18:23
• Two postings from other SE sites. 1: stackoverflow.com/questions/849211/… 2: stackoverflow.com/questions/4438244/… – Katu Jul 5 '14 at 21:12
• Thank you to those who provided constructive comments. I have absolutely no idea what I'm doing, I'm a complete math noob, and none of the things that I had found by searching (yes, I searched previously!) seemed to be very easily adaptable to my code. I appreciate now that there are quite a few methods that I can use to get what I'm trying to calculate! – ev0lution Jul 5 '14 at 22:13