is.insidePolygon {tigers} | R Documentation |
Test If a Point Is Inside a Polygon
Description
This function tests if a point is inside a polygon.
Usage
is.insidePolygon(XY, points)
Arguments
XY |
A two-column matrix giving the coordinates of a polygon. |
points |
a vector with two values giving the coordinates of a point, or a matrix with two columns. |
Details
The algorithm is based on “ray-tracing”: a segment is traced between
points
and an arbitrary point far from the polygon. If this
segment intersects an odd number of edges of the polygon, then
points
is inside the polygon.
The polygon must be open and can be in either clockwise or counterclockwise order. If the polygon is closed, it is modified internally without warning (the original polygon is not modified).
Value
a logical vector indicating whether each point is inside the polygon
defined by XY
.
Author(s)
Emmanuel Paradis
See Also
Examples
XY <- rbind(c(0, 0), c(0, 1), c(1, 1), c(1, 0))
stopifnot(is.insidePolygon(XY, c(0.5, 0.5)))
stopifnot(!is.insidePolygon(XY, c(1.5, 1.5)))
[Package tigers version 0.1-3 Index]