[英]How to find the convex hull of a 3D facet in R
Is there a way to find the vertices of a facet in R given a set of points (the facet is the convex hull of the points and is of dimension 2).有没有办法在给定一组点的情况下在 R 中找到小平面的顶点(小平面是点的凸包,维度为 2)。 That is, how to define function convexHull
:即,如何定义函数convexHull
:
vertices<-matrix(c(0,0,0,0,1,1,0,2,2,0,0,2), ncol = 3, byrow = TRUE) # ex1
vertices<-matrix(c(1,0,0,1,1,1,1,2,2,3,1,1), ncol = 3, byrow = TRUE) # ex2 (updated question)
vertices # one vertex in each row.
convexHull(vertices) # should return indices 1,3,4 (vertex 1,3 and 4 since vertex 2 is a convex combination of 1 and 3)
Thanks to user2554330 for hints.感谢 user2554330 的提示。
convexHull <- function(points) {
points <- unique(points)
l <- dim(points)[1]
n <- dim(points)[2]
comb <- t(combn(n,2))
for (i in 1:dim(comb)[1]) { # simple projection down on each axis
p <- unique(points[,comb[i,]])
if (l == dim(p)[1]) {
return(chull(points[,comb[i,]]))
}
}
stop("Cannot find the vertices!")
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.