Find if point lays on line segment

前端 未结 12 1289
抹茶落季
抹茶落季 2020-11-30 04:01

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?

12条回答
  •  一整个雨季
    2020-11-30 04:53

    Let V1 be the vector (B-A), and V2 = (p-A), normalize both V1 and V2.

    If V1==(-V2) then the point p is on the line, but preceding A, & therefore not in the segment. If V1==V2 the point p is on the line. Get the length of (p-A) and check if this is less-or-equal to length of (B-A), if so the point is on the segment, else it is past B.

提交回复
热议问题