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.

  • 2
    \$\begingroup\$ A quick Google search gives tons of results for this. \$\endgroup\$ – Nathan Reed Jul 5 '14 at 17:27
  • 1
    \$\begingroup\$ Also answered well at Math SE. \$\endgroup\$ – Anko Jul 5 '14 at 17:28
  • 1
    \$\begingroup\$ 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! \$\endgroup\$ – Patrick Hughes Jul 5 '14 at 18:23
  • \$\begingroup\$ Two postings from other SE sites. 1: stackoverflow.com/questions/849211/… 2: stackoverflow.com/questions/4438244/… \$\endgroup\$ – Katu Jul 5 '14 at 21:12
  • \$\begingroup\$ 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! \$\endgroup\$ – ev0lution Jul 5 '14 at 22:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.