@Br0BOLE the Delaunay triangulation takes a set of points as input and a set of indices of points marking the boundary. By default we only use the boundary points of polygons, leading to the triangles illustrated above.
If you need triangles with better angles, you can insert more points in the list. Below is a helper function that samples points inside the polygonal area according to a minimum distance, and then calls the underlying Delaunay routine to create the mesh:
using Meshes
using Unitful
import DelaunayTriangulation as DT
# alpha is the minimum distance between points
function mydiscretize(poly::Polygon, α=0.05)
verts = map(rings(poly)) do ring
collect(eachvertex(ring))
end
offset = 0
bverts = [[Int[]] for _ in 1:length(verts)]
for i in 1:length(verts)
nverts = length(verts[i])
bverts[i][1] = [(offset + 1):(offset + nverts); (offset + 1)]
offset += nverts
end
points1 = reduce(vcat, verts)
points2 = sample(poly, MinDistanceSampling(α)) |> collect
points = [points1; points2]
coords = map(p -> ustrip.(to(p)), points)
triang = DT.triangulate(coords, boundary_nodes=bverts)
connec = connect.(DT.each_solid_triangle(triang))
SimpleMesh(points, connec)
end
m = mydiscretize(p, 0.05)
viz(m, showsegments=true)
This function is a workaround. We will try to find the time to incorporate this function into our Meshes.jl machinery to faciliate the lives of end-users.
The downside of the above implementation is that it relies on another discretization of the geometry to sample points in the interior. We can do better with primitive geometries like balls, sphere, etc.
I ran the example with the same polygon p of my previous comment above.
