region.inside: Test for points inside a polygon

Description Usage Arguments Details Value Author(s) Examples

Description

Given a set of vertices of a polygon, determine which test points lie inside the polygon.

Usage

1
region.inside(test, vertices)

Arguments

test

a two-column matrix of points to be tested.

vertices

a two-column matrix of vertices of the polygon. The last vertex should be the same as the first.

Details

The algorithm works by checking whether the angle from the test point to the polygon changes by 2pi over one circuit.

Value

A logical vector taking value TRUE where the point lies inside the polygon and FALSE otherwise.

Author(s)

Peter Perkins (peter@caliban.ucsd.edu) on S-news: http://math.yorku.ca/Who/Faculty/Monette/S-news/0474.html

Examples

1
2
3
4
5
test <- as.matrix(expand.grid(x=0:10,y=0:10))
poly <- jitter(rbind(c(1,3), c(7,5), c(3,9)))[c(1:3,1),]
inside <- region.inside(test, poly)
plot(test, col=ifelse(inside,"red","black"), pch=16)
lines(poly)

conformal documentation built on May 2, 2019, 5:47 p.m.