views:

62

answers:

2

hi, i am having a line in normal graph,i want to know intersecting some points with that line , any formula for it?any help please? The line is from startpoint(50,50),endPoint(50,0)....the some point may be (0,10),(2,45),etc..

+1  A: 
  1. Make line equation
  2. Check if your point satisfies that equation.

The equation of line passing 2 arbitrary points (x1,y1) and (x2,y2) is:

(y1-y2)x + (x2-x1)y + (x1*y2 - x2*y1) = 0

In your case the line is just vertical and its equation is

x = 50

If you also want to check if point belongs to the line segment rather than to the whole line you can check that the following inequality holds (in addition to the previous condition) (may be it is not the most elegant/efficient solution):

(x-x1)*(x-x2)+(y-y1)*(y-y2) < 0
Vladimir
@Vladimir, you should be checking also if the point falls between the two points, in the given example if 0 <= y <= 50.
Unreason
+1  A: 

Well, if you know the endpoints of the line you are interested in it's easy. Any point on the line has the formula

a * p1 + (1-a) * p2

where p1, p2 are the endpoints and a is a scalar. If a is between 0 and 1 the point lies between the endpoints.

High Performance Mark
will you explain little bit more pls?
Mikhail Naimy
Try working through a few simple examples with pencil and graph paper, you'll figure it out.
High Performance Mark