is_in: Point in a Polygon

View source: R/is_in.R

is_inR Documentation

Point in a Polygon

Description

Determine is a point (x, y) is inside, on an edge, or outside of a polygon.

Usage

is_in(x, y, pg)

Arguments

x

x coordinate of the point.

y

y coordinate of the point.

pg

a sccm_pg or sccm_ch object

Value

an integer with value of 0, or 1.

0

(x, y) is on edge or outside of the polygon

1

(x, y) is inside of the polygon

See Also

polygon link{convex_hull}

Examples


xvert <- c(0, 5, 6, 4, 2, 0)
yvert <- c(0, 0, 1, 3, 3, 2)

pg <- polygon(xvert, yvert)
plot(pg)

points_to_test <-
  rbind(c(x = 0,   y = 1.1),
        c(x = 0.7, y = 2.1),
        c(x = 0.5, y = 2.8),
        c(x = 3.2, y = 1.2),
        c(x = 0.2, y = 0.01),
        c(x = 1,   y = 2.5),
        c(x = 5.5, y = 0.3),
        c(x = 4.5, y = 2.5),
        c(x = pi,  y = pi/3))

is_in(0, 1.1, pg)
is_in(3.2, 1.1, pg)

test_results <-
  is_in(points_to_test[, 1],
        points_to_test[, 2],
        pg)

test_results

summary(test_results)

points(points_to_test,
       col = factor(summary(test_results)$label),
       pch = 16)
text(points_to_test, pos = 4)


dewittpe/sccm documentation built on Feb. 2, 2024, 5:25 p.m.