[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

*Subject*: Re: Point inside/outside a polygon?*From*: Med Bennett <mbennett(at)indra.com>*Date*: Fri, 10 Aug 2001 17:24:41 -0600*Newsgroups*: comp.lang.idl-pvwave*Organization*: Posted via Supernews, http://www.supernews.com*References*: <djboccip-ECCC8D.11144210082001@news.mia.bellsouth.net>*Reply-To*: mbennett(at)indra.com*Xref*: news.doit.wisc.edu comp.lang.idl-pvwave:26159

Here is what I ended up with when I had to solve this problem a few years back: 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 A-A'. 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. Med Bennett 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... > > Thanks, > > Dennis Boccippio

**References**:**Point inside/outside a polygon?***From:*Dennis Boccippio

- Prev by Date:
**Re: column labels on table widgets** - Next by Date:
**Re: Point inside/outside a polygon?** - Prev by thread:
**Re: Point inside/outside a polygon?** - Next by thread:
**Re: Point inside/outside a polygon?** - Index(es):