Reputation: 540
I've tried to create a 3D mesh looking like a cylinder and then cut it in half as following:
library(rgl)
library(Morpho)
xpos = c(-500,500)
ypos = c(0,0)
zpos = c(-200,-200)
rad = 50
cylinder = cylinder3d(center = cbind(xpos,ypos,zpos), radius = rad, sides = 100)
plot3d(cylinder, axes = FALSE, xlab = "", ylab = "", zlab ="")
upperHalf = cutMeshPlane(cylinder,v1 = c(0,0,-200), normal = c(0,0,1),keep.upper = TRUE)
plot3d(t(upperHalf$vb), axes = FALSE, xlab = "", ylab = "", zlab ="")
plot3d(upperHalf) #this produces an error: index out of bounds
The first plot shows the cylinder with the red line implying the plane along which I'd like to cut the cylinder.
The second plot shows the corner coordinates after using cutMeshPlane
to separate the cylinder along the z-axis. As desired, only the upper half remains.
However, I cannot plot a new 3d mesh representing half the cylinder. I believe that the vertex indices from cylinder$ib
were not updated in upperHalf$ib
and that's why. However, I cannot figure out how to solve this problem or create a new 3d mesh with the remaining coordinates. Help is much appreciated!
Upvotes: 0
Views: 331
Reputation: 11
I just updated cutMeshPlane
to also work with quad meshes. I tested with your example (see below)
you can install it using devtools::install_github("zarquon42b/Morpho")
Upvotes: 1
Reputation: 44788
The Morpho::cutMeshPlane
function requires a mesh made of triangles, but yours is made up of quadrilaterals. The simplest fix is to use rgl::clipMesh3d
instead:
upperHalfrgl <- clipMesh3d(cylinder, "z", -200)
plot3d(upperHalfrgl, axes = FALSE, xlab = "", ylab = "", zlab ="")
You could also convert your mesh to triangles using the internal rgl
function rgl:::as.tmesh3d
, but it's risky to use internal functions.
Upvotes: 1