inverse_distance_weight

Crates.ioinverse_distance_weight
lib.rsinverse_distance_weight
version0.1.1
sourcesrc
created_at2023-09-09 10:13:39.575689
updated_at2023-09-09 10:18:28.262686
descriptionInverse Distance Weighting (IDW) algorithm for spatial interpolation.
homepagehttps://github.com/fralonra/inverse_distance_weight
repositoryhttps://github.com/fralonra/inverse_distance_weight
max_upload_size
id968061
size17,306
fralonra (fralonra)

documentation

README

inverse_distance_weight

Latest version Documentation MIT

An implementation of the Inverse Distance Weighting (IDW) algorithm.

The crate supports points of 1 to 3 dimension to perform the interpolation.

The weighted function used in the algorithm is weightᵢ = 1 / distance(pointᵢ, position)ᵖ.

Examples

use inverse_distance_weight::IDW;

// 1 dimension
let points = vec![0.0, 1.0];
let values = vec![0.0, 1.0];
let idw = IDW::new(points, values);

let result = idw.evaluate(0.5);

// 2 dimension
let points = vec![(0.0, 0.0), (1.0, 1.0)];
let values = vec![0.0, 1.0];
let idw = IDW::new(points, values);

let result = idw.evaluate((0.5, 0.5));

// 3 dimension
let points = vec![(0.0, 0.0, 0.0), (1.0, 1.0, 1.0)];
let values = vec![0.0, 1.0];
let idw = IDW::new(points, values);

let result = idw.evaluate((0.5, 0.5, 0.5));

// Customize
let points = vec![0.0, 1.0];
let values = vec![0.0, 1.0];
let idw = IDW::new(points, values)
    // Sets a power parameter. Default is 2.
    .power(0.5)
    // Sets a transform function for weights.
    .weighted_function(|weight| (1.0 + (4.0 * std::f64::consts::PI * weight).sin()) * 0.5);
Commit count: 8

cargo fmt