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

  1. Newsgroups: comp.programming
  2. Path: sparky!uunet!usc!cs.utexas.edu!uwm.edu!csd4.csd.uwm.edu!markh
  3. From: markh@csd4.csd.uwm.edu (Mark)
  4. Subject: Re: How to decide if a point is inside a polygon?
  5. Message-ID: <1992Aug27.170349.13453@uwm.edu>
  6. Sender: news@uwm.edu (USENET News System)
  7. Organization: Computing Services Division, University of Wisconsin - Milwaukee
  8. References: <7121@bigbird.hri.com.hri.com>
  9. Date: Thu, 27 Aug 1992 17:03:49 GMT
  10. Lines: 21
  11.  
  12. In article <7121@bigbird.hri.com.hri.com> mps@hri.com writes:
  13. >I am in need of an algorithm to compute whether or not a given
  14. >point exists within or without a polygon. Any help or pointers to
  15. >where to look would be much appreciated.
  16.  
  17. Implement a polygon by putting its vertices in counter-clockwise order in a
  18. circular list.  A line drawn from a point inside to each of the vertices of
  19. the list will move in a counter clockwise direction as you go through each
  20. vertex in the list.  In other words, the sum of the angles AVB where V is the
  21. point in question and A and B are adjacent items in the circular list, where
  22. each angle is measured in a counterclockwise direction, will be 360 degrees.
  23. If the point lies outside the polygon, this sum will be 0.  If the point, V,
  24. lies ON the polygon, the sum will be 360.
  25.  
  26. So, this algorithm is linear in the number of vertices in the polygon.
  27.  
  28. In order to verify that you properly implemented the polygon, you have to
  29. perform a one-time check to make sure that the sum of all the angles ABC,
  30. where A, B, and C are adjacent items in the circular list, is 180*(N - 2)
  31. degrees, where N is the number of points in the polygon.  Again, the angles
  32. are measured in a counterclockwise direction.
  33.