Delaunay.jl

Find the Delaunay triangulation for a set of points
Author eschnett
Popularity
19 Stars
Updated Last
8 Months Ago
Started In
July 2020

Delaunay / də lɔˈnɛ /: Find the Delaunay triangulation for a set of points

  • GitHub: Source code repository
  • GitHub CI

This package finds the Delaunay triangulation for a set of points in arbitrary dimensions. It uses the Python package scipy.spatial.Delaunay to perform the actual calculation.

This package is inspired by QHull.jl, which uses the same Python library.

Example in 2D

using Delaunay
points = rand(10, 2)
mesh = delaunay(points)

mesh.points                      # the points
mesh.simplices                   # the simplices (triangles in 2d)
mesh.neighbors                   # neighbouring simplices of a simplex
mesh.vertex_to_simplex           # find a simplex for a point
mesh.convex_hull                 # convex hull of the domain
mesh.vertex_neighbor_vertices    # neighbouring vertices of a vertex

using GLMakie # or CairoMakie/WGLMakie/RPRMakie
color = rand(size(mesh.points, 1))
fig, ax, pl = Makie.poly(mesh.points, mesh.simplices, color=color, strokewidth=2, figure=(resolution=(800, 400),))
points = randn(100, 2)
mesh = delaunay(points)
color = rand(size(mesh.points, 1))
poly(fig[1, 2], mesh.points, mesh.simplices, color=color, strokewidth=2)
save("delaunay2d.png", fig) 

delaunay2d

Example in 3D

using Delaunay
points = rand(100, 3)
mesh = delaunay(points)

using GeometryBasics
# Convert to tetrahedra faces
tetras = [GeometryBasics.TetrahedronFace(mesh.simplices[i, :]...) for i in 1:size(mesh.simplices, 1)]
points = Makie.to_vertices(mesh.points) # Use Makie to convert to Vector{Point3f}
m = GeometryBasics.Mesh(points, tetras) # create tetrahedra mesh
# Triangulate it, since Makie's mesh conversion currently doesn't handle tetrahedras itself 
tris = GeometryBasics.triangle_mesh(m)
fig, ax, pl = Makie.mesh(tris, color=rand(length(tris.position)), colormap=(:viridis, 0.5), transparency=true)
# add wireframe plot, which actually supports tetrahedras...
wireframe!(ax, m, color=:white, transparency=true)
save("delaunay3d.png", fig)

delaunay3d

The test cases contain also examples in higher dimensions.

Used By Packages