我怎样才能知道,如果一个点属于一定行? [英] How can I tell if a point belongs to a certain line?

查看:304
本文介绍了我怎样才能知道,如果一个点属于一定行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何才能知道一个点属于某一行?

How can I tell if a point belongs to a certain line?

例子是AP preciated,如果可能的话。

Examples are appreciated, if possible.

推荐答案

在最简单的形式,只需将坐标转换为直线方程,并检查是否相等。

In the simplest form, just plug the coordinates into the line equation and check for equality.

由于:

Point p (X=4, Y=5)
Line l (Slope=1, YIntersect=1)

插上X和Y:

Plug in X and Y:

   Y = Slope * X + YIntersect
=> 5 = 1 * 4 + 1
=> 5 = 5

所以,是的,一点就行了。

So yes, the point is on the line.

如果您的线条被重新psented在$ P $(X1,Y1),(X2,Y2)的形式,那么你就可以计算出斜率为:

If your lines are represented in (X1,Y1),(X2,Y2) form, then you can calculate slope with:

 Slope = (y1 - y2) / (x1-x2)

,然后得到的Y相交的:

And then get the Y-Intersect with this:

 Y-Intersect = - Slope * X1 + Y1;

编辑:我固定的Y相交(已经进行了X1 / Y1 ...)

I fixed the Y-Intersect (which has been X1 / Y1 ...)

您将必须检查 X1 - X2 不是 0 。如果是,则检查是否点上线检查,如果你点的Y值等于或者 X1 X2 。此外,检查点的X不是X1或X2。

You'll have to check that x1 - x2 is not 0. If it is, then checking if the point is on the line is a simple matter of checking if the Y value in your point is equal to either x1 or x2. Also, check that the X of the point is not 'x1' or 'x2'.

这篇关于我怎样才能知道,如果一个点属于一定行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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