points.in.poly(x, y, polygon)
x
.
x
. If
TRUE
then the corresponding
point is inside the given polygon and so on.
if a ray from a point to an edge intersects a horizontal edge, i.e. is
collinear with it, the
C program will return
TRUE
even if such point is not in the polygon.
# 100 points on a unit square x <- runif(100); y <- runif(100) # A square polygon in the center: pcenter <- list(x=c(.25,.25,.75,.75), y=c(.25,.75,.75,.25)) pin <- points.in.poly(x, y, pcenter) # Plot the unit square and the center square: plot(x, y, type='n'); polygon(pcenter, density=0, col=2) # Plot only the points in the center square: points(x[pin], y[pin], col=3)