# 2D examples of DistMesh.jl or other simple mesh generator?

**URL:** <https://discourse.julialang.org/t/2d-examples-of-distmesh-jl-or-other-simple-mesh-generator/114404>\
**Category:** General Usage\
**Tags:** mesh, finite-element, meshes, distmesh\
**Created:** [May 17, 2024, 4:05pm UTC](https://discourse.julialang.org/t/2d-examples-of-distmesh-jl-or-other-simple-mesh-generator/114404 "2024-05-17T16:05:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![marianoarnaiz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marianoarnaiz/32/19377_2.png) [@marianoarnaiz](https://discourse.julialang.org/u/marianoarnaiz)\
**Post date:** [May 17, 2024, 4:05pm UTC](https://discourse.julialang.org/t/2d-examples-of-distmesh-jl-or-other-simple-mesh-generator/114404/1 "2024-05-17T16:05:39Z")

</div>

Hi everyone.  
I am looking to generate some simple 2D meshes (triangles filling a big rectangle with some smaller square holes). I used for years the DistMesh for Matlab. Now I am trying to use the Julia port. There are several that do not seem to be updated or to have all the functionality (e.g. Distmesh2d.jl does not output the connectivity of the elements).  
I am looking for some examples of DistMesh.jl in 2D or other mesh generator.  
Any help?  
Kind regards.  
M.

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [May 17, 2024, 4:17pm UTC](https://discourse.julialang.org/t/2d-examples-of-distmesh-jl-or-other-simple-mesh-generator/114404/2 "2024-05-17T16:17:22Z")

</div>

Are you aware that Meshes.jl can discretize geometries like Box? Check the docs and search for `discretize` or `simplexify`

---

<div class="post-metadata">

**Author:** ![DanielVandH](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielvandh/32/31134_2.png) [@DanielVandH](https://discourse.julialang.org/u/DanielVandH)\
**Post date:** [May 17, 2024, 7:02pm UTC](https://discourse.julialang.org/t/2d-examples-of-distmesh-jl-or-other-simple-mesh-generator/114404/3 "2024-05-17T19:02:16Z")

</div>

DelaunayTriangulation.jl doesn’t work exactly the same as DistMesh.jl, but if you wanted to triangulate for example (as you say) a rectangle with holes, you could use it like

```julia
using DelaunayTriangulation, CairoMakie
outer = [(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0), (0.0, 0.0)]
inner_1 = [(0.2, 0.2), (0.2, 0.5), (0.5, 0.5), (0.5, 0.2), (0.2, 0.2)]
inner_2 = [(0.7, 0.2), (0.7, 0.5), (0.9, 0.5), (0.9, 0.2), (0.7, 0.2)]
boundary = [[outer], [inner_1], [inner_2]]
boundary_nodes, points = convert_boundary_points_to_indices(boundary)
tri = triangulate(points; boundary_nodes)

# Unrefined 
fig = Figure()
ax = Axis(fig[1, 1], width = 400, height = 400, title = "Unrefined")
triplot!(ax, tri)

# Refined 
refine!(tri; max_area = 0.01) # you can also do custom constraints with the custom_constraint keyword 
ax = Axis(fig[1, 2], width = 400, height = 400, title = "Unrefined")
triplot!(ax, tri)
resize_to_layout!(fig)
fig

```

 ![mXd8LkQ](https://global.discourse-cdn.com/julialang/original/3X/f/f/ff5fd5f380c6aa3f64da089f6a9825e41fa13e10.png)

The docs give plenty of examples of working with the `tri` output (e.g. working with the connectivities)
