|
1 | 1 | # rbf-interpolation |
2 | | -Radial basis function interpolation in Rust using nalgebra |
| 2 | +Radial basis function interpolation in Rust using nalgebra. Uses nightly rust in order to keep all matrix sizes known at compile time. |
| 3 | + |
| 4 | +# Example |
| 5 | +```rs |
| 6 | +use gnuplot::{AutoOption::Auto, AxesCommon, Figure, HELIX}; |
| 7 | +use nalgebra::{Matrix, SMatrix, SVector, Vector2}; |
| 8 | +use rbf_interpolation::builder::RBFInterpolatorBuilder; |
| 9 | + |
| 10 | +fn main() { |
| 11 | + let points: SMatrix<f64, 2, 5> = Matrix::from_columns(&[ |
| 12 | + Vector2::new(2.0, 2.0), |
| 13 | + Vector2::new(3.0, 4.0), |
| 14 | + Vector2::new(6.0, 4.0), |
| 15 | + Vector2::new(1.0, 1.0), |
| 16 | + Vector2::new(7.0, 7.0), |
| 17 | + ]); |
| 18 | + let values = SVector::<f64, 5>::new(2.0, 6.0, 4.0, 4.0, 5.0); |
| 19 | + |
| 20 | + let interpolant = RBFInterpolatorBuilder::<1, 3, 5, 2>::ThinPlateSpline |
| 21 | + .build(points.clone(), values.clone()) |
| 22 | + .unwrap(); |
| 23 | + |
| 24 | + //15x15 with 0.1 resolution |
| 25 | + let mut surface = Vec::with_capacity(150*150); |
| 26 | + for i in 0..150 { |
| 27 | + for j in 0..150 { |
| 28 | + surface.push(interpolant.interpolate(&Vector2::new(i as f64 / 10.0, j as f64 / 10.0))); |
| 29 | + } |
| 30 | + } |
| 31 | + |
| 32 | + let mut points = points.row_iter(); |
| 33 | + |
| 34 | + let mut fg = Figure::new(); |
| 35 | + fg.axes3d() |
| 36 | + .set_title("Thin plate spline, 1 degree polynomial", &[]) |
| 37 | + .surface(surface, 150, 150, Some((0.0, 0.0, 15.0, 15.0)), &[]) |
| 38 | + .points(points.next().unwrap(), points.next().unwrap(), values.iter(), &[]) |
| 39 | + .set_x_label("X", &[]) |
| 40 | + .set_y_label("Y", &[]) |
| 41 | + .set_z_label("Z", &[]) |
| 42 | + .set_z_range(Auto, Auto) |
| 43 | + .set_palette(HELIX) |
| 44 | + .set_view(45.0, 175.0); |
| 45 | + fg.show().unwrap(); |
| 46 | +} |
| 47 | +``` |
0 commit comments