Fast computation of the connected components of an undirected graph.
<- function(x, y, z, a, cosb, sinb){
f sqrt((sqrt(x*x + (y*sinb + a*cosb)^2) - 2)^2) - 1)^2 +
(sqrt((sqrt(z*z + (y*cosb - a*sinb)^2) - 2)^2) - 1)^2
(
}<- 0.6
a <- 0.785
b <- cos(b)
cosb <- sin(b)
sinb
<- z <- seq(-3.5, 3.5, len = 150L)
x <- seq(-4.2, 4.2, len = 150L)
y <- expand.grid(X = x, Y = y, Z = z)
g <- array(
voxel with(g, f(X, Y, Z, a, cosb, sinb)),
dim = c(150L, 150L, 150L)
)
library(rmarchingcubes)
<- contour3d(
contour_shape griddata = voxel,
level = 0.1,
x = x,
y = y,
z = z
)
library(rgl)
<- tmesh3d(
tmesh vertices = t(contour_shape[["vertices"]]),
indices = t(contour_shape[["triangles"]]),
normals = contour_shape[["normals"]],
homogeneous = FALSE
)open3d(windowRect = c(50, 50, 562, 562), zoom = 0.9)
shade3d(tmesh, color = "orangered")
library(concom)
<- concom3d(tmesh)
meshes
<- hcl.colors(length(meshes))
colors open3d(windowRect = c(50, 50, 562, 562), zoom = 0.9)
for(i in 1L:length(meshes)){
shade3d(meshes[[i]], color = colors[i])
}