trimesh.convex module

convex.py

Deal with creating and checking convex objects in 2, 3 and N dimensions.

Convex is defined as: 1) “Convex, meaning “curving out” or “extending outward” (compare to concave) 2) having an outline or surface curved like the exterior of a circle or sphere. 3) (of a polygon) having only interior angles measuring less than 180

class trimesh.convex.QhullOptions(Qa: bool = False, Qc: bool = False, Qi: bool = False, QJ: bool = False, Qt: bool = False, Qu: bool = False, Qw: bool = False, Qbb: bool = False, Qs: bool = False, Qv: bool = False, Qx: bool = False, Qz: bool = False, QbB: bool = False, QR0: bool = False, Qg: bool = False, Pp: bool = False)

Bases: object

A helper class for constructing correct Qhull option strings. More details available at: http://www.qhull.org/html/qh-quick.htm#options

Currently only includes the boolean flag options, which is most of them.

Parameters:
  • Qa (bool) – Allow input with fewer or more points than coordinates

  • Qc (bool) – Keep coplanar points with nearest facet

  • Qi (bool) – Keep interior points with nearest facet.

  • QJ (bool) – Joggled input to avoid precision problems

  • Qt (bool) – Triangulated output.

  • Qu (bool) – Compute upper hull for furthest-site Delaunay triangulation

  • Qw (bool) – Allow warnings about Qhull options

  • Qbb (bool) – Scale last coordinate to [0,m] for Delaunay

  • Qs (bool) – Search all points for the initial simplex

  • Qv (bool) – Test vertex neighbors for convexity

  • Qx (bool) – Exact pre-merges (allows coplanar facets)

  • Qz (bool) – Add a point-at-infinity for Delaunay triangulations

  • QbB (bool) – Scale input to fit the unit cube

  • QR0 (bool) – Random rotation (n=seed, n=0 time, n=-1 time/no rotate)

  • Qg (bool) – only build good facets (needs ‘QGn’, ‘QVn’, or ‘Pdk’)

  • Pp (bool) – Do not print statistics about precision problems and remove some of the warnings including the narrow hull warning.

Pp: bool = False

Do not print statistics about precision problems and remove some of the warnings including the narrow hull warning.

QJ: bool = False

Joggled input to avoid precision problems

QR0: bool = False

Random rotation (n=seed, n=0 time, n=-1 time/no rotate)

Qa: bool = False

Allow input with fewer or more points than coordinates

QbB: bool = False

Scale input to fit the unit cube

Qbb: bool = False

Scale last coordinate to [0,m] for Delaunay

Qc: bool = False

Keep coplanar points with nearest facet

Qg: bool = False

Only build good facets (needs ‘QGn’, ‘QVn’, or ‘Pdk’)

Qi: bool = False

Keep interior points with nearest facet.

Qs: bool = False

Search all points for the initial simplex

Qt: bool = False

Triangulated output.

Qu: bool = False

Compute upper hull for furthest-site Delaunay triangulation

Qv: bool = False

Test vertex neighbors for convexity

Qw: bool = False

Allow warnings about Qhull options

Qx: bool = False

Exact pre-merges (allows coplanar facets)

Qz: bool = False

Add a point-at-infinity for Delaunay triangulations

__init__(Qa: bool = False, Qc: bool = False, Qi: bool = False, QJ: bool = False, Qt: bool = False, Qu: bool = False, Qw: bool = False, Qbb: bool = False, Qs: bool = False, Qv: bool = False, Qx: bool = False, Qz: bool = False, QbB: bool = False, QR0: bool = False, Qg: bool = False, Pp: bool = False) None
trimesh.convex.adjacency_projections(mesh)

Test if a mesh is convex by projecting the vertices of a triangle onto the normal of its adjacent face.

Parameters:

mesh (Trimesh) – Input geometry

Returns:

projection – Distance of projection of adjacent vertex onto plane

Return type:

(len(mesh.face_adjacency),) float

trimesh.convex.convex_hull(obj: Geometry3D | ndarray[tuple[int, ...], dtype[_ScalarType_co]], qhull_options: QhullOptions | str | None = QhullOptions(Qa=False, Qc=False, Qi=False, QJ=False, Qt=True, Qu=False, Qw=False, Qbb=False, Qs=False, Qv=False, Qx=False, Qz=False, QbB=True, QR0=False, Qg=False, Pp=True), repair: bool = True) trimesh.Trimesh

Get a new Trimesh object representing the convex hull of the current mesh attempting to return a watertight mesh with correct normals.

Parameters:
  • obj – Mesh or (n, 3) points.

  • qhull_options – Options to pass to qhull.

Returns:

Mesh of convex hull.

Return type:

convex

trimesh.convex.hull_points(obj, qhull_options='QbB Pp')

Try to extract a convex set of points from multiple input formats.

Details on qhull options:

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

Parameters:

obj (Trimesh object) – (n,d) points (m,) Trimesh objects

Returns:

points

Return type:

(o,d) convex set of points

trimesh.convex.is_convex(mesh)

Check if a mesh is convex.

Parameters:

mesh (Trimesh) – Input geometry

Returns:

convex – Was passed mesh convex or not

Return type:

bool