Skip to content

Instantly share code, notes, and snippets.

@zeffii
Created April 27, 2022 08:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeffii/06af8631258e387057acd79d753b73a6 to your computer and use it in GitHub Desktop.
Save zeffii/06af8631258e387057acd79d753b73a6 to your computer and use it in GitHub Desktop.
bbox_simple
def basic_bbox(verts):
"""
input:
accepts verts as python iterables or as an np.array
verts = [v1, v2, v3, v3, ....]
or
verts = np.array(verts)
output:
if the function received an np.array as input it will also output a tuple of np.arrays
else it will output a tuple of two python-iterables
ultimately: ((min_x, min_y, min_z), (max_x, max_y, max_z))
"""
np_mode = isinstance(verts, np.ndarray)
np_vec = verts if np_mode else np.array(verts)
bbox_max = np.amax(np_vec, axis=0)
bbox_min = np.amin(np_vec, axis=0)
return (bbox_min, bbox_max) if np_mode else (tuple(bbox_min), tuple(bbox_max))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment