在R中查找3D顶点对象的尺寸

问题描述 投票:0回答:1

是否有一种方法可以在R中找到由一组顶点定义的3D对象(面)的尺寸(该对象是顶点的凸包)。也就是说,定义函数getDim()

vertices<-matrix(c(1,1,1,1,1,1), ncol = 3, byrow = TRUE)
getDim(vertices)  # should return 0
vertices<-matrix(c(0,0,0,1,1,1,2,2,2,3,3,3), ncol = 3, byrow = TRUE)
getDim(vertices)  # should return 1
vertices<-matrix(c(0,0,0,0,1,1,0,2,2,0,0,2), ncol = 3, byrow = TRUE)
getDim(vertices)  # should return 2
vertices<-matrix(c(0,0,0,0,1,1,0,2,2,0,0,2,1,1,1), ncol = 3, byrow = TRUE)
getDim(vertices)  # should return 3
r 3d
1个回答
0
投票

感谢斯蒂芬·洛朗的提示

getDim3D<-function(points) {
  x <- unique(points)
  if (dim(x)[1]==1) return(0)
  x <- x[2:dim(x)[1],,drop=F] - matrix(rep(x[1,], times = dim(x)[1]-1), ncol = dim(x)[2], byrow = TRUE)
  return(Matrix::rankMatrix(x)[1])
}
© www.soinside.com 2019 - 2024. All rights reserved.