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

Description Usage Arguments Details Value See Also Examples

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

1
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
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)

recexcavAAR documentation built on May 1, 2019, 6:48 p.m.