x-cross-section produces weird result
See original GitHub issueI also posted this question here: https://stackoverflow.com/posts/69336886/edit
I have a simple box (w:400, l=400, height=50):
Here the code to create that box:
# Vertices
vert = np.array([[-200., -200., 0.],
[-200., -200., 50.],
[-200., 200., 0.],
[-200., 200., 50.],
[ 200., -200., 0.],
[ 200., -200., 50.],
[ 200., 200., 0.],
[ 200., 200., 50.]])
# Faces
fa = np.array([[6, 0, 4],
[0, 6, 2],
[4, 6, 5],
[6, 7, 5],
[6, 2, 7],
[2, 3, 7],
[2, 0, 3],
[0, 1, 3],
[0, 4, 1],
[4, 5, 1],
[7, 1, 5],
[1, 7, 3]])
# MESH
mesh = trimesh.Trimesh(vertices= vert,
faces=fa)
The issue
As you can see, the top surface of the box is at z=0
, and the lower surface is at z=50
.
Now, I would expect to see this clearly, when I do a cross-section, using x as a normal:
# X - Normal => AXIS WRONG
slice_ = mesh.section(plane_origin=(0,0,0),
plane_normal=[1,0,0])
slice_2D, to_3D = slice_.to_planar()
slice_2D.show()
… but what I get is this:
You can clearly see that the box cross-section is not positioned correctly, as it should begin at z=0, and extend to z=50.
Interestingly, getting cross-sections with z-normal works perfectly:
# Z - Normal => OK
slice_ = mesh.section(plane_origin=(0,0,0),
plane_normal=[0,0,1])
slice_2D, to_3D = slice_.to_planar()
slice_2D.show()
…if I ask for a cross-section at z=-10, where there should be no box, it rightfully complains.
# Z - Normal => OK
slice_ = mesh.section(plane_origin=(0,0,-10),
plane_normal=[0,0,1])
slice_2D, to_3D = slice_.to_planar()
slice_2D.show()
AttributeError: ‘NoneType’ object has no attribute ‘to_planar’
I would really appreciate any help to get the correct cross-section for the x-normal!
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (1 by maintainers)
Top GitHub Comments
@mikedh After long trial and error I found this method to fix it:
Do you understand why this works? Btw: Thank you so much for creating this awesome python package!
Thank you so much! I had a similar issue when slicing with plane that is normal to x-axis. Your last comment saved me 👍