Reputation: 115
I have a problem in which i need to verify if a point had crossed a line-path,
a line path is collection of line(y=ax+b).
Does anyone know some known algorithim for this?
so i solved it like this: i added 2 points in the start and the end of the path- so now it is a polygon i added the 2 points in 90 degrees to the points in a fixed distance. and i used the ray algorithim.
Upvotes: 2
Views: 1897
Reputation: 51845
I know of two approaches:
Upvotes: 0
Reputation: 115
so i solved it like this: i added 2 points in the start and the end of the path- so now it is a polygon i added the 2 points in 90 degrees to the points in a fixed distance. and i used the ray algorithim.
edit: its not always 90 degrees, it's depens on the angle between point start and point end
Upvotes: 0
Reputation: 6026
Given a input point (x_1, y_1) , and your line is of the form y = ax + b
, then you can tell where your input point locates by putting x_1 into the line equation:
if y_1 == a * x_1 + b then (x_1, y_1) is on the line
if y_1 < a * x_1 + b then (x_1, y_1) locates below the line
if y_1 > a * x_1 + b then (x_1, y_1) locates above the line
So you can tell whether a point has crossed a line by keeping track of the above result of that point.
Upvotes: 1
Reputation: 6379
There are simple algorithms to know if a point is inside or outside a polygon: http://en.wikipedia.org/wiki/Point_in_polygon This can be adapted to a line path setting by pushing some edges of the polygon to infinity (in practice, you can put your line path in a large box and cansider the polygon formed by the part of the box that is on the right (or left, as you want) side of the line).
Upvotes: 1