home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: sci.math
- Path: sparky!uunet!cs.utexas.edu!sdd.hp.com!sgiblab!news.cs.indiana.edu!umn.edu!thompson
- From: thompson@atlas.socsci.umn.edu (T. Scott Thompson)
- Subject: Re: Polygon point enclosure
- Message-ID: <thompson.714934114@daphne.socsci.umn.edu>
- Sender: news@news2.cis.umn.edu (Usenet News Administration)
- Nntp-Posting-Host: daphne.socsci.umn.edu
- Reply-To: thompson@atlas.socsci.umn.edu
- Organization: Economics Department, University of Minnesota
- References: <7122@bigbird.hri.com.hri.com> <1992Aug26.235700.16224@infodev.cam.ac.uk>
- Date: Thu, 27 Aug 1992 16:48:34 GMT
- Lines: 30
-
- 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.
-
- This algorithm is in _Algorithms_ by Robert Sedgewick, Addison-Wesley
- (1983), pp 315-318. (I believe there is a second edition out, but I
- don't have it.) Sedgewick also gives some pseudo-code for the
- algorithm that takes into account some other nasty special cases, as
- well as the one where the ray includes one of the connecting line
- segments. For example, you must allow for the case where the ray
- enters or leaves the polygon at a vertex properly in order for the
- method to work.
-
- The strategy of choosing a new direction when the ray goes along a
- side is not efficient since there are ways of fixing up the count to
- allow for this. Sedgewick's algorithm provides the details.
-
- --
- T. Scott Thompson email: thompson@atlas.socsci.umn.edu
- Department of Economics phone: (612) 625-0119
- University of Minnesota fax: (612) 624-0209
-