home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!olivea!decwrl!deccrl!news.crl.dec.com!rdg.dec.com!ryn.mro4.dec.com!3d.enet.dec.com!roth
- From: roth@3d.enet.dec.com (Jim Roth)
- Newsgroups: sci.math
- Subject: Re: Polygon point enclosure
- Message-ID: <1992Aug31.215655.13098@ryn.mro4.dec.com>
- Date: 1 Sep 92 00:31:25 GMT
- Sender: news@ryn.mro4.dec.com (USENET News System)
- Organization: Digital Equipment Corporation
- Lines: 27
-
-
- In article <thompson.714934114@daphne.socsci.umn.edu>, thompson@atlas.socsci.umn.edu (T. Scott Thompson) writes...
- >gjm11@cus.cam.ac.uk (G.J. McCaughan) writes:
- >
- >>In article <7122@bigbird.hri.com.hri.com>, mps@sparc68.hri.com (Mark Stockley) writes:
- >
- >>> I'm looking for a method to determine if a point is enclosed
- >>> by a polygon. Any help would be greatly appreciated.
- >
- >>Well, here's one approach. Imagine a ray (=half-line) coming off from the point
- >>in some direction. Count how many of the sides of the polygon it goes through.
- >>(If it goes *along* any of those sides you're in trouble and should try another
- >>direction.) If it's an odd number the point is inside the polygon; if it's an
- >>even number the point is outside the polygon.
-
- It is much better to choose your ray parallel to the X axis in this approach.
-
- It is then easy to handle all "degenerate" cases such passing exactly
- thru a vertex (which you can detect precisely without incurring any roundoff
- error), passing coincident to a side (which again is easily and precisely
- checked), these cases handled with a simple convention about half open
- intervals in the x and y directions.
-
- You'll be pleasantly surprised at how nicely the algorithm comes
- out when you code it up this way. It's foolproof.
-
- - Jim
-