[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Point inside/outside a polygon?
Here is what I ended up with when I had to solve this problem a few years
1) define a point that is outside of the polygon - easy enough.
2) define a line from the point in question to your outside point, say
3) Count the number of times that this line crosses any of the line
segments making up the polygon. If it's an even number, your point is
outside the polygon. If it's odd, your point is inside the polygon.
It's easy to see why this works geometrically with a simple drawing, and
it's pretty straightforward to code. David's method appears to be more
computationally efficient, as it avoids loops, but I don't fully understand
why it works. I'd be happy to send you my actual code if you'd like. The
polyfillv method works also, but is better for points on a regular grid,
and you have to convert the polygon coordinates to image coordinates to get
it to work.
Dennis Boccippio wrote:
> Hi all,
> Does anyone know of IDL routines for determination of whether a point
> datum is inside/outside a closed irregular polygon? I'm told that some
> variants of this functionality are available in Matlab and Mathematica,
> was curious if anyone had implemented a solution for IDL. My usual
> kludge to this is polyfill/mask-based, which is probably a very
> inefficient approach...
> Dennis Boccippio