Skip to content

Mesh

Triangulated surface or solid with per-vertex and per-face attributes.

bounds property

bounds

(min, max) corners of the bounding box, None when empty.

column_names property

column_names

Names of the vertex columns, then the face columns.

coords property

coords

(n, 3) vertices.

is_closed property

is_closed

Every edge shared by exactly two non-degenerate triangles.

length_unit property

length_unit

Unit of the coordinates, such as m or ft; None when not declared.

volume property

volume

Enclosed volume of a closed mesh, positive when wound outward.

Raises:

Type Description
InvalidInput

If the mesh is not closed or not consistently wound; repair() fixes the winding.

x property

x

x of each row's coordinates.

y property

y

y of each row's coordinates.

z property

z

z of each row's coordinates.

contains method descriptor

contains(points)

Whether each point is inside, by generalized winding number.

cut method descriptor

cut(origin, normal)

The part of the mesh behind a plane.

Parameters:

Name Type Description Default
origin sequence of float

A point on the plane, (x, y, z).

required
normal sequence of float

Points away from the part kept, so it is the outward normal of the cut face; any non-zero length.

required

Returns:

Type Description
Mesh

The part where (p - origin) · normal < 0; a vertex on the plane counts as cut away, as in section. A closed mesh gets a cap over the cut, holes left open where the plane passes through cavities, so it stays closed; an open surface is just trimmed. Kept faces and vertices keep their columns; cap faces and the vertices made on the plane get nulls.

Raises:

Type Description
InvalidInput

With a zero or non-finite normal, or when the capped mesh would not close, as when the mesh crosses itself.

distance method descriptor

distance(points, *, signed=False)

Distance to the surface; signed makes inside points negative.

fill_holes method descriptor

fill_holes()

Closes each hole with a fan of triangles from its first vertex.

Returns:

Type Description
Mesh

A new mesh with the fans appended, wound like the faces around each hole, with null face attributes. A hole is a loop of boundary edges; a loop through a vertex that starts two boundary edges stays open. A fan suits small, nearly planar, convex holes; others can come out folded, so validate the result.

merge method descriptor

merge(other)

The solid inside this mesh or other.

Parameters:

Name Type Description Default
other Mesh

A closed mesh in the same CRS and length unit, when both declare one.

required

Returns:

Type Description
Mesh

A closed mesh wound outward. Faces keep the columns of the face they came from, the union of both meshes' face columns with nulls where a mesh lacks one; vertex columns carry over the same way, null on vertices made where the surfaces cross. Where faces of both meshes lie in one plane facing the same way, the first mesh's face is kept. Empty when nothing is kept.

Raises:

Type Description
InvalidInput

When a mesh is open, the CRSs or length units differ, a column has different types in the two meshes, or the result would not be a closed solid, such as two solids meeting only along an edge.

Notes

The surfaces are corefined: triangles that cross are split along their intersection, found with exact orientation predicates, and each piece is kept by whether it lies inside the other mesh. Points closer than 1e-9 of the size of both meshes weld together, or 1e-6 where faces lying within rounding of each other need it to close.

overlap method descriptor

overlap(other)

The solid inside both this mesh and other.

Parameters:

Name Type Description Default
other Mesh

A closed mesh in the same CRS and length unit, when both declare one.

required

Returns:

Type Description
Mesh

A closed mesh, with columns carried over as in merge. Empty when the solids do not overlap.

Raises:

Type Description
InvalidInput

As merge.

proportion method descriptor

proportion(targets, *, size=None, discretization=Ellipsis)

Proportion of each block inside, from a grid of points per block where the surface may cut it: discretization per axis, or one count for all three. targets is a BlockModel, whose rotation and sub-block extents count, or axis-aligned centroids with a shared size, finite and positive. A discretization of more than 10 000 000 points per block raises InvalidInput.

repair method descriptor

repair(*, tolerance=0.0)

Weld close vertices, drop degenerate and duplicate triangles, and wind the triangles consistently.

Parameters:

Name Type Description Default
tolerance float

Vertices within this distance of an earlier vertex merge into it; 0 merges exact duplicates only.

0.0

Returns:

Type Description
Mesh

A new mesh without unused vertices, each connected piece wound one way. A closed piece inside an even number of other closed pieces winds outward; inside an odd number it is a cavity and winds inward, so the volume is outer minus cavities. Kept vertices and triangles keep their order and attributes. Repairing it again changes nothing. Crossing faces stay; validate reports them.

section method descriptor

section(origin, normal, *, offsets=None)

Lines where one or more parallel planes cut the mesh.

Parameters:

Name Type Description Default
origin sequence of float

A point on the plane, (x, y, z).

required
normal sequence of float

The plane's normal, any non-zero length.

required
offsets sequence of float

Distances along the unit normal to move the plane by, one section each; defaults to [0.0], the plane through origin.

None

Returns:

Type Description
Polylines

One feature per line, with an offset column naming its plane and the face columns of the faces it crosses. A closed mesh gives closed loops and an open surface open lines where the cut leaves it; a line through faces whose columns differ splits into open lines where they change. Loops of a solid wound outward run counter-clockwise around its inside seen from the side normal points to, so loops round cavities run clockwise. A vertex on a plane counts as on the side normal points to, so a face lying in the plane adds nothing. The CRS and length unit carry over.

Raises:

Type Description
InvalidInput

With a zero or non-finite normal, non-finite offsets, or a face column named offset.

subtract method descriptor

subtract(other)

The solid inside this mesh and outside other.

Parameters:

Name Type Description Default
other Mesh

A closed mesh in the same CRS and length unit, when both declare one.

required

Returns:

Type Description
Mesh

A closed mesh, with columns carried over as in merge. Faces from other are turned over to face out of the result; a solid inside other leaves a cavity wound inward.

Raises:

Type Description
InvalidInput

As merge.

to_crs method descriptor

to_crs(target)

A copy in the CRS target, an EPSG code such as EPSG:4326.

Geographic and UTM CRSs on WGS 84, SIRGAS 2000, SAD69, NAD83, ETRS89 and GDA2020 are supported, with datum changes by the published EPSG 7-parameter Helmert transformations. Geographic coordinates are longitude and latitude in degrees, projected ones are in metres; heights are kept.

Parameters:

Name Type Description Default
target str

The CRS to convert to, EPSG:n.

required

Returns:

Type Description
Mesh

The mesh in target.

Raises:

Type Description
InvalidInput

Without a CRS, or with a CRS outside the supported set.

to_length_unit method descriptor

to_length_unit(unit, *, crs=None)

A copy with the coordinates converted to unit, the new length unit.

Parameters:

Name Type Description Default
unit str

A length unit, such as m or ft.

required
crs str

The CRS of the converted coordinates; required when the coordinates have a CRS, which a change of unit changes.

None

Raises:

Type Description
InvalidInput

Without a length unit to convert from, or with a CRS and no crs.

validate method descriptor

validate(*, tolerance=0.0)

Everything that keeps the mesh from being a clean closed solid.

Parameters:

Name Type Description Default
tolerance float

A vertex within this distance of an earlier vertex is a duplicate; 0 finds exact duplicates only.

0.0

Returns:

Type Description
MeshReport

Counts in summary and one row per problem in problems. Degenerate faces are left out of the edge, vertex and shell checks.

vertical_distance method descriptor

vertical_distance(points)

Signed vertical distance to a surface such as topography.

Parameters:

Name Type Description Default
points (array_like, PointSet or BlockModel)

(n, 3) points, or the centroids of a point set or block model. Rows with a NaN coordinate are allowed.

required

Returns:

Type Description
ndarray

Point elevation minus surface elevation at the same (x, y): positive above, negative below. NaN where a coordinate is NaN or no triangle covers the point in plan; where the surface overlaps itself, the highest counts.

with_face_column method descriptor

with_face_column(name, values)

New mesh with the per-triangle attribute name added or replaced.

with_vertex_column method descriptor

with_vertex_column(name, values)

New mesh with the per-vertex attribute name added or replaced.

Used in