pnp {recexcavAAR}R Documentation

Check if a point is within a polygon (2D)

Description

pnp is able to determine if a point is within a polygon in 2D space. The polygon is described by its corner points. The points must be in a correct drawing order.

Based on this solution: Copyright (c) 1970-2003, Wm. Randolph Franklin http://wrf.ecse.rpi.edu/pmwiki/pmwiki.php/Main/Software#toc24

Usage

pnp(vertx, verty, testx, testy)

Arguments

vertx

vector of x axis values of polygon corner points

verty

vector of y axis values of polygon corner points

testx

x axis value of point of interest

testy

y axis value of point of interest

Details

For discussion see: http://stackoverflow.com/questions/217578/how-can-i-determine-whether-a-2d-point-is-within-a-polygon/2922778#2922778

Value

boolean value - TRUE, if the point is within the polygon. Otherwise FALSE.

See Also

Other pnpfuncs: pnpmulti

Examples

df <- data.frame(
  x = c(1,1,2,2),
  y = c(1,2,1,2)
)

pnp(df$x, df$y, 1.5, 1.5)
pnp(df$x, df$y, 2.5, 2.5)

# caution: false-negatives in edge-cases:
pnp(df$x, df$y, 2, 1.5)


[Package recexcavAAR version 0.3.0 Index]