I have line segment defined by two points A(x1,y1,z1) and B(x2,y2,z2) and point p(x,y,z). How can I check if the point lays on the line segment?
Based on Konstantin's answer above, here is some C code to find if a point is actually on a FINITE line segment. This takes into account horizontal/vertical line segments. This also takes in to account that floating point numbers are never really "exact" when comparing them with one another. The default epsilon of 0.001f will suffice in most cases. This is for 2D lines... adding "Z" would be trivial. PointF class is from GDI+, which is basically just: struct PointF{float X,Y};
Hope this helps!
#define DEFFLEQEPSILON 0.001
#define FLOAT_EQE(x,v,e)((((v)-(e))<(x))&&((x)<((v)+(e))))
static bool Within(float fl, float flLow, float flHi, float flEp=DEFFLEQEPSILON){
if((fl>flLow) && (fl