This repository contains a Rust implementation of B-Spline interpolation. The code demonstrates how to create a B-Spline curve using a set of control points and generate basis functions using the Cox-de Boor recursion formula.
- Create a B-Spline curve with a specified degree, knot vector, and control points
- Generate basis functions using the Cox-de Boor recursion formula
- Interpolate points along the B-Spline curve
- Plot the basis functions and the interpolated B-Spline curve
peroxide
: For plotting functionality & numerical utils
To use the B-Spline interpolation code in your Rust project, follow these steps:
- Add the necessary dependencies
cargo add peroxide --features plot
- Import the required modules in your Rust code:
use peroxide::fuga::*;
use anyhow::Result;
- Create an instance of the
BSpline
struct with the desired parameters:
let knots = vec![0f64, 0f64, 0f64, 0f64, 1f64, 2f64, 3f64, 3f64, 3f64, 3f64];
let degree = 3;
let num_points = 100;
let control_points = vec![
vec![0f64, 2f64],
vec![0.2, -1f64],
vec![0.4, 1f64],
vec![0.6, -1f64],
vec![0.8, 1f64],
vec![1f64, 2f64],
];
let spline = BSpline::new(degree, knots, num_points, control_points);
- Generate the basis functions and plot them:
let bases = spline.generate_bases();
spline.bases_plot(bases)?;
- Interpolate points along the B-Spline curve and plot the curve:
spline.plot()?;
The code generates two plots:
plot.png
: A plot of the basis functions generated using the Cox-de Boor recursion formula.
interpolate_plot.png
: A plot of the interpolated B-Spline curve using the provided control points.
This code is released under the MIT License.