question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

x-cross-section produces weird result

See original GitHub issue

I also posted this question here: https://stackoverflow.com/posts/69336886/edit

I have a simple box (w:400, l=400, height=50):

image

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:

image

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()

image

…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:open
  • Created 2 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
dorianherlecommented, Sep 28, 2021

@mikedh After long trial and error I found this method to fix it:

def cross_section(mesh, plane_origin=[0,0,0], plane_normal=[1,0,0]):
  
    slice_ = mesh.section(plane_origin=plane_origin, 
                          plane_normal=plane_normal)

    # transformation matrix for to_planar 
    # I don't know why
    to_2D = trimesh.geometry.align_vectors(plane_normal, [0,0,-1])
    
    slice_2D, to_3D = slice_.to_planar(to_2D = to_2D)
    
    return slice_2D, to_3D


slice_2D, to_3D = cross_section(mesh)
slice_2D.show()

image

Do you understand why this works? Btw: Thank you so much for creating this awesome python package!

0reactions
ne1114commented, Mar 30, 2022

@mikedh After long trial and error I found this method to fix it:

def cross_section(mesh, plane_origin=[0,0,0], plane_normal=[1,0,0]):
  
    slice_ = mesh.section(plane_origin=plane_origin, 
                          plane_normal=plane_normal)

    # transformation matrix for to_planar 
    # I don't know why
    to_2D = trimesh.geometry.align_vectors(plane_normal, [0,0,-1])
    
    slice_2D, to_3D = slice_.to_planar(to_2D = to_2D)
    
    return slice_2D, to_3D


slice_2D, to_3D = cross_section(mesh)
slice_2D.show()

image

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 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python trimesh x-cross section produces weird result
After long trial and error I found this method to fix it: def cross_section(mesh, plane_origin=[0,0,0], plane_normal=[1,0,0]): slice_ ...
Read more >
Unusual Cross Section Shape - Hydrologic Engineering Center
Sometimes active cross sections can produce strange shapes, like the example shown in the figure below (top). First, make sure the toe station...
Read more >
Strange lines on crosssection plot - Civil 3D - Autodesk Forums
Solved: Am getting these lines on my crossection when I plot my crosssection sheets. they don appear when I preview. they only appear...
Read more >
CROSS SECTION AND LUMINOSITY
metrics of particle collisions that determine the likelihood of seeing interactions resulting in new particles. CROSS SECTION AND LUMINOSITY. LUMINOSITY.
Read more >
What Shape is the Cross Section? (Parallel and Perpendicular ...
We investigate how to predict what shape the cross section will be when it is parallel or perpendicular to the base of a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found