Learn R Programming

polyclip (version 1.10-7)

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)

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.

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.

Author

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

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.

References

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

Vatti, B. (1992) A generic solution to polygon clipping. Communications of the ACM 35 (7) 56--63. https://dl.acm.org/doi/10.1145/129902.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

polyclip.

Examples

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

Run the code above in your browser using DataLab