Example #1
0
def test_oriented_bounding_box_numpy(coords, expected):
    if compas.IPY:
        return

    from compas.geometry import oriented_bounding_box_numpy

    results = oriented_bounding_box_numpy(coords).tolist()
    for result, expected_values in zip(results, expected):
        assert allclose(result, expected_values, tol=1e-3)
Example #2
0
def mesh_oriented_bounding_box_numpy(mesh):
    """Compute the (axis aligned) bounding box of a mesh.

    Parameters
    ----------
    mesh : compas.datastructures.Mesh
        The mesh data structure.

    Returns
    -------
    list
        The bounding box of the mesh as a list of corner vertex coordinates.

    Examples
    --------
    >>> box = mesh_oriented_bounding_box_numpy(hypar)
    >>> len(box)
    8

    """
    xyz = mesh.get_vertices_attributes('xyz')
    return oriented_bounding_box_numpy(xyz)
Example #3
0
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)
from math import radians

from compas.geometry import Pointcloud, Box
from compas.geometry import Rotation
from compas.geometry import oriented_bounding_box_numpy

from compas_view2.app import App

cloud = Pointcloud.from_bounds(10, 5, 3, 100)

Rz = Rotation.from_axis_and_angle([0.0, 0.0, 1.0], radians(60))
Ry = Rotation.from_axis_and_angle([0.0, 1.0, 0.0], radians(20))
Rx = Rotation.from_axis_and_angle([1.0, 0.0, 0.0], radians(10))

cloud.transform(Rz * Ry * Rx)

bbox = oriented_bounding_box_numpy(cloud)
box = Box.from_bounding_box(bbox)

viewer = App()
viewer.add(cloud)
viewer.add(box, show_faces=False, linecolor=(1, 0, 0), linewidth=3)
viewer.run()
Example #5
0
def test_oriented_bounding_box_numpy(coords, expected):
    print(oriented_bounding_box_numpy(coords).tolist())
    assert expected == oriented_bounding_box_numpy(coords).tolist()