Visualize.Geo.Delaunay (Visualize v0.2.25)

Copy Markdown View Source

Delaunay triangulation for a set of points.

Computes the Delaunay triangulation, which connects points such that no point is inside the circumcircle of any triangle. This is useful for interpolation, mesh generation, and computing Voronoi diagrams.

The triangulation is built by incremental insertion (Bowyer–Watson) over ghost triangles that stand for the unbounded region beyond each hull edge, so no finite super-triangle can distort the hull. Every triangle is counter-clockwise, which is what makes the in-circle determinant's sign meaningful.

Examples

points = [{0, 0}, {100, 0}, {50, 100}, {25, 50}, {75, 50}]

delaunay = Visualize.Geo.Delaunay.new(points)

# Get triangles (each is [i, j, k] indices)
triangles = Visualize.Geo.Delaunay.triangles(delaunay)

# Find which triangle contains a point
i = Visualize.Geo.Delaunay.find(delaunay, {30, 30})

# Get neighbors of a point
neighbors = Visualize.Geo.Delaunay.neighbors(delaunay, 0)

Summary

Functions

Finds the triangle containing the given point, returns triangle index or -1

Returns the convex hull as point indices

Returns the indices of points neighboring the given point

Creates a new Delaunay triangulation from points.

Returns the points

Generates SVG path data for the convex hull

Generates SVG path data for all triangle edges

Returns the triangles as lists of point indices

Types

point()

@type point() :: {number(), number()}

t()

@type t() :: %Visualize.Geo.Delaunay{
  halfedges: [integer()],
  hull: [non_neg_integer()],
  points: [point()],
  triangles: [non_neg_integer()]
}

Functions

find(delaunay, arg)

@spec find(t(), point()) :: integer()

Finds the triangle containing the given point, returns triangle index or -1

hull(delaunay)

@spec hull(t()) :: [non_neg_integer()]

Returns the convex hull as point indices

neighbors(delaunay, point_index)

@spec neighbors(t(), non_neg_integer()) :: [non_neg_integer()]

Returns the indices of points neighboring the given point

new(points)

@spec new([point()]) :: t()

Creates a new Delaunay triangulation from points.

triangles holds three point indices per triangle, counter-clockwise; halfedges[e] is the index of the half-edge opposite half-edge e (3t + k runs from triangles[3t + k] to triangles[3t + (k + 1) rem 3]) or -1 on the hull; hull lists the convex hull counter-clockwise from the leftmost point. Coincident points after the first are left out of the triangulation.

points(delaunay)

@spec points(t()) :: [point()]

Returns the points

render_hull(delaunay)

@spec render_hull(t()) :: String.t()

Generates SVG path data for the convex hull

render_triangles(delaunay)

@spec render_triangles(t()) :: String.t()

Generates SVG path data for all triangle edges

triangles(delaunay)

@spec triangles(t()) :: [[non_neg_integer()]]

Returns the triangles as lists of point indices