# Triangular mesh of a 3D surface

I have an irregular grid of points describing this surface (a large subduction fault in South America). The color is depth. Anyway I have 3D coordinates (lon,lat,depth) at irregular intervals. I'm trying to generate a triangular mesh using gmsh but I'm struggling with how. I can make every irregular grid point be a "Point" in gmsh with a little python function:

def xyz2gmsh(fout,x,y,z):
f=open(fout,'w')
for k in range(len(x)):
line='Point('+str(k+1)+') = {%.6f, %.6f, %.6f, 0.01};\n' %(x[k],y[k],z[k])
f.write(line)
f.close()


And this file (fout) gnerated loads into gmsh but nothing shows! As I understand it I need to somehow tell gmsh that these points collectively represent a surface to be meshed. How? And can I tell gmsh to shoot for making elements of a certain size?

Thanks!

• This is a question best asked on the gmsh mailing lists. Jan 17, 2015 at 20:30
• How complex is the surface you're looking at? Does it fold under itself at any point? If you can (temporarily) toss out the z-values, generate a 2d triangular mesh based on the $x$, $y$-values of the sample points, and then "lift" that up to a surface mesh, it would be easier than generating the surface mesh from the start. Jan 17, 2015 at 21:00
• As long as the gradients of depth aren't too steep, @DanielShapero's method should work pretty well. You could end up with some pretty distorted triangles if they are large since points that are a separated by a large distance get projected only a short distance away from one another in the (x,y) plane. As a side note, the "0.01" that you've hard-coded into your python function is the suggested element size. Jan 17, 2015 at 21:07
• The surface is very smooth and close to horizontal, so yeah, ignoring the z is not too bad. So how do I do this in gmsh? I need to specify the perimeter then? The tutorial has something about a Line Loop? I just started with gmsh yesterday... Jan 17, 2015 at 21:12
• Since you already have the points, gmsh may not be the right tool. Gmsh uses a Boundary Representation (BREP) to represent the geometry, onto which it places points that will become the mesh. Since you already have the mesh points, half of that work is already done. What you need to do is to identify the exterior boundary (if not convex) and just use a constrained Delaunay triangulation tool on the points. There are many such tools ready-to-use in the wild. Here's some bonus reading: en.wikipedia.org/wiki/Chew%27s_second_algorithm Jan 17, 2015 at 21:20

I'll expand my comment to an answer. Since your surface is fairly smooth, rather than generating a surface mesh, you can generate a 2D mesh of just the $(x, y)$-points that have been sampled, and then create a surface mesh by adding in the $z$-values later.
In gmsh, you'd have to specify a line loop that parameterizes the convex hull of your input points. With Triangle, you can just give it a point cloud; it will compute the convex hull for you and then triangulate the interior. You only have to describe the boundary if the domain isn't convex. To get triangles of given area, you can either give it a command line switch, or you can write a special .area file if the desired sizes are depend on where you are. I have example code for doing just that in Python for a case where I needed a mesh that was finer in some areas than others.