views:

445

answers:

6

Hi there,

I asked "How can I tell if a point belongs to a certain line?" before and I found a suitable answer so thank you very much.

Now, I would like to know how to tell if a certain point is close to my line.

+17  A: 
Alan Jackson
Note: If you are dealing with line segments (ie not infinitely long lines), this might yield wrong results: The point might be far from the endpoints of the segment and nevertheless have a small normal distance...
MartinStettner
Also note that if you're going to turn around and compare d to D, it will be more efficient to compare |(x2 - x1) x (x1 - x0)|^2 to D^2 |x2 - x1|^2, saving two square roots and a division at the cost of a multiply.
Dave
Thank you Mr.Alan But the link doesn't work!.I tried the equation that you put before but this give me the distance between the new point and the first point of the line not the hole line.Please Excuse me for my bad language.Sincerly,Wahid
Wahid Bitar
I'm not sure why the link doesn't work for you, a google search for "Point-Line Distance (2-Dimensional)" will bring it up as the first response and it goes into much more detail.
Alan Jackson
In case you can't get to the link and you just want an equation to plug the numbers in, I put up the formula you want.
Alan Jackson
Excuse me Mr.Alan but the formula too doesn't appear!.
Wahid Bitar
The site must be blocked from your location, sorry. The formula is: abs((x2-x1)*(y1-y0)-(x1-x0)(y2-y1)) / sqrt((x2-x1)^2 + (y2-y1)^2)
Alan Jackson
+5  A: 

Distance between a point and a line

Lou Franco
+1  A: 

Google is your friend: Point-Line Distance (2-Dimensional). You can just use the equation at the bottom and there you go.

n3rd
A: 

Basically, what you want to do it find the normal line — that is, a line perpendicular to your line — that intersects your point and the line, and then compute the distance along that line.

Charlie Martin
Yes Sir but i'm very weak in math so please help me and give me the equation for this.
Wahid Bitar
See the top one. It's all there.
Charlie Martin
A: 

How close is near?

Some geometry will give you the answer you need, you just need to be aware of the following steps.

Assuming your like is of the form y=mx+b, the shortest distance to your point will be the line perpendicular to your starting line (m1=-1/m), intersecting your point in question.

From there you calculate the distance between the intersection point and the point in question.

Ian Jacobs
slight important correction Ian, slope of line 2 is negative reciprocal of slope line 1 ( m1 = -1/m ) –
Charles Bretana
My mistake... Never good at checking my work :-)
Ian Jacobs
A: 
Wahid Bitar