Closed omaralvarez closed 1 month ago
I have also tested cut_with_box
and it does not work either. Could it be due to the mesh not interseting in all sides with the bounding box (mesh just intersects with one side)?
It could be! but I cannot tell, you are not giving me enough information.. :) Syntax looks ok though.
Sorry, you are right, I have made a drawing to make it clearer:
I have the mesh of a plane, and I want to get the area of the part that is inside the box in the drawing (A). plane_mesh
is the plane, and mesh
is the mesh of the box. I have tested both meshes inside vedo, and the render looks ok. I have also tested cut_with_box
with mesh
coverted to a vedo Box
.
The cut always is empty, not sure why.
I hope that now it is clearer, sorry for the drawing skills.
No worries! This seems to work though
from vedo import Cube, Plane, show, settings
settings.use_parallel_projection = True
cube = Cube().rotate_z(10).alpha(0.5)
plane = Plane().scale(0.5).rotate_x(5).shift(dx=0.6)
# cube.subdivide(3, method=1)
# plane.subdivide(3, method=1)
cut_plane = plane.clone().cut_with_mesh(cube).shift(dz=0.01)
cut_plane.c("red5")
show(cube, plane, cut_plane, axes=1)
Note that this doesn´t work if some edges are exactly coincident as then the inside/outside becomes ambiguous.
That may be the problem, the front and back edges are common. The rest should not match. Here is the full code of one of the failing cases:
from vedo import Cube, Mesh, show
box = Box(pos=[0.00073, 0.00279, 0.03353, 0.03529, 0.0, 0.07])
face_mesh = Mesh(
[[0.00041, 0.035, 0.0],[0.00104, 0.03498, 0.0], [0.00104, 0.03498, 0.07]],
[[2, 1, 0]]
)
cut = face_mesh.clone().cut_with_box(box)
cut.c("red5")
show(box, face_mesh, cut)
It's weird because when it is fully inside it works:
that might be a problem of precision (?)
from vedo import *
box = Box(pos=[0.00073, 0.00279, 0.03353, 0.03529, 0.0, 0.07])
face_mesh = Mesh(
[[
[0.00041, 0.035, 0.0],
[0.00104, 0.03498, 0.0],
[0.00104, 0.03498, 0.07]
],
[[2, 1, 0]]]
)
face_mesh.subdivide(3, method=1)
box.subdivide(3, method=1)
box.alpha(0.5).lighting('off')
cut = face_mesh.clone().cut_with_box(box)
cut.c("red5")
show(box, cut)
You are right. Let me investigate further with your suggested code. Thanks for the help I'll let you know what I find out!
It looks like indeed it was a matter of precision. Subdividing the meshes results look correct. Thank you very much for the help.
I am using
cut_with_mesh
to obtain the part of a plane mesh that is inside another mesh. What I am using now:It looks like this:
Right now it is crashing silently and I do not know why. I am using the right function to do this?