2

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?

user1118321
  • 25,567
  • 4
  • 55
  • 86
dummy
  • 63
  • 9

1 Answers1

6

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.)

Gareth McCaughan
  • 19,888
  • 1
  • 41
  • 62