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
624 stars 105 forks source link

Cutting/Splitting .stl file #85

Closed DavideBassano closed 5 years ago

DavideBassano commented 6 years ago

Hello, I have an .stl file with z-coordinates from 0 to ~200 (x and y don't matter) and I would like to cut it in z-direction in order to get a smaller one (e.g. with z-coordinates from 0 to 50). (Please see Image 1 - red line has nothing to do with it, it is used for another purpose)

Now I'm using NetFabb software (https://www.netfabb.com/blog/netfabb-basic-now-just-netfabb) and it works very well (Please see Image 2). Since I'm coding with Python and I'm using that "original" .stl file in my Python code, would be useful to have a code to cut this .stl and to generate a new .stl file from the original one, without using any external software.

Is there a way to do it with numpy-stl?

Thanks, Cheers,

Davide Bassano

Image 1: 99perc

Image 2: 99perc5cm

Uvar commented 6 years ago

So if I understand correctly, you want to make a cross-sectional cut at an arbitrary point?

I guess it can be done by:

  1. Tracking which mesh faces intersect at the appropriate height
  2. Interpolating points at this height to reduce said polygons to the appropriate dimensions
  3. Enforcing new mesh points with arbitrary precision range of closeness to join (if Euclidean distance < cutoff, assume interpolation numerical artefact, they are supposed to be the same vertex)
  4. Fill up the hole at z=cross-section height. This can for example be done by tracing the edges at this height, recursively adding a new polygon at the three subsequent vertices of the edge trace with the smallest angle between them. If you do not really care about the mesh quality in terms of aspect ratio, you can forgo this smallest angle requirement, just filling up as you encounter them. Do take care to compare the normal of your prospective polygon to the unit vector [0,0,1], as with such a cut, it should definitely resemble this unit vector to numerical precision.
DavideBassano commented 6 years ago

Hi Uvar,

thank you very much for your reply. I'll try what you are suggesting.

Thanks, Cheers,

Davide

stale[bot] commented 6 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.