interpolate::scatter::linear
Interpolants of scattered data: piecewise linear on the Delaunay triangulation (2-d) and nearest neighbor through a k-d tree (any d).
Structs
LinearNDSource
pub struct LinearNDPiecewise-linear interpolation of 2-d scattered data: inside each
Delaunay triangle the plane through its three values (barycentric
weights), so linear functions come back exactly (to rounding).
Outside the convex hull it gives fill (NaN unless set). A query
finds its triangle by a walk that starts at the triangle of the
nearest vertex (k-d tree), O(log n) per point.
use interpolate::scatter::LinearND;
use core::array::Matrix;
let p: Matrix<f64> = [[0, 0], [1, 0], [0, 1], [1, 1]];
let f = try LinearND::new(p, [0, 1, 2, 3]); // 1 x + 2 y
assert((f([0.5, 0.25]) - 1.0).abs() < 1e-15);
assert(f([2.0, 0.0]).is_nan());
assert(f.fill(0.0).at([2.0, 0.0]) == 0.0);
Sourcepub fn new(§points: Matrix<f64>, values: Vector<f64>) throws (InterpError) -> LinearND The interpolant of
values[i]at rowiofpoints(n x 2).nabiuse interpolate::scatter::LinearND; use core::array::Matrix; let p: Matrix<f64> = [[0, 0], [2, 0], [0, 2]]; assert((try LinearND::new(p, [1, 1, 1])).at([0.5, 0.5]) == 1.0);This interpolant giving
voutside the convex hull.nabiuse interpolate::scatter::LinearND; use core::array::Matrix; let p: Matrix<f64> = [[0, 0], [1, 0], [0, 1]]; assert((try LinearND::new(p, [1, 2, 3])).fill(-1.0).at([5.0, 5.0]) == -1.0);The triangulation underneath.
nabiuse interpolate::scatter::LinearND; use core::array::Matrix; let p: Matrix<f64> = [[0, 0], [1, 0], [0, 1]]; assert((try LinearND::new(p, [1, 2, 3])).triangulation().len() == 1);The value at
p(two coordinates).nabiuse interpolate::scatter::LinearND; use core::array::Matrix; let p: Matrix<f64> = [[0, 0], [1, 0], [0, 1]]; assert((try LinearND::new(p, [0, 1, 1])).at([0.5, 0.5]) == 1.0);
Sourcepub fn eval(§self, ps: Matrix<f64>) throws (InterpError) -> Vector<f64> The value at every row of
ps(m x 2). Each walk starts from the previous answer, so nearby rows in order cost O(1) each.nabiuse interpolate::scatter::LinearND; use core::array::Matrix; let p: Matrix<f64> = [[0, 0], [1, 0], [0, 1]]; let q: Matrix<f64> = [[0.1, 0.1], [0.2, 0.3]]; let v = try (try LinearND::new(p, [0, 1, 0])).eval(q); assert((v[1] - 0.2).abs() < 1e-15);
Trait implementations 1
impl ops::Call<Vector<f64>> for LinearND
NearestNDSource
pub struct NearestNDNearest-neighbor interpolation in any dimension: the value of the closest data point (the lowest row among equally close ones), found with a k-d tree.
use interpolate::scatter::NearestND;
use core::array::Matrix;
let p: Matrix<f64> = [[0, 0, 0], [1, 1, 1]];
let f = try NearestND::new(p, [10, 20]);
assert(f([0.9, 0.8, 0.7]) == 20.0);
Sourcepub fn new(§points: Matrix<f64>, values: Vector<f64>) throws (InterpError) -> NearestND The interpolant of
values[i]at rowiofpoints(n x d, n >= 1).nabiuse interpolate::scatter::NearestND; use core::array::Matrix; let p: Matrix<f64> = [[0], [1]]; assert((try NearestND::new(p, [5, 6])).at([0.4]) == 5.0);The value at
p; NaN whenphas the wrong length or is not finite.nabiuse interpolate::scatter::NearestND; use core::array::Matrix; let p: Matrix<f64> = [[0, 0], [4, 0]]; assert((try NearestND::new(p, [1, 2])).at([3.0, 9.0]) == 2.0);
Sourcepub fn eval(§self, ps: Matrix<f64>) throws (InterpError) -> Vector<f64> The value at every row of
ps(m x d), in parallel for large m.nabiuse interpolate::scatter::NearestND; use core::array::{Matrix, Vector}; let p: Matrix<f64> = [[0], [1], [2]]; let q: Matrix<f64> = [[0.2], [1.9]]; assert(try (try NearestND::new(p, [7, 8, 9])).eval(q) == Vector::<f64>::from([7.0, 9.0]));
Trait implementations 1
impl ops::Call<Vector<f64>> for NearestND
Enums
MethodSource
pub enum MethodHow griddata interpolates.
use interpolate::scatter::Method;
assert(Method::Linear != Method::Nearest);
LinearND: barycentric on the Delaunay triangles (2-d only).NearestND: the closest data point (any d).
Functions
griddataSource
pub fn griddata(points: Matrix<f64>, values: Vector<f64>, xi: Matrix<f64>, method: Method = Method::Linear) throws (InterpError) -> Vector<f64> The data values at points (n x d) interpolated at the rows of
xi (m x d), in one call: LinearND (NaN outside the hull) or
NearestND.
use interpolate::scatter::{Method, griddata};
use core::array::Matrix;
let p: Matrix<f64> = [[0, 0], [1, 0], [0, 1], [1, 1]];
let q: Matrix<f64> = [[0.5, 0.5]];
let v = try griddata(p, [0, 1, 1, 2], q, Method::Linear);
assert((v[0] - 1.0).abs() < 1e-15);