Question

I just wonder how can I determine if a given 3D point lies on a line given by 2 points, and ALSO it lies between those 2 points?

Was it helpful?

Solution

Points a,b,c are collinear (all lie on a single line) if b-a,c-a are parallel, which is true iff the cross product (b-a) x (c-a) is zero. (That is, all three of its components are zero. You should probably actually permit them to be nonzero but very very small; exactly what that should mean will depend on your application.)

Given that points a,b,c are collinear, b lies between a and c iff the scalar product (b-a).(c-b) is positive. (Non-negative, if it's OK for b to be coincident with a or c.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top