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

Finding bounding box with slt.Dimension.X or Y or Z #118

Closed snowbugxs closed 4 years ago

snowbugxs commented 4 years ago

Hi. In the tutorial of combining multiple stl files, the first step is to find the bounding box, i.e., the max and min coordinates in x, y and z directions. It uses the stl.Dimension.X to refer an x coordinate of the first point, as shown in the source code, stl.Dimension.X = 0 (Y=1, Z=2) and the last two points are neglected. However, i want to ask do all the points have a chance to be the first point of a facet? Because in that way only the first point's coordinates are iterated.

wolph commented 4 years ago

Honestly, looking at that sample it doesn't make much sense to me. In most cases the find_mins_maxs(...) function will still work because the dimensions of 1/3 of the points often still covers the same cases, but it can definitely go wrong at times. Additionally, it's overly complex, I would suggest this instead:

minx = obj.x.min()
maxx = obj.x.max()
miny = obj.y.min()
maxy = obj.y.max()
minz = obj.z.min()
maxz = obj.z.max()

As for being the first point of a facet. You would need to define what is "first" in this case :) It's pretty arbitrary really, you could call any of the 3 points first or last. The order of the points doesn't really make much of a difference

snowbugxs commented 4 years ago

Thanks.