This code demonstrates the implementation and visualization of uniform cubic B-spline basis functions using the Rust programming language and the Peroxide library.
The code defines two main structures:
-
CubicBasis
: Represents a unit cubic basis function from the Irwin-Hall distribution (n=4). It is used to evaluate the basis function at a given point within a specified interval. -
CubicBSpline
: Represents a set of uniform cubic B-spline basis functions. It is constructed by dividing a given interval into a specified number of basis functions.
The main
function demonstrates the usage of the CubicBSpline
structure. It creates a set of cubic B-spline basis functions by dividing the interval (0, 1) into 5 basis functions. It then evaluates the basis functions and the overall spline at 1000 equally spaced points within the interval.
The resulting values are plotted using the Peroxide library, and the plot is saved as an image file named "plot.png".
To run the code, ensure that you have Rust and the necessary dependencies installed. The code requires the following dependencies:
You can add the dependencies by running the following command:
cargo add peroxide --features plot
Then, you can run the code using the following command:
cargo run --release
The code will generate a plot of the cubic B-spline basis functions and save it as "plot.png" in the current directory.