# 2D mesh generator with geometric primitives

The question is exactly as the title: Which 2D (triangular) mesh generator software can be used which has a set of geometric primitives, controlled mesh size and standard output (.vtk or something similar)?

For testing my code I need a triangular mesh for a circle and I am looking for the easiest way to do that. E.g., in 3D case for a sphere I am happy to use NETGEN with several lines of code to get meshes with controlled mesh size and standard output format.

Can anyone give me a recommendation?

Thanks!

Shewchuk's triangle mesh generator produces high quality meshes and is quite robust. However, the boundary definition is a series of straight lines. So to produce a sequence of refined meshes over a circle you would also have to refine the definition of the boundary for each mesh.

Another option is Persson's distmesh triangle mesher, As shown on this page, only two lines of MATLAB (or Octave) code are required to mesh a circle

fd=@(p) sqrt(sum(p.^2,2))-1;
[p,t]=distmesh2d(fd,@huniform,0.2,[-1,-1;1,1],[]);


And the mesh can be refined by changing a single "mesh density" parameter with no changes to the geometry definition.

You can conveniently use MATLAB to write the coordinate matrix, p, and the connectivity matrix, t, in whatever format you choose. And, as I've verified, it also runs in Octave if you don't have access to MATLAB.

• Thought the same about the Triangle. distmesh seems to be exactly what I need right now, thank you! Feb 21 '17 at 22:03

You can use Jonathan Shewchuk's triangle mesh generator [1]. It has its own file format, but it can be easily translated. If you plan to embed it in another software, it can be also compiled as a library with an easy to use API. You can also use CGAL [2], a large piece of software with many functionalities (including 2D mesh generation).

• Thanks for the ideas. I had some experience with Triangle, but somehow I was sure that it is difficult to make a circle there (are you sure it is possible?), I will look more carefully, as well as have a look at CGAL. Feb 21 '17 at 20:15