Crates.io | bspline |
lib.rs | bspline |
version | 1.1.0 |
source | src |
created_at | 2015-10-09 05:50:30.371776 |
updated_at | 2022-02-11 04:37:25.580164 |
description | A simple generic library for computing B-splines |
homepage | https://github.com/Twinklebear/bspline |
repository | https://github.com/Twinklebear/bspline |
max_upload_size | |
id | 3179 |
size | 67,370 |
A library for computing B-spline interpolating curves on generic control points. bspline can be used to evaluate B-splines of varying orders on any type that can be linearly interpolated, ranging from floats, positions, RGB colors to transformation matrices and so on.
The bspline logo was generated using this library with a cubic B-spline in 2D for the positioning of the curve and a quadratic B-spline in RGB space to color it (check out the logo example!). Other much simpler examples of 1D and 2D quadratic, cubic and quartic B-splines can also be found in the examples.
Just grab the crate on crates.io and you're set!
Rust doc can be found here.
This example shows how to create the 1D cardinal cubic B-spline example shown on Wikipedia's B-splines page. For examples of evaluating the spline to an image and saving the output see the examples.
let points = vec![0.0, 0.0, 0.0, 6.0, 0.0, 0.0, 0.0]
let knots = vec![-2.0, -2.0, -2.0, -2.0, -1.0, 0.0, 1.0, 2.0, 2.0, 2.0, 2.0];
let degree = 3;
let spline = bspline::BSpline::new(degree, points, knots);
The library assumes you are familiar at some level with how B-splines work, e.g. how control points and knots and effect the curve produced. No interactive editor is provided (at least currently). Some good places to start reading about B-splines to effectively use this library can be found below.
nalgerba is one of the most popular linear algbera packages for Rust. To make this create compatible with it, you need to enable the nalgebra-support
feature and then you can recreate the above example:
use nalgebra as na;
let points = na::DVector::from(vec![0.0, 0.0, 0.0, 6.0, 0.0, 0.0, 0.0])
let knots = na::DVector::from(vec![-2.0, -2.0, -2.0, -2.0, -1.0, 0.0, 1.0, 2.0, 2.0, 2.0, 2.0]);
let degree = 3;
let spline = bspline::BSpline::new(degree, points, knots);