RE: finding if point is inside irregular rectangle

new topic     » goto parent     » topic index » view thread      » older message » newer message

What happens if both l[1][2] and l[2][2] < p[2]? It's still gonna check 
if p[1] is in bounds.

Chris

David Cuny wrote:
> 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. smile
> 
> -- David Cuny
> 
>

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu