Convex Hull

Contents

Convex Hull#

In geometry the convex hull of a point cloud is the smallest convex shape that contains all points, see Wikipedia.

Magpylib offers construction of convex hull magnets by combining the magpylib.magnets.TriangularMesh and the scipy.spatial.ConvexHull classes via the classmethod from_ConvexHull. Note, that the Scipy method does not guarantee correct face orientations if reorient_faces is disabled.

Pyramid magnet#

This is the fastest way to construct a pyramid magnet.

import numpy as np

import magpylib as magpy

# Create pyramid magnet
points = np.array([(-2, -2, 0), (-2, 2, 0), (2, -2, 0), (2, 2, 0), (0, 0, 3)]) / 100
tmesh_pyramid = magpy.magnet.TriangularMesh.from_ConvexHull(
    polarization=(0, 0, 1),
    points=points,
    style_label="Pyramid Magnet",
)

# Display graphically
tmesh_pyramid.show(backend="plotly")