is.insidePolygon | R Documentation |
This function tests if a point is inside a polygon.
is.insidePolygon(XY, points)
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. |
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).
a logical vector indicating whether each point is inside the polygon
defined by XY
.
Emmanuel Paradis
is.open
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)))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.