trimesh.bounds module

trimesh.bounds.contains(bounds, points)

Do an axis aligned bounding box check on a list of points.

Parameters:
  • bounds ((2, dimension) float) – Axis aligned bounding box

  • points ((n, dimension) float) – Points in space

Returns:

points_inside – True if points are inside the AABB

Return type:

(n,) bool

trimesh.bounds.corners(bounds)

Given a pair of axis aligned bounds, return all 8 corners of the bounding box.

Parameters:

bounds ((2,3) or (2,2) float) – Axis aligned bounds

Returns:

corners – Corner vertices of the cube

Return type:

(8,3) float

trimesh.bounds.minimum_cylinder(obj, sample_count=6, angle_tol=0.001)

Find the approximate minimum volume cylinder which contains a mesh or a a list of points.

Samples a hemisphere then uses scipy.optimize to pick the final orientation of the cylinder.

A nice discussion about better ways to implement this is here: https://www.staff.uni-mainz.de/schoemer/publications/ALGO00.pdf

Parameters:
  • obj (trimesh.Trimesh, or (n, 3) float) – Mesh object or points in space

  • sample_count (int) – How densely should we sample the hemisphere. Angular spacing is 180 degrees / this number

Returns:

result

With keys:

’radius’ : float, radius of cylinder ‘height’ : float, height of cylinder ‘transform’ : (4,4) float, transform from the origin

to centered cylinder

Return type:

dict

trimesh.bounds.oriented_bounds(obj, angle_digits=1, ordered=True, normal=None, coplanar_tol=1e-12)

Find the oriented bounding box for a Trimesh

Parameters:
  • obj (trimesh.Trimesh, (n, 2) float, or (n, 3) float) – Mesh object or points in 2D or 3D space

  • angle_digits (int) – How much angular precision do we want on our result. Even with less precision the returned extents will cover the mesh albeit with larger than minimal volume, and may experience substantial speedups.

  • ordered (bool) – Return a consistent order for bounds

  • normal (None or (3,) float) – Override search for normal on 3D meshes.

  • coplanar_tol (float) – If a convex hull fails and we are checking to see if the points are coplanar this is the maximum deviation from a plane where the points will be considered coplanar.

Returns:

  • to_origin ((4,4) float) – Transformation matrix which will move the center of the bounding box of the input mesh to the origin.

  • extents ((3,) float) – The extents of the mesh once transformed with to_origin

trimesh.bounds.oriented_bounds_2D(points, qhull_options='QbB')

Find an oriented bounding box for an array of 2D points.

Details on qhull options:

http://www.qhull.org/html/qh-quick.htm#options

Parameters:

points ((n,2) float) – Points in 2D.

Returns:

  • transform ((3,3) float) – Homogeneous 2D transformation matrix to move the input points so that the axis aligned bounding box is CENTERED AT THE ORIGIN.

  • rectangle ((2,) float) – Size of extents once input points are transformed by transform

trimesh.bounds.to_extents(bounds)

Convert an axis aligned bounding box to extents and transform.

Parameters:

bounds ((2, 3) float) – Axis aligned bounds in space

Returns:

  • extents ((3,) float) – Extents of the bounding box

  • transform ((4, 4) float) – Homogeneous transform moving extents to bounds