interpolate::scatter::delaunay
On this page
The 2-d Delaunay triangulation by a radial sweep and edge flips (Mapbox's Delaunator, after Sinclair's S-hull): seed with the smallest circumcircle near the center, add the points by distance from it, each to the visible part of the convex hull, and flip every new edge that fails the empty-circle test. Orientation and in-circle tests are exact (Shewchuk), so cocircular sets (grids) come out consistent and every flip loop ends. O(n log n) expected.
Structs
DelaunaySource
pub struct DelaunayA Delaunay triangulation of points in the plane: no point lies strictly inside the circumcircle of any triangle. Repeated points are kept once (the first in sweep order); triangles turn counterclockwise.
use interpolate::scatter::Delaunay;
use core::array::Matrix;
let p: Matrix<f64> = [[0, 0], [1, 0], [0, 1], [1, 1]];
let d = try Delaunay::new(p);
assert(d.len() == 2 && d.hull().len() == 4);
assert(d.find_simplex([0.2, 0.2]) != none);
assert(d.find_simplex([2.0, 2.0]) == none);
Sourcepub fn new(§points: Matrix<f64>) throws (InterpError) -> Delaunay The triangulation of the rows of
points(n x 2). At least three points not on one line are needed; all on one line throwsBadArgument(interpolate along the line with a 1-d method).nabiuse interpolate::scatter::Delaunay; use core::array::Matrix; let p: Matrix<f64> = [[0, 0], [2, 0], [1, 2], [1, 0.5]]; assert((try Delaunay::new(p)).len() == 3);The number of triangles. For h hull vertices and v vertices in all (duplicates once), it is 2 v - h - 2.
nabiuse interpolate::scatter::Delaunay; use core::array::Matrix; let p: Matrix<f64> = [[0, 0], [1, 0], [0, 1]]; assert((try Delaunay::new(p)).len() == 1);The triangles, one row of three point rows each, counterclockwise.
nabiuse interpolate::scatter::Delaunay; use core::array::Matrix; let p: Matrix<f64> = [[0, 0], [1, 0], [0, 1]]; let t = (try Delaunay::new(p)).simplices(); assert(t.shape() == [1, 3] && t[0, 0] + t[0, 1] + t[0, 2] == 3);For each triangle, the triangle across from each of its three vertices (in
simplicesorder), -1 on the hull.nabiuse interpolate::scatter::Delaunay; use core::array::Matrix; let p: Matrix<f64> = [[0, 0], [1, 0], [0, 1], [1, 1]]; let nb = (try Delaunay::new(p)).neighbors(); assert(nb.shape() == [2, 3] && nb[0, 0] + nb[0, 1] + nb[0, 2] == -1);The convex hull's vertices, counterclockwise.
nabiuse interpolate::scatter::Delaunay; use core::array::Matrix; let p: Matrix<f64> = [[0, 0], [2, 0], [1, 2], [1, 0.5]]; assert((try Delaunay::new(p)).hull().len() == 3);The input points, n x 2.
nabiuse interpolate::scatter::Delaunay; use core::array::Matrix; let p: Matrix<f64> = [[0, 0], [1, 0], [0, 1]]; assert((try Delaunay::new(p)).points() == p);The triangle (a row of
simplices) holdingp, ornoneoutside the hull. A point on a shared edge gets one of the two.nabiuse interpolate::scatter::Delaunay; use core::array::Matrix; let p: Matrix<f64> = [[0, 0], [1, 0], [0, 1]]; assert((try Delaunay::new(p)).find_simplex([0.25, 0.25]) == 0);The barycentric coordinates of
pin trianglet(a row ofsimplices), in its vertex order; they sum to 1 and all are in [0, 1] inside it.nabiuse interpolate::scatter::Delaunay; use core::array::Matrix; let p: Matrix<f64> = [[0, 0], [1, 0], [0, 1]]; let d = try Delaunay::new(p); let w = d.barycentric(0, [0.25, 0.5]); assert((w[0] + w[1] + w[2] - 1.0).abs() < 1e-15);