如果找点线段规定 [英] Find if point lays on line segment

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

问题描述

我有两点定义线段A(X1,Y1,Z1)和B(X2,Y2,Z2)和点p(X,Y,Z)。我如何检查是否线段上的点规定?

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?

推荐答案

如果该点就行了,然后:

If the point is on the line then:

(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天全站免登陆