packages

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 Delaunay

A 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.

nabi
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);
  • pub fn new(points: Matrix<f64>) throws (InterpError) -> Delaunay§

    Source

    The triangulation of the rows of points (n x 2). At least three points not on one line are needed; all on one line throws BadArgument (interpolate along the line with a 1-d method).

    nabi
    use 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);
    
  • pub fn len(self) -> usize§

    Source

    The number of triangles. For h hull vertices and v vertices in all (duplicates once), it is 2 v - h - 2.

    nabi
    use interpolate::scatter::Delaunay;
    use core::array::Matrix;
    
    let p: Matrix<f64> = [[0, 0], [1, 0], [0, 1]];
    assert((try Delaunay::new(p)).len() == 1);
    
  • pub fn simplices(self) -> Matrix<usize>§

    Source

    The triangles, one row of three point rows each, counterclockwise.

    nabi
    use 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);
    
  • pub fn neighbors(self) -> Matrix<i64>§

    Source

    For each triangle, the triangle across from each of its three vertices (in simplices order), -1 on the hull.

    nabi
    use 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);
    
  • pub fn hull(self) -> Vector<usize>§

    Source

    The convex hull's vertices, counterclockwise.

    nabi
    use 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);
    
  • pub fn points(self) -> Matrix<f64>§

    Source

    The input points, n x 2.

    nabi
    use interpolate::scatter::Delaunay;
    use core::array::Matrix;
    
    let p: Matrix<f64> = [[0, 0], [1, 0], [0, 1]];
    assert((try Delaunay::new(p)).points() == p);
    
  • pub fn find_simplex(self, p: Vector<f64>) -> usize?§

    Source

    The triangle (a row of simplices) holding p, or none outside the hull. A point on a shared edge gets one of the two.

    nabi
    use 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);
    
  • pub fn barycentric(self, t: usize, p: Vector<f64>) -> Vector<f64>§

    Source

    The barycentric coordinates of p in triangle t (a row of simplices), in its vertex order; they sum to 1 and all are in [0, 1] inside it.

    nabi
    use 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);