pnpoly: Point Inclusion in Polygon Test

View source: R/pnpoly.R

pnpolyR Documentation

Point Inclusion in Polygon Test

Description

Point inclusion test by W. Randolph Franklin to test for inclusion of a set of points within a polygon defined by a set of vertices.

Usage

pnpoly(points, vertices)

Arguments

points

Points to be tested as any form appropriate for xy.coords.

vertices

Points that define the vertices of the polygon, also processed by xy.coords where the order defines the polygon and the first and last points will be connected to close the polygon.

Value

Logical vector indicating whether each point lies in (TRUE) or out (FALSE) of the polygon.

Examples

  vv <- list(x = c(4.7, 3.8, 2, 3.6, 6.9, 6.9),
    y = c(9, 5.8, 4.7, 2.1, 4.2, 7.5))
  pp <- list(x = c(3.3, 6, 3.2, 4.9),
    y = c(4.4, 4.6, 7.2, 6.9))
  plot(1:10, 1:10, type = "n")
  polygon(vv)
  text(pp$x, pp$y, 1:4, col = 2)
  data.frame(point = 1:4, inside = pnpoly(pp, vv))


ornelles/EBImageExtra documentation built on Aug. 10, 2022, 11:44 p.m.