/
bbox_numpy.py
57 lines (44 loc) · 1.49 KB
/
bbox_numpy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from compas.geometry import oriented_bounding_box_numpy
from compas.geometry import oriented_bounding_box_xy_numpy
def mesh_oriented_bounding_box_numpy(mesh):
"""Compute the (axis aligned) bounding box of a mesh.
Parameters
----------
mesh : :class:`compas.datastructures.Mesh`
The mesh data structure.
Returns
-------
list[list[float]]
The bounding box of the mesh as a list of corner vertex coordinates.
Examples
--------
>>> from compas.datastructures import Mesh
>>> hypar = Mesh.from_obj(compas.get('hypar.obj'))
>>> box = mesh_oriented_bounding_box_numpy(hypar)
>>> len(box)
8
"""
xyz = mesh.vertices_attributes("xyz")
return oriented_bounding_box_numpy(xyz)
def mesh_oriented_bounding_box_xy_numpy(mesh):
"""Compute the (axis aligned) bounding box of a projection of the mesh in the XY plane.
Parameters
----------
mesh : :class:`compas.datastructures.Mesh`
The mesh data structure.
Returns
-------
list[list[float]]
The bounding box.
Examples
--------
>>> from compas.datastructures import Mesh
>>> mesh = Mesh.from_obj(compas.get('faces.obj'))
>>> mesh_oriented_bounding_box_xy_numpy(mesh)
[[10.0, 0.0], [0.0, 0.0], [0.0, 10.0], [10.0, 10.0]]
"""
xyz = mesh.vertices_attributes("xyz")
return oriented_bounding_box_xy_numpy(xyz)