grapes-inside-grapes: Check if points lie inside a simple polygon

%inside%R Documentation

Check if points lie inside a simple polygon

Description

Check if points lie inside a simple polygon

Usage

points %inside% polygon

Arguments

points

a data.frame with components x,y specifying the points

polygon

a data.frame with components x,y specifying the polygon

Value

a logical value matching the number of points, TRUE = "inside"

Examples

oldPar <- par(pty = "s", las = 1, xpd = NA)
pts <- expand.grid(x = seq(0, 1, len=25), y = seq(0, 1, len=25))
pol <- (1 + 1i)/2 + complex(argument = seq(-base::pi, base::pi, len=100))/3
show_red <- as_points(pts) %inside% as_polygon(pol)
plot(pts, col = ifelse(show_red, "red", "royal blue"), ann = FALSE, bty = "n",
     pch = ".", cex = ifelse(show_red, 4, 2.5), asp = 1)
polygon(pol, lwd = 0.5)
par(oldPar)

frenchCurve documentation built on June 18, 2022, 9:05 a.m.