home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / sci / math / 10635 < prev    next >
Encoding:
Text File  |  1992-08-27  |  2.0 KB  |  44 lines

  1. Newsgroups: sci.math
  2. Path: sparky!uunet!cs.utexas.edu!sdd.hp.com!sgiblab!news.cs.indiana.edu!umn.edu!thompson
  3. From: thompson@atlas.socsci.umn.edu (T. Scott Thompson)
  4. Subject: Re: Polygon point enclosure
  5. Message-ID: <thompson.714934114@daphne.socsci.umn.edu>
  6. Sender: news@news2.cis.umn.edu (Usenet News Administration)
  7. Nntp-Posting-Host: daphne.socsci.umn.edu
  8. Reply-To: thompson@atlas.socsci.umn.edu
  9. Organization: Economics Department, University of Minnesota
  10. References: <7122@bigbird.hri.com.hri.com> <1992Aug26.235700.16224@infodev.cam.ac.uk>
  11. Date: Thu, 27 Aug 1992 16:48:34 GMT
  12. Lines: 30
  13.  
  14. gjm11@cus.cam.ac.uk (G.J. McCaughan) writes:
  15.  
  16. >In article <7122@bigbird.hri.com.hri.com>, mps@sparc68.hri.com (Mark Stockley) writes:
  17.  
  18. >> I'm looking for a method to determine if a point is enclosed
  19. >> by a polygon. Any help would be greatly appreciated.
  20.  
  21. >Well, here's one approach. Imagine a ray (=half-line) coming off from the point
  22. >in some direction. Count how many of the sides of the polygon it goes through.
  23. >(If it goes *along* any of those sides you're in trouble and should try another
  24. >direction.) If it's an odd number the point is inside the polygon; if it's an
  25. >even number the point is outside the polygon.
  26.  
  27. This algorithm is in _Algorithms_ by Robert Sedgewick, Addison-Wesley
  28. (1983), pp 315-318.  (I believe there is a second edition out, but I
  29. don't have it.)  Sedgewick also gives some pseudo-code for the
  30. algorithm that takes into account some other nasty special cases, as
  31. well as the one where the ray includes one of the connecting line
  32. segments.  For example, you must allow for the case where the ray
  33. enters or leaves the polygon at a vertex properly in order for the
  34. method to work.
  35.  
  36. The strategy of choosing a new direction when the ray goes along a
  37. side is not efficient since there are ways of fixing up the count to
  38. allow for this.  Sedgewick's algorithm provides the details.
  39.  
  40. --
  41. T. Scott Thompson              email:  thompson@atlas.socsci.umn.edu
  42. Department of Economics        phone:  (612) 625-0119
  43. University of Minnesota        fax:    (612) 624-0209
  44.