user141302
user141302

Reputation:

intersecting line and array of points?

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..

Upvotes: 1

Views: 183

Answers (2)

Vladimir
Vladimir

Reputation: 170849

  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

Upvotes: 2

High Performance Mark
High Performance Mark

Reputation: 78364

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.

Upvotes: 1

Related Questions