region.inside {conformal} | R Documentation |
Given a set of vertices of a polygon, determine which test points lie inside the polygon.
region.inside(test, vertices)
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. |
The algorithm works by checking whether the angle from the test point to the polygon changes by 2pi over one circuit.
A logical vector taking value TRUE
where the point lies inside the
polygon and FALSE
otherwise.
Peter Perkins (peter@caliban.ucsd.edu) on S-news: http://math.yorku.ca/Who/Faculty/Monette/S-news/0474.html
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)