Skip to content

Mesh from common files

An alternative option is to use the mesh generation tools provided by the Partial Differential Toolbox in Matlab. Such function is also included in Mesh.generate. SDFs can also be used in this process, although an intermediate step is required. For two-dimensional domains, SDFs are first converted into binary images and then the image boundary detection is used to convert them to either a linear mesh Tri3 or a quadratic mesh Tri6. Direct input of black-and-white .jpg or .png images is also supported. For three-dimensional domains, SDF functions are converted to an .stl file using the Marching Cube algorithm1 and then provided to the Matlab PDE toolbox to generate the tessellation. Importing and exporting .stl or .obj files directly is also possible.

Example: Mesh from image file

Image title Image title

1
2
3
4
5
6
7
8
9
% distance function
file = '+preset/assets/img/sorotoki_bwlogo.png'

% generate mesh
msh = Mesh(file,'ElementSize',2.5);
msh = msh.generate;

% show mesh
msh.show();

For Sorotoki to use .png/.jpg, the background must be white and foreground black!
Example: Mesh from STL file

Image title Image title

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
% distance function
file = '+preset/assets/stl/Bunny.stl'

% generate mesh
msh = Mesh(file,'ElementSize',5);
msh = msh.generate;

% show mesh
msh.show();
view(10,10);


  1. William E. Lorensen and Harvey E. Cline. Marching cubes: A high resolution 3D surface construction algorithm. In ACM SIGGRAPH Computer Graphics, volume 21, pages 163–169. Association for Computing Machinery, New York, NY, USA, 1987. doi:10.1145/37401.37422