{"id":22059737,"url":"https://github.com/precise-simulation/distmesh","last_synced_at":"2025-05-12T19:55:17.696Z","repository":{"id":201688126,"uuid":"490177134","full_name":"precise-simulation/distmesh","owner":"precise-simulation","description":"DistMesh - simple 2D and 3D mesh generator for MATLAB and Octave (with GUI support)","archived":false,"fork":false,"pushed_at":"2022-05-09T07:36:56.000Z","size":34,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-01T02:52:59.093Z","etag":null,"topics":["matlab","mesh","mesh-generation","octave"],"latest_commit_sha":null,"homepage":"https://www.featool.com/grid/2018/03/06/Matlab-Mesh-Generation-Comparison.html","language":"MATLAB","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/precise-simulation.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2022-05-09T07:24:08.000Z","updated_at":"2024-11-29T08:28:44.000Z","dependencies_parsed_at":null,"dependency_job_id":"81b7cd67-6d67-4019-99df-2f4dcf179f37","html_url":"https://github.com/precise-simulation/distmesh","commit_stats":null,"previous_names":["precise-simulation/distmesh"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/precise-simulation%2Fdistmesh","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/precise-simulation%2Fdistmesh/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/precise-simulation%2Fdistmesh/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/precise-simulation%2Fdistmesh/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/precise-simulation","download_url":"https://codeload.github.com/precise-simulation/distmesh/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253813486,"owners_count":21968491,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["matlab","mesh","mesh-generation","octave"],"created_at":"2024-11-30T17:32:09.124Z","updated_at":"2025-05-12T19:55:17.654Z","avatar_url":"https://github.com/precise-simulation.png","language":"MATLAB","funding_links":[],"categories":[],"sub_categories":[],"readme":"DistMesh - A Simple Mesh Generator for MATLAB\n=============================================\n\nAbout DistMesh\n--------------\n\nDistMesh is a simple MATLAB and\n[GNU Octave](https://www.gnu.org/software/octave/) code for automatic\ngeneration of unstructured 2D triangular and 3D tetrahedral volume\nmeshes.\n\nThis repository contains a slightly modified, consolidated, and\nrefactored version of DistMesh, which also can be used from a\ngraphical user interface (GUI) together with the FEATool Multiphysics\nOctave and [MATLAB PDE and FEM Toolbox](https://www.featool.com).\n\nNote that a Julia implementation of this DistMesh version is also\navailable in the\n[DistMesh-Julia repository](https://github.com/precise-simulation/distmesh-julia)\nas well as\nQuadMesh - unstructured quadrilateral mesh generation based on distance functions.\n\n\u003ctable align=\"center\"\u003e\n\u003ctr\u003e\n\u003ctd width=\"30%\"\u003e\u003cimg src=\"https://www.featool.com/images/featool-multiphysics-easy-to-use-gui.jpg\" style=\"width:100%\"\u003e\u003c/td\u003e\n\u003ctd width=\"30%\"\u003e\u003cimg src=\"https://www.featool.com/doc/grid_main_50.png\" style=\"width: 100%;\"\u003e\u003c/td\u003e\n\u003ctd width=\"30%\"\u003e\u003cimg src=\"http://persson.berkeley.edu/distmesh/ex06zoom.png\" style=\"width: 100%;\"\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/table\u003e\n\n\nDescription\n-----------\n\nThe DistMesh algorithm was invented by Per-Olof Persson and Gilbert\nStrang in the Department of Mathematics at MIT. More detailed\ndescriptions of the original DistMesh method and MATLAB mesh\ngeneration code can be found in the SIAM Review paper and other\nreferences linked below.\n\nThe simplicity of the DistMesh algorithm is due to using signed\ndistance functions (level sets) to specify and describe domains,\ngeometries, and regions to mesh. Distance functions specify the\nshortest distance from any point in space to the boundary of the\ndomain, where the sign of the function is positive outside the region,\nnegative inside, and zero on the boundary. This definition is used to\nidentify if a point is located in or outside of the\ngeometry. Moreover, the gradient of the distance function points in\nthe direction of the boundary, allowing points outside to be\nefficiently moved back to the domain.\n\nA simple example is the unit circle in two dimensions, which has the\ndistance function _d(r) = r-1_, where _r = sqrt(x^2+y^2)_ is the\ndistance from the origin. For more complicated geometries the distance\nfunction can be computed by interpolation between values on a grid,\nwhich is a common representation for level set methods.\n\nFor the mesh generation procedure, DistMesh uses the Delaunay\ntriangulation routine in MATLAB and Octave and tries to optimize the\nnode locations by a force-based smoothing procedure. The topology is\nregularly updated by Delaunay. The boundary points are only allowed to\nmove tangentially to the boundary by projections using the distance\nfunction. This iterative procedure typically results in very uniform\nand well-shaped high quality meshes.\n\n\nModifications\n-------------\n\nIn addition to cleanup, refactoring, and consolidation, this DistMesh\nimplementation has been modified in the following ways:\n\n- CAD geometry and GUI support (with the FEATool Multiphysics Toolbox)\n\n- 2D and 3D cases merged and handled in one code base.\n\n- Full support for mesh generation in both MATLAB and Octave.\n\n- Support for constrained edges (and constraint functions).\n\n- Delaunay function selection depending on MATLAB or Octave version\n  (with constrained Delaunay triangulation if available).\n\n- _fd_ and _fh_ can both be specified as function handles and as cell\n  arrays of a function handle/string names with optional calling\n  arguments.\n\n- Alternative optimized edge pair computation.\n\n- Optional number of re-tracing steps for grid points outside domain.\n\n- Added statistics and timing output.\n\n\nUsage\n-----\n\nTo use the this mesh generation code, simply download the stand alone\n[distmesh](https://github.com/precise-simulation/distmesh/blob/master/distmesh.m)\nsource code and run it in MATLAB or Octave. The function syntax is as follows\n\n    [ P, T, STAT ] = DISTMESH( FD, FH, H0, BBOX, P_FIX, E_FIX, IT_MAX, FID, FIT )\n\nwhere **FD** is a function handle to the geometry description that\nshould take evaluation coordinates and points as input. For example\n\u003ccode\u003efd = @(p) sqrt(sum(p.^2,2)) - 1;\u003c/code\u003e specifies the distance\nfunction for a unit circle (both function handles, string function\nnames, and anonymous functions are supported). Similar to _FD_, **FH**\na function describing the desired relative mesh size distribution. For\nexample \u003ccode\u003efh = @(p) ones(size(p,1),1);\u003c/code\u003e specifies a uniform\ndistribution where _FH_ evaluates to _1_ at all points. **H0** is a\nnumeric scalar specifying the initial edge lengths, and **BBOX** is a\n2 by 2 in 2D (or 2 by 3 in 3D) bounding box of the domain (enclosing\nthe zero contour/level set of _FD_). **P_FIX** optionally specifies a\nnumber of points that should always be present (fixed) in the\nresulting mesh. **E_FIX** can be sets of edge vertex indices to\nconstrain, or alternatively a cell array with function handle to call.\n**IT_MAX** sets the maximum number of grid generation iterations\nallowed (default _1000_).  Finally, **FID** specifies a file\nidentifies for output (default _1_ = terminal output), **FIT** is an\noptional % function to call every iteration to check for early\ntermination.\n\nThe DistMesh MATLAB function returns the grid point vertices in **P**,\ntriangulated simplices in **T**, as well as an optional statistics\nstruct **STAT** including timings and convergence information.\n\n    Input:\n\n       FD:        Distance function d(x,y,(z))\n       FH:        Scaled edge length function h(x,y,(z))\n       H0:        Initial edge length\n       BBOX:      Bounding box [xmin,ymin,(zmin); xmax,ymax,(zmax)]\n       P_FIX:     Fixed node positions (N_P_FIX x 2/3)\n       E_FIX:     Constrained edges (N_E_FIX x 2)\n       IT_MAX:    Maximum number of iterations\n       FID:       Output file id number (default 1 = terminal)\n\n    Output:\n\n       P:         Grid vertex/node coordinates (N_P x 2/3)\n       T:         Triangle indices (N_T x 3)\n       STAT:      Mesh generation statistics (struct)\n\n\n\nExamples\n--------\n\nTo automatically run the collection of basic mesh generation examples\ndescribed below, type\n[distmesh_demo](https://github.com/precise-simulation/distmesh/blob/master/distmesh_demo.m)\ninto the MATLAB or Octave CLI command prompts from the directory where\nthe _distmesh_ files can be found.\n\n- Example 1: Uniform mesh on unit circle\n\n        fd = @(p) sqrt(sum(p.^2,2)) - 1;\n        fh = @(p) ones(size(p,1),1);\n        [p,t] = distmesh( fd, fh, 0.2, [-1,-1;1,1] );\n        patch( 'vertices', p, 'faces', t, 'facecolor', [.9, .9, .9] )\n\n- Example 2: Uniform mesh on ellipse\n\n        fd = @(p) p(:,1).^2/2^2 + p(:,2).^2/1^2 - 1;\n        fh = @(p) ones(size(p,1),1);\n        [p,t] = distmesh( fd, fh, 0.2, [-2,-1;2,1] );\n        patch( 'vertices', p, 'faces', t, 'facecolor', [.9, .9, .9] )\n\n- Example 3: Uniform mesh on unit square\n\n        fd = @(p) -min(min(min(1+p(:,2),1-p(:,2)),1+p(:,1)),1-p(:,1));\n        fh = @(p) ones(size(p,1),1);\n        [p,t] = distmesh( fd, fh, 0.2, [-1,-1;1,1], [-1,-1;-1,1;1,-1;1,1] );\n        patch( 'vertices', p, 'faces', t, 'facecolor', [.9, .9, .9] )\n\n- Example 4: Uniform mesh on complex polygon\n\n        pv = [-0.4 -0.5;0.4 -0.2;0.4 -0.7;1.5 -0.4;0.9 0.1;\n              1.6 0.8;0.5 0.5;0.2 1;0.1 0.4;-0.7 0.7;-0.4 -0.5];\n        fd = { 'l_dpolygon', [], pv };\n        fh = @(p) ones(size(p,1),1);\n        [p,t] = distmesh( fd, fh, 0.1, [-1,-1; 2,1], pv );\n        patch( 'vertices', p, 'faces', t, 'facecolor', [.9, .9, .9] )\n\n- Example 5: Rectangle with circular hole, refined at circle boundary\n\n        drectangle = @(p,x1,x2,y1,y2) -min(min(min(-y1+p(:,2),y2-p(:,2)),-x1+p(:,1)),x2-p(:,1));\n        fd = @(p) max( drectangle(p,-1,1,-1,1), -(sqrt(sum(p.^2,2))-0.5) );\n        fh = @(p) 0.05 + 0.3*(sqrt(sum(p.^2,2))-0.5);\n        [p,t] = distmesh( fd, fh, 0.05, [-1,-1;1,1], [-1,-1;-1,1;1,-1;1,1] );\n        patch( 'vertices', p, 'faces', t, 'facecolor', [.9, .9, .9] )\n\n- Example 6: Square, with size function point and line sources\n\n        dcircle = @(p,xc,yc,r) sqrt((p(:,1)-xc).^2+(p(:,2)-yc).^2)-r;\n        fd = @(p) -min(min(min(p(:,2),1-p(:,2)),p(:,1)),1-p(:,1));\n        dpolygon = @(p,v) feval('l_dpolygon',p,v);\n        fh = @(p) min(min(0.01+0.3*abs(dcircle(p,0,0,0)), ...\n                          0.025+0.3*abs(dpolygon(p,[0.3,0.7;0.7,0.5;0.3,0.7]))),0.15);\n        [p,t] = distmesh( fd, fh, 0.01, [0,0;1,1], [0,0;1,0;0,1;1,1] );\n        patch( 'vertices', p, 'faces', t, 'facecolor', [.9, .9, .9] )\n\n- Example 7: NACA0012 airfoil\n\n        hlead = 0.01; htrail = 0.04; hmax = 2; circx = 2; circr = 4;\n        a = 0.12/0.2*[0.2969,-0.126,-0.3516,0.2843,-0.1036];\n        fd = @(p) max( dcircle(p,circx,0,circr), ...\n                       -((abs(p(:,2))-polyval([a(5:-1:2),0],p(:,1))).^2-a(1)^2*p(:,1)) );\n        fh = @(p) min(min(hlead+0.3*dcircle(p,0,0,0),htrail+0.3*dcircle(p,1,0,0)),hmax);\n\n        fixx = 1 - htrail*cumsum(1.3.^(0:4)');\n        fixy = a(1)*sqrt(fixx) + polyval([a(5:-1:2),0],fixx);\n        pfix = [[circx+[-1,1,0,0]*circr; 0,0,circr*[-1,1]]'; 0,0; 1,0; fixx,fixy; fixx,-fixy];\n        bbox = [circx-circr,-circr; circx+circr,circr];\n        h0   = min([hlead,htrail,hmax]);\n        [p,t] = distmesh( fd, fh, h0, bbox, pfix );\n        patch( 'vertices', p, 'faces', t, 'facecolor', [.9, .9, .9] )\n\n- Example 8: Uniform mesh on unit sphere\n\n        fd = @(p) sqrt(sum(p.^2,2)) - 1;\n        fh = @(p) ones(size(p,1),1);\n        [p,t] = distmesh( fd, fh, 0.2, [-1,-1,-1;1,1,1] );\n        f = [t(:,[1:3]); t(:,[1,2,4]); t(:,[2,3,4]); t(:,[3,1,4])];\n        patch( 'vertices', p, 'faces', f, 'facecolor', [.9, .9, .9] )\n\n- Example 9: Uniform mesh on unit cube\n\n        fd = @(p) -min(min(min(min(min(p(:,3),1-p(:,3) ),p(:,2)),1-p(:,2)),p(:,1)),1-p(:,1));\n        fh = @(p) ones(size(p,1),1);\n        pfix = [-1,-1,-1;-1,1,-1;1,-1,-1;1,1,-1; -1,-1,1;-1,1,1;1,-1,1;1,1,1];\n        [p,t] = distmesh( fd, fh, 0.2, [-1,-1,-1;1,1,1], pfix );\n        f = [t(:,[1:3]); t(:,[1,2,4]); t(:,[2,3,4]); t(:,[3,1,4])];\n        patch( 'vertices', p, 'faces', f, 'facecolor', [.9, .9, .9] ), view(3)\n\n- Example 10: Uniform mesh on cylinder\n\n        fd = @(p) -min(min(p(:,3),4-p(:,3)),1-sqrt(sum(p(:,1:2).^2,2)));\n        fh = @(p) ones(size(p,1),1);\n        pfix = [-1,-1,-1;-1,1,-1;1,-1,-1;1,1,-1; -1,-1,1;-1,1,1;1,-1,1;1,1,1];\n        [p,t] = distmesh( fd, fh, 0.5, [-1,-1,0;1,1,4], [] );\n        f = [t(:,[1:3]); t(:,[1,2,4]); t(:,[2,3,4]); t(:,[3,1,4])];\n        patch( 'vertices', p, 'faces', f, 'facecolor', [.9, .9, .9] ), view(3)\n\n\nReferences\n----------\n\n[1] [P.-O. Persson, G. Strang, A Simple Mesh Generator in MATLAB. SIAM Review, Volume 46 (2), pp. 329-345, June 2004.](http://persson.berkeley.edu/distmesh/persson04mesh.pdf)\n\n[2] [P.-O. Persson, Mesh Generation for Implicit Geometries. Ph.D. thesis, Department of Mathematics, MIT, Dec 2004.](http://persson.berkeley.edu/thesis/persson-thesis-color.pdf)\n\n[3] [P.-O. Persson's DistMesh website](http://persson.berkeley.edu/distmesh/)\n\n[4] [FEATool Multiphysics grid generation documentation](https://www.featool.com/doc/grid.html)\n\n\nAlternative Implementations\n---------------------------\n\n[5] [libDistMesh: A Simple Mesh Generator in C++](https://github.com/pgebhardt/libdistmesh)\n\n[6] [DistMesh-Julia - Julia Mesh Generation with DistMesh](https://github.com/precise-simulation/distmesh-julia)\n\n[7] [PyDistMesh - A Simple Mesh Generator in Python](https://github.com/bfroehle/pydistmesh)\n\n[8] [Mesh generator - Java implementation of DistMesh](https://github.com/plichjan/jDistMesh)\n\n[9] [DistMesh - Wolfram Language Implementation](https://github.com/WolframResearch/DistMesh)\n\n[10] [J. Burkardt's DistMesh repository](http://people.sc.fsu.edu/~jburkardt/m_src/distmesh/distmesh.html)\n\n[11] [KOKO Mesh Generator](http://fc.isima.fr/~jkoko/codes.html)\n\n\nLicense\n-------\n\nDistMesh is distributed for free under the GNU GPL; see the License\nand Copyright notice for more information.\n\nModifications made to the original DistMesh code are copyrighted by\nPrecise Simulation Limited and licensed under the GNU GPL License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprecise-simulation%2Fdistmesh","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprecise-simulation%2Fdistmesh","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprecise-simulation%2Fdistmesh/lists"}