I need a formula for the distance from a point to the nearest point on a line in three dimensional space.
My line is defined by two sets of coordinates p1 (x1, y1, z1), p2 (x2, y2, z2).
The point is defined by a third set of coordinates p3 (x3, y3, z3).
My actual interest is in determining if p3 is within the cylinder defined by the line segment p1, p2, radius r.
Since the actual goal is finding stars in a 3-d field that are roughly "between" star 1 (p1) and star 2 (p2), given the distance from p3 to the line is <= r, I can determine the distance p3 is from each of p1 and p2, and if both are less than the distance between p1 and p2, then it is "roughly between". The shape defined by these criteria isn't quite a cylinder, but it's actually closer to what I want.
Possibly what I really want is some kind of ovoid or two intersecting cones or something.
Thanks for your help
Frank
My line is defined by two sets of coordinates p1 (x1, y1, z1), p2 (x2, y2, z2).
The point is defined by a third set of coordinates p3 (x3, y3, z3).
My actual interest is in determining if p3 is within the cylinder defined by the line segment p1, p2, radius r.
Since the actual goal is finding stars in a 3-d field that are roughly "between" star 1 (p1) and star 2 (p2), given the distance from p3 to the line is <= r, I can determine the distance p3 is from each of p1 and p2, and if both are less than the distance between p1 and p2, then it is "roughly between". The shape defined by these criteria isn't quite a cylinder, but it's actually closer to what I want.
Possibly what I really want is some kind of ovoid or two intersecting cones or something.
Thanks for your help
Frank