查找点是否位于线段上 [英] Find if point lies on line segment

查看:19
本文介绍了查找点是否位于线段上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有由以下两点定义的线段:A(x1,y1,z1)B(x2,y2,z2).我有一点p(x,y,z).如何检查点是否位于线段上?

I have line segment defined by these two points: A(x1,y1,z1) and B(x2,y2,z2). I have point p(x,y,z). How can I check if the point lies on the line segment?

推荐答案

如果点在线那么:

(x - x1) / (x2 - x1) = (y - y1) / (y2 - y1) = (z - z1) / (z2 - z1)

计算所有三个值,如果它们相同(在某种程度的公差),你的点就在这条线上.

Calculate all three values, and if they are the same (to some degree of tolerance), your point is on the line.

要测试点是否在段中,而不仅仅是在线上,您可以检查是否

To test if the point is in the segment, not just on the line, you can check that

x1 < x < x2, assuming x1 < x2, or
y1 < y < y2, assuming y1 < y2, or
z1 < z < z2, assuming z1 < z2

这篇关于查找点是否位于线段上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆