DistMesh.jl implements simplex refinement on signed distance functions, or anything that has a sign, distance, and called like a function. The algorithm was first presented in 2004 by Per-Olof Persson, and was initially a port of the corresponding Matlab Code.

What is Simplex Refinement?

In layman's terms, a simplex is either a triangle in the 2D case, or a tetrahedra in the 3D case.

When simulating, you other want a few things from a mesh of simplices: - Accurate approximation of boundaries and features - Adaptive mesh sizes to improve accuracy - Near-Regular Simplicies

DistMesh is designed to address the above.

Algorithm Overview

The basic processes is as follows:

Comparison to other refinements

DistMesh generally has a very low memory footprint, and can refine without additional memory allocation. Similarly, since the global state of simplex qualities is accounted for in each refinement iteration, this leads to very high quality meshes.

Aside from the above, since DistMesh works on signed distance functions it can handle complex and varied input data that are not in the form of surface meshes (Piecewise Linear Complicies).

Difference from the MatLab implementation

Given the same parameters, the Julia implementation of DistMesh will generally perform 4-60 times faster than the MatLab implementation. Delaunay Triangulation in MatLab uses QHull, whereas DistMesh.jl uses TetGen.

How do I get a Signed Distance Function?

Here are some libraries that turn gridded and level set data into an approximate signed distance function:

  • Interpolations.jl
  • AdaptiveDistanceFields.jl

Use Tetrahedral quality analysis to control the meshing process

iso (default: 0): Value of which to extract the iso surface, inside negative
deltat (default: 0.1): the fraction of edge displacement to apply each iteration

A struct returned from the distmesh function that includes point, simplex, and interation statistics.


Takes Keyword arguments as follows:

iso (default: 0): Value of which to extract the isosurface, inside surface is negative
deltat (default: 0.1): the fraction of edge displacement to apply each iteration
sort (default:false): If true and no fixed points, sort points using a hilbert sort.
sort_interval (default:20) Use hilbert sort after the specified retriangulations
distribution (default: :regular) Initial point distribution, either :regular or :packed.
3D Mesh Generator using Signed Distance Functions.
    fdist:       Distance function
    fh:          Edge length function
    h:           Smallest edge length

    p:           Node positions
    t:           Triangle indices

Example: Unit ball
    d(p) = sqrt(sum(p.^2))-1
    p,t = distmeshnd(d,huniform,0.2)

Hilbert Sorting. If carry is specified, this array will be permuted in line with the specified array.


Given a point set, generate a delaunay triangulation, and other requirements. This includes: - Spatial sorting of points - Delaunay triangulation - Filtering of invalid tetrahedra outside the boundary

Decompose tets to edges, using a pre-allocated array and set.
Set ensures uniqueness, and result will be sorted.

Determine the quality of a triangle given 3 points.

Points must be 3D.