distmesh, a MATLAB code which generates and manipulates unstructured meshes in 2D, 3D and general ND, by Per-Olof Persson.

The code is relatively simple, and the user is able to define a variety of geometric shapes, and desired mesh densities.

DISTMESH can be a very quick and flexible means of computing a set of points in a region. However, keep in mind the following considerations:


[ p, t ] = distmesh_2d ( fd, fh, h, box, iteration_max, fixed );


DISTMESH is Copyright (C) 2004 Per-Olof Persson.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

If you use distmesh() in any program or publication, please acknowledge its authors by citing the reference.


distmesh is available in a MATLAB version.

Related Data and Programs:

dist_plot, a MATLAB code which creates a color contour plot of the distance functions that are used by DISTMESH.

distmesh_3d, a MATLAB code which is a subset of the DISTMESH routines, exclusively for 3D problems.


mesh2d, a MATLAB code which can automatically create a triangular mesh for a given polygonal region, by Darren Engwirda.

table_io, a MATLAB code which reads and writes files using the TABLE format.

test_triangulation, a MATLAB code which defines some test regions for triangulation.

triangulation_boundary_nodes, a MATLAB code which reads data defining a triangulation and determines which nodes lie on the boundary.

triangulation_l2q, a MATLAB code which reads data defining a linear triangulation and adds midpoint nodes to create a quadratic triangulation.

triangulation_mask, a MATLAB code which is compiled with a user routine that defines a region; it then reads data defining a triangulation and removes all triangles that are outside the region. This is one way to clean up an unconstrained Delaunay triangulation of a nonconvex region.

triangulation_order3, a data directory which discusses order 3 triangulations; The node and triangle files output by DISTMESH are an example of such triangulations.

triangulation_orient, a MATLAB code which reads data defining a triangulation, makes sure that every triangle has positive orientation, and if not, writes a corrected triangle file.

triangulation_plot, a MATLAB code which plots a triangulation.

triangulation_rcm, a MATLAB code which reads data defining a triangulation, and uses the Reverse Cuthill McKee algorithm to reorder the nodes so as the reduce the bandwidth of the corresponding adjacency matrix. This can be very helpful for cases where the data is to be handled by a frontal technique, or treated as a banded linear system.

triangulation_refine, a MATLAB code which reads data defining a triangulation and creates a refinement of the triangulation by subdividing each triangle.


Per-Olof Persson.


  1. Per-Olof Persson and Gilbert Strang,
    A Simple Mesh Generator in MATLAB,
    SIAM Review,
    Volume 46, Number 2, June 2004, pages 329-345.

Source Code:

Last revised on 09 January 2019.