Find if point lays on line segment

前端 未结 12 1292
抹茶落季
抹茶落季 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:52

    First take the cross product of AB and AP. If they are colinear, then it will be 0.

    At this point, it could still be on the greater line extending past B or before A, so then I think you should be able to just check if pz is between az and bz.

    This appears to be a duplicate, actually, and as one of the answers mentions, it is in Beautiful Code.

提交回复
热议问题