我在“足迹”形状非常不规则的区域中有一系列点:
我想确定足迹顶点内的所有坐标。最终目标是确定哪些数据点位于此足迹之外。
有没有人有一种有效的方法来做到这一点?
我最好的解决办法是根据绿色区域的顶点绘制一个多边形,然后使用所述多边形的坐标来确定“异常值”点(尽管我不确定如何做到这一点 - 一次一个步骤!)。
但是,当我尝试创建 convex hull 时,由于我的绿色空间的不规则形状,它显然会产生问题。 [有谁知道创建方法凹面 船体?]
或者,有没有办法使用“单击图形”类型的方法手动绘制多边形?
...同样,如果您对我的问题有比使用多边形更好的解决方案,请务必提出该解决方案!
最佳答案
Alternatively, is there a way to draw polygons manually using a 'click the graph' type method?
这是一个想法。首先,一些随机点:
library(manipulate)
library(sp)
set.seed(1)
par(pch = 19, cex=.5)
x <- runif(1000)
y <- runif(1000)
现在,绘制并捕获多边形:
coords <- data.frame()
manipulate({
plot(y~x)
res <- manipulatorMouseClick()
coords <<- rbind(coords, data.frame(x=res$userX, y=res$userY))
if (length(coords)) lines(coords)
})
并确定哪些点在其内部/外部(参见
?point.in.polygon
):res <- point.in.polygon(x, y, coords$x, coords$y)!=0
plot(y~x, col = res + 1L)
lines(coords)
关于r - 确定哪些点位于 R 中不规则形状的数据足迹之外?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39580566/