pointsInPolygon: Are points inside a polygon?

View source: R/pointsInPolygon.R

pointsInPolygonR Documentation

Are points inside a polygon?

Description

For a given matrix of points coordinates, pointsInPolygon returns a logical vector stating whether or not these points are inside a specific polygon whose coordinate as passed as an argument.

Usage

pointsInPolygon(points, polygon)

Arguments

points

a matrix of coordinates of points to be tested.

polygon

a two-columns matrix including the coordinate of the polygon.

Details

Implements the Ray-casting algorithm.

References

https://rosettacode.org/wiki/Ray-casting_algorithm#C

Examples

mat <- matrix(10*runif(100), 50)
res <- pointsInPolygon(mat, cbind(c(4,8,8,4),c(4,4,8,8)))
# Visual assessment
plot0(c(0,10), c(0,10))
polygon(c(4,8,8,4),c(4,4,8,8))
graphics::points(mat[,1], mat[,2], col=res+1)

inSileco/graphicsutils documentation built on Sept. 12, 2022, 11:13 p.m.