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? 开发者_如何学C The line is from startpoint(50,50),endPoint(50,0)....the some point may be (0,10),(2,45),etc..
- Make line equation
- 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
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.
精彩评论