Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

pointinpolygon

Test Whether a Point Lies Inside a Polygon


Description

Test whether each point lies inside a specified polygon.

Usage

pointinpolygon(P, A, eps, x0, y0)

Arguments

P

Spatial coordinates of the points to be tested. A list of two vectors named x and y.

A

A single polygon, specified as a list of two vectors named x and y.

eps

Spatial resolution for coordinates.

x0,y0

Spatial origin for coordinates.

Details

This is part of an interface to the polygon-clipping library Clipper written by Angus Johnson.

The argument A represents a closed polygon. It should be a list containing two components x and y giving the coordinates of the vertices. The last vertex should not repeat the first vertex.

Calculations are performed in integer arithmetic after subtracting x0,y0 from the coordinates, dividing by eps, and rounding to the nearest integer. Thus, eps is the effective spatial resolution. The default values ensure reasonable accuracy.

Value

An integer vector with one entry for each point in P. The result is 0 if the point lies outside A, 1 if the point lies inside A, and -1 if it lies on the boundary.

Author(s)

Angus Johnson. Ported to R by Adrian Baddeley Adrian.Baddeley@curtin.edu.au.

References

Clipper Website: http://www.angusj.com

Vatti, B. (1992) A generic solution to polygon clipping. Communications of the ACM 35 (7) 56–63. http://portal.acm.org/citation.cfm?id=129906

Agoston, M.K. (2005) Computer graphics and geometric modeling: implementation and algorithms. Springer-Verlag. http://books.google.com/books?q=vatti+clipping+agoston

See Also

Examples

A <- list(x=1:10, y=c(1:5,5:1))
  P <- list(x=4, y=2)
  pointinpolygon(P, A)

polyclip

Polygon Clipping

v1.10-0
BSL
Authors
Angus Johnson [aut] (C++ original, http://www.angusj.com/delphi/clipper.php), Adrian Baddeley [aut, trl, cre], Kurt Hornik [ctb], Brian D. Ripley [ctb], Elliott Sales de Andrade [ctb], Paul Murrell [ctb]
Initial release
2019-03-13

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.