[英]Plotting surface of a sphere using 3d Delaunay triangulated panels in R
[编辑:在这个问题的答案中可以看到更通用的解决方案]
我想知道是否有人可以帮助我使用 XYZ 坐标绘制球体表面的近似值。 我曾尝试使用包geometry
计算 Delaunay 三角面板,然后使用 rgl rgl
。 第一次尝试看起来不错,但不幸的是创建了穿过球体的 Delaunay 3d 三角形。 我最终只想绘制表面:
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)
#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")
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")
显然,有些东西不起作用。 任何帮助将不胜感激。
您需要的是凸包,而不是 Delaunay 三角剖分。 这是cxhull包的一种方法,但您也可以使用geometry包。
library(tessellation)
n <- 10
rho <- 1
theta <- seq(0, 2*pi, length.out = n) # azimuthal coordinate running from 0 to 2*pi
phi <- seq(0, pi, length.out = 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)
xyz <- cbind(x,y,z)
library(cxhull)
hull <- cxhull(xyz, triangulate = TRUE)
library(rgl)
open3d()
for(facet in hull$facets){
triangles3d(xyz[facet[["vertices"]], ], color = "green")
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.