region.inside {conformal}R Documentation

Test for points inside a polygon

Description

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

Usage

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

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)

[Package conformal version 1.1 Index]