wolph / numpy-stl

Simple library to make working with STL files (and 3D objects in general) fast and easy.
http://numpy-stl.readthedocs.org/
BSD 3-Clause "New" or "Revised" License
605 stars 103 forks source link

How can I split a stl model with a plane? #137

Closed a740615405 closed 3 years ago

a740615405 commented 4 years ago

I want to make a plane when you input a Z height number, that is parallel to XY plane. Then I want to split the stl file with this plane and measure the remaining volume below the plane.

How can I do this ?

wolph commented 3 years ago

I imagine you would have to walk through all vertices and see if they cross your plane and create new vertices if needed.

In any case not that easy to do and definitely not within this library because numpy arrays normally have a fixed size so splitting is not a trivial operation.

Areteos commented 3 years ago

Are you trying to do calculations on the displacement of objects in water? My approach to the same problem has been to get the centroid of each triangle, check which centroids are below the surface, then take work out volumes based on those triangles whose centroids are below the surface. It's a bit rough because it means you have a sort of jagged edge along the plane, but it does avoid the difficult problem of having to reconnect the mesh; as you would have to if you were checking based on vertices.

a740615405 commented 3 years ago

I imagine you would have to walk through all vertices and see if they cross your plane and create new vertices if needed.

In any case not that easy to do and definitely not within this library because numpy arrays normally have a fixed size so splitting is not a trivial operation.

hello @WoLpH : Thank you very much for replying, I have solved the problem with another library named trimesh, that is easier using this lib.

a740615405 commented 3 years ago

Are you trying to do calculations on the displacement of objects in water? My approach to the same problem has been to get the centroid of each triangle, check which centroids are below the surface, then take work out volumes based on those triangles whose centroids are below the surface. It's a bit rough because it means you have a sort of jagged edge along the plane, but it does avoid the difficult problem of having to reconnect the mesh; as you would have to if you were checking based on vertices.

hello @Skullsploder : Thank you very much for replying, I have solved the problem with another library named trimesh, that is easier using this lib.

wolph commented 3 years ago

Excellent :)

Manipulating meshes never has been a goal for this library, just storing and loading.

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.