Building a sphere surface using Delaunay 3D triangular panels in R

[ EDIT : More general solutions can be seen in the answers to this question ]

I am wondering if anyone can help me build an approximation of the surface of a sphere using XYZ coordinates. I tried to calculate Delaunay triangulated panels using a package geometry, and then draw iwith rgl. The first attempt, which looks beautiful, unfortunately, created Delaunay triangular triangles that intersect the sphere. Ultimately, I would only like to build a surface:

Generate 3D xyz sphere data

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)

Calculate 3d Delaunay triangles and graph with 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

Trying to only return surface triangles through a 2d Delaunay triangulation

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

, - . .

+4

Source: https://habr.com/ru/post/1533140/


All Articles