library(MeshesOperations)
library(rgl)
# a tetrahedron with ill-oriented faces ####
vertices1 <- rbind(
c(-1, -1, -1),
c( 1, 1, -1),
c( 1, -1, 1),
c(-1, 1, 1)
)
faces1 <- rbind(
c(1, 2, 3),
c(3, 4, 2),
c(4, 2, 1),
c(4, 3, 1)
)
# same tetrahedron translated ####
vertices2 <- vertices1 + 3
# merge the two tetrahedra ####
vertices <- rbind(vertices1, vertices2)
faces <- rbind(faces1, faces1 + 4)
# now run the `connectedComponents` function ####
meshes <- connectedComponents(vertices, faces, normals = FALSE)
mesh1 <- meshes[[1]]; mesh2 <- meshes[[2]]
# plot
tmesh1 <- toRGL(mesh1)
tmesh2 <- toRGL(mesh2)
open3d(windowRect = c(50, 50, 562, 562))
shade3d(tmesh1, color = "green", back = "culled")
shade3d(tmesh2, color = "red", back = "culled")
Run the code above in your browser using DataLab