使用R中的3d Delaunay三角形面板绘制球体表面

时间:2014-03-24 10:56:29

标签: r 3d plot delaunay

[编辑:在this question的答案中可以看到更一般的解决方案

我想知道是否有人可以帮助我使用XYZ坐标绘制球体表面的近似值。我尝试使用包geometry计算Delaunay三角形面板,然后用rgl绘制i。不幸的是,第一次看起来不错的尝试创造了穿过球体的Delaunay 3d三角形。我最终只想绘制表面:

生成球体的3d xyz数据

n <- 10 
rho <- 1
theta <- seq(0, 2*pi,, n) # azimuthal coordinate running from 0 to 2*pi 
phi <- seq(0, pi,, n) # polar coordinate running from 0 to pi (colatitude)
grd <- expand.grid(theta=theta, phi=phi)

x <- rho * cos(grd$theta) * sin(grd$phi)
y <- rho * sin(grd$theta) * sin(grd$phi)
z <- rho * cos(grd$phi)
xyzw <- cbind(x,y,z,w=1)

计算3d Delaunay三角形并用rgl:

绘图
#install.packages("geometry")
library(geometry)
library(rgl)

tc <- delaunayn(xyzw[,1:3])
open3d()
tetramesh(tc,cbind(x,y,z), alpha=0.2, col=5)
rgl.snapshot("3d_delaunay.png")

enter image description here

仅通过2d Delaunay三角测量

尝试返回表面三角形
tc <- delaunayn(xyzw[,c(1:2)])
open3d()
for(i in seq(nrow(tc))){
    vertices <- c(t(xyzw[tc[i,],]))
    indices <- c( 1, 2, 3)
    shade3d( tmesh3d(vertices,indices) , alpha=0.2, col="cyan")
}
rgl.snapshot("2d_delaunay.png")

enter image description here

显然,有些东西不起作用。任何帮助将不胜感激。

0 个答案:

没有答案
相关问题