home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / programm / 2511 < prev    next >
Encoding:
Text File  |  1992-08-27  |  1.9 KB  |  54 lines

  1. Newsgroups: comp.programming
  2. Path: sparky!uunet!s5!is1.is.morgan.com!is.morgan.com!berlin
  3. From: berlin@is.morgan.com (Alexander Berlin)
  4. Subject: Re: How to decide if a point is inside a polygon?
  5. Message-ID: <1992Aug27.153902@is.morgan.com>
  6. Sender: news@is.morgan.com
  7. Nntp-Posting-Host: chico
  8. Organization: Morgan Stanley - IS
  9. References: <7121@bigbird.hri.com.hri.com> <schnitzi.714934670@eola.cs.ucf.edu>
  10. Date: Thu, 27 Aug 1992 19:39:02 GMT
  11. Lines: 41
  12.  
  13. In article <schnitzi.714934670@eola.cs.ucf.edu>, schnitzi@cs.ucf.edu (Mark Schnitzius) writes:
  14. |> mps@sparc68.hri.com (Mark Stockley) writes:
  15. |> 
  16. |> >I am in need of an algorithm to compute whether or not a given
  17. |> >point exists within or without a polygon. Any help or pointers to
  18. |> >where to look would be much appreciated.
  19. |> 
  20. |> If I remember right the trick is to extend a line from the point
  21. |> infinitely in any direction (say, up).  Count how many of the
  22. |> polygon's edges this line passes through.  If it passes through
  23. |> an even number of polygon edges (including zero) the point is
  24. |> outside of the polygon.  An odd number indicates the point is
  25. |> inside the polygon.
  26.  
  27. Correct, but a word of caution should be said.
  28. When drawind the line in any direction, you want to avoid
  29. crossing corners of the polygon. So, make sure no one of the given points
  30. (that make polygon) belongs to the line.
  31.  
  32.         A           B
  33.         .___________.
  34.          \         /
  35.           \  Y.   /
  36.            \  |  /
  37.     X       \ | /
  38.     .________\|/___________________
  39.               |
  40.               | C
  41.               |
  42.  
  43. In the above example X is outside triangle ABC, Y is inside it. Their lines
  44. exactly the same crossings whith the edge. So instead of coming up with
  45. additional complicated rules just make sure you don't hit the corners. 
  46.  
  47. |> 
  48. |> Mark Schnitzius
  49. |> schnitzi@eola.cs.ucf.edu
  50. |> University of Central Florida
  51. ---
  52. Alex Berlin                     
  53. berlin@is.morgan.com
  54.