FACTOID # 135: The Pitcairn Islands have the world’s shortest highway system, with only 6.4 kilometers of road. They also have the fourth-fewest main phone lines.
 
 Home   Encyclopedia   Statistics   Countries A-Z   Flags   Maps   Education   Forum   FAQ   About 
 
WHAT'S NEW
RELATED ARTICLES
People who viewed "Point in polygon" also viewed:
RECENT ARTICLES
More Recent Articles »
 

FACTS & STATISTICS    Simple view

  1. Select countries to view: (hold down Control key and click to select several)

     

     

    Compare:

     

     

  1. Select fact or statistic: (* = graphable)

     

     

     

  2. (OPTIONAL) Compare to statistic: (both need to be graphable)

     

     

     

  3. View result as:

     

       
(OR) SEARCH ALL encyclopedia, stats & forums:   

Encyclopedia > Point in polygon

In computational geometry, the point in polygon (also point-in-polygon or PIP) problem asks whether a given point in the plane lies inside, outside, or on the boundary of a simple polygon. It finds applications in areas that deal with processing geometrical data, such as computer graphics, geographical information systems (GIS), motion planning, and CAD.


Ray casting algorithms

One simple way of finding whether the point is inside or outside is to test how many times a ray starting from the point intersects the edges of the polygon. If it is an even number of times, the point is outside, if odd, inside.


Below is another variant of this approach.


Let P = (x0,y0) be the point to be tested against a polygon specified by the ordered list of its vertices (and hence, edges).

  • Set l := 0 and r := 0
  • for each line segment L of the polygon do the following:
    • if the y-coordinate of one endpoint of L is less than y0 and the other is greater than or equal to y0, then:
      • if P lies in the half plane to the left of L, then set l := l + 1, else set r := r + 1 (*)
  • if both l and r are odd, then P lies inside the polygon; if both l and r are even, then P lies outside the polygon; if one is even and the other is odd, then some error has occurred, e.g. a rounding error or the line segments do not form a closed path.

This algorithm does not always produce the correct answer if P lies directly on the polygon's boundary; if implemented on a computer with floating point arithmetic, the results may also be wrong if the point lies very close to that boundary, because of rounding errors. This is not normally a concern, as speed is much more important than complete accuracy in computer graphics. However, for a formally correct computer program, one would have to introduce a numerical tolerance ε and test in line (*) whether P lies within ε of L, in which case the algorithm should stop and report "P lies very close to the boundary."


External link

  • C code to determine if a point is in a polygon (http://www.ecse.rpi.edu/Homepages/wrf/research/geom/pnpoly.html)

  Results from FactBites:
 
Wikinfo | Polygon (930 words)
A polygon (from the Greek poly, for "many", and gwnos, for "angle") is a closed planar path composed of a finite number of straight line segments.
Polygons are named according to the number of sides, combining a Greek root with the suffix -gon, e.g.
A concyclic or cyclic polygon is a polygon whose vertices all lie on a single circle.
Point in Polygon Strategies (4418 words)
MacMartin (MacMartin 1992) pointed out that for polygons with a large number of edges there are generally runs of edges which have Y components with the same sign.
When a point is tested, the angle from the anchor edge is computed and a binary search is used to determine the wedge it is in, then the corresponding polygon edge is tested against it (Figure 4).
Points exactly on the unshared edge of a polygon will be classified as arbitrarily inside or outside the polygon by this method, however.
  More results at FactBites »


 

COMMENTARY     


Share your thoughts, questions and commentary here
Your name
Your comments
Please enter the 5-letter protection code

Want to know more?
Search encyclopedia, statistics and forums:

 


Lesson Plans | Student Area | Student FAQ | Reviews | Press Releases |  Feeds | Contact
The Wikipedia article included on this page is licensed under the GFDL.
Images may be subject to relevant owners' copyright.
All other elements are (c) copyright NationMaster.com 2003-5. All Rights Reserved.
Usage implies agreement with terms.