magnet.cell.Polyhedron#

class magnet.cell.Polyhedron(nodes=None, mesh_vertices=None, faces=None)#

Bases: Cell

Generic 3D polyhedral cell.

Constructor

__init__(nodes=None, mesh_vertices=None, faces=None) None#

Methods

inscribed_diameter([center])

Compute the diameter of the inscribed sphere of the cell.

is_inside(p)

Check if a point is inside the polyhedron.

surface_area()

Compute the surface area of the cell.

volume()

Compute the volume of the polyhedron.

volume_center()

inscribed_diameter(center=None) float#

Compute the diameter of the inscribed sphere of the cell.

Computes (approximately) the diameter of the biggest sphere contained in the polyhedron.

Parameters:

center (np.ndarray, optional) – Center point of the circle for diameter computation. By default, uses the centroid of the convex hull of the cell.

Returns:

The diameter of the inscribed sphere.

Return type:

float

Notes

The inscribed diameter is computed by taking the centroid of the cell and then computing its minimum distance to each face of the polyhedron. If the face is a triangle, this is done geometrically by projection (cheaper), otherwise a constrained minimization problem is solved (slower and less accurate).

is_inside(p)#

Check if a point is inside the polyhedron.

Parameters:

p (np.ndarray of float) – Point in question.

Returns:

True if the point is inside the polyhedron, False otherwise.

Return type:

bool

Notes

Uses ray casting method; the ray is cast in a random direction. Only supports triangular faces.

surface_area() float#

Compute the surface area of the cell.

Parameters:

None

Returns:

Surface area value.

Return type:

float

volume()#

Compute the volume of the polyhedron.

The volume is computed using the formula derived from the divergence theorem. Note that the face normals must be oriented consistently for this to work.

Parameters:

None

Returns:

Volume value.

Return type:

float

volume_center()#

Inherited Methods

__init__([nodes, mesh_vertices, faces])