Re: finding if point is inside irregular rectangle
- Posted by David Cuny <dcuny at LANSET.COM> Feb 25, 2002
- 425 views
Derek Parnell wrote: > Not sure if this works for concave polygons. It should. Odd/Even edge crossing is pretty much the classic method. Plus, it's easy to optimize. You don't have to actually cast a ray, you just count the number lines that "cover" the point that lie above the point (ie: the x of the point lies between (x1, x2) and the one of (y1,y2) lies above the y of the point. Something like: -- p = {x,y} -- l = { {x1,y1}, {x2,y2}} function crosses( sequence p, sequence l ) if l[1][2] >= p[1] or l[2][2] >= p[2] then if l[1][1] < l[2][1] then return l[1][1] <= p[1] and l[2][1] >= p[1] else return l[2][1] <= p[1] and l[1][1] >= p[1] end if end if return 0 end function Untested code, of course. -- David Cuny