閉領域内外の判定

ある座標がポリゴン領域の内側と外側のどちらにあるかを判定

# ポリゴン(閉領域)内外の判定
library(sp)
# ポリゴンの座標
pol.x <- c(0, 1, 1, 0, 0)
pol.y <- c(0, 0, 1, 1, 0)
# 内外判定する座標
x <- c(0.5, 1.5, 1, 1)
y <- c(0.5, 0.5, 0.5, 1)
# 内外の判定 0 : 領域外の点 1 : 領域内の点 2 : 境界上の点(辺) 3 :
# 境界上の点(頂点)
res <- point.in.polygon(x, y, pol.x, pol.y)

図による説明:

plot(pol.x, pol.y, type = "l", xlim = c(0, 1.5), ylim = c(0, 1.5), 
    asp = 1)
points(x, y, pch = 20, col = "red")
text(x, y, labels = res, pos = 4)

plot of chunk polygon-fig