Implicit Meshing#

Mesh generation based on implicit functions is a major focus of MyMesh. It offers a way to generate surface and volume meshes of objects defined by mathematical functions.

What is an implicit function?#

In three dimensions, implicit functions represent surfaces with the form:

\[f(x,y,z) = 0\]

For example, a sphere defined by \(x^2+y^2+z^2=r^2\) can be represented implicitly by the function \(f(x,y,z) = x^2+y^2+z^2 - r^2 = 0\). Any point satisfying the condition \(f(x,y,z) = 0\) is considered to be on the surface, while points where \(f(x,y,z) < 0\) are considered to be inside the surface and points where \(f(x,y,z) > 0\) are considered to be outside the surface. This convention is assumed by default throughout the implicit meshing functions of MyMesh (others may adopt the opposite convention elsewhere).

Defining implicit functions#

Implicit functions being defined for use with MyMesh should generally be defined as functions of three variables (x, y, z) and accept vectorizable inputs (if x, y, z are scalars, func(x, y, z) should return a scalar, if x, y, z are numpy arrays, func(x, y, z) should return an array). For example, the “surface of genus 2” example from wikipedia can be defined as follows:

def example_func(x,y,z):
    f = 2*y*(y**2 - 3*x**2)*(1-z**2) + (x**2 + y**2)**2 - (9*z**2 - 1)*(1-z**2)
    return f

Several built-in implicit function are available in mymesh.implicit, including a sphere, box, and torus. For example, the implicit function of a unit sphere (center = (0,0,0), radius=1) can be obtained from: func = implicit.sphere([0,0,0], 1)

More complex geometries can be obtained by combining multiple functions using union, intersection, and difference operations (see Implicit CSG for more details).

Meshing Implicit Functions#

Surface Meshing

m = implicit.SurfaceMesh(example_func, [-2,2,-2,2,-2,2], .05)
../_images/implicit_meshing-3.png
../_images/implicit_meshing-4.png

Volume Meshing

m = implicit.VoxelMesh(example_func, [-2,2,-2,2,-2,2], .1)
../_images/implicit_meshing-6.png
../_images/implicit_meshing-7.png
m = implicit.TetMesh(example_func, [-2,2,-2,2,-2,2], .05)
../_images/implicit_meshing-9.png
../_images/implicit_meshing-10.png