Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在R中将椭球体转换为mesh3d?_R_Ellipse_Rgl_Drawellipse - Fatal编程技术网

如何在R中将椭球体转换为mesh3d?

如何在R中将椭球体转换为mesh3d?,r,ellipse,rgl,drawellipse,R,Ellipse,Rgl,Drawellipse,我使用包中的椭球壳方法从一组点获得最小体积封闭椭球(mvee)。此方法返回类椭球体的对象。我需要绘制生成的椭球体。我尝试使用软件包中的wire3d方法绘制椭球体,但该方法将mesh3d类的对象作为输入参数。如何将椭球体对象转换为mesh3d对象?如果您实际上并不关心网格,只是想绘制一个透明的椭球体,则可以使用以下方法: library(rgl) library(cluster) open3d() ellipsoid3d <- function(cen, a = 1,b = 1,c = 1

我使用包中的椭球壳方法从一组点获得最小体积封闭椭球(mvee)。此方法返回类椭球体的对象。我需要绘制生成的椭球体。我尝试使用软件包中的wire3d方法绘制椭球体,但该方法将mesh3d类的对象作为输入参数。如何将椭球体对象转换为mesh3d对象?

如果您实际上并不关心网格,只是想绘制一个透明的椭球体,则可以使用以下方法:

library(rgl)
library(cluster)
open3d()

ellipsoid3d <- function(cen, a = 1,b = 1,c = 1,n = 65, ...){
  f <- function(s,t){ 
    cbind(   a * cos(t)*cos(s) + cen[1],
             b *        sin(s) + cen[2],
             c * sin(t)*cos(s) + cen[3])
  }
  persp3d(f, slim = c(-pi/2,pi/2), tlim = c(0, 2*pi), n = n, add = T, ...)
}

set.seed(123)
n <- 6
for (i in 1:n){
   cen <- 3*runif(3)
   a <- runif(1)
   b <- runif(1)
   c <- runif(1)

   clr <- c("red","blue","green")[i %% 3 + 1 ]
   elpf <- ellipsoid3d(cen,a=a,b=b,c=c,col=clr,alpha=0.5)
}
库(rgl)
图书馆(群集)
open3d()
椭球体3D
库(群集)

xyz对我的回答有什么反馈吗?谢谢。当然,我有矩阵形式的椭球方程:t(x-c)*A*(x-c)=1。所以我没有椭球半径。如何获得半径?这是一个工作,实际上是一个单独的问题-rgl问题太少了-我们需要更多的活动。请接受这个(请也投票)。然后把你的要求作为一个单独的问题发布,如果其他人没有先回答,我会在周末解决。我投票支持你的答案,因为它可能有助于某人绘制椭球体。我需要获得mesh3d对象。
library(cluster)
xyz <- cbind(rnorm(10), rnorm(10), rnorm(10))
e <- ellipsoidhull(xyz)
A <- e$cov
center <- e$loc
r <- sqrt(e$d2)

library(Rvcg)
sphr <- vcgSphere()
library(rgl)
ell <- translate3d(
  scale3d(
    transform3d(sphr, chol(A)), 
    r, r, r),
  center[1], center[2], center[3])

shade3d(ell, color="red", alpha=0.3)
points3d(xyz)