I have a 3d point P and a line segment defined by A and B (A is the start point of the line segment, B the end).
I want to calculate the shortest distance between P and the line AB.
Calculating the distance of a point to an infinite line was easy as their was a solution on Wolfram Mathworld, and I have implemented that, but I need to do this for a line of finite length.
I have not managed to find a reliable solution for this in 3d after a lot of looking around.
I have implemented algorithms to calculate the dot product, cross product, magnitude and so on in C++ with a struct that contains floats x, y and z.
Pseudo code, links, or code in pretty much any language for this would be great.