pub struct Curve {
pub knots: Knots,
pub points: ControlPoints,
}
Expand description
Fields§
§knots: Knots
§points: ControlPoints
Implementations§
source§impl Curve
impl Curve
sourcepub fn new(knots: Knots, points: ControlPoints) -> Result<Self, CurveError>
pub fn new(knots: Knots, points: ControlPoints) -> Result<Self, CurveError>
Returns a B-Spline
§Arguments
degree
- The degree of the spline
§Examples
use nalgebra::{dmatrix, dvector};
use bsplines::curve::Curve;
use bsplines::curve::generation::{generate, Generation::Manual};
use bsplines::curve::knots;
use bsplines::curve::points::ControlPoints;
// Create a coordinate matrix containing with five 3D points.
let points = ControlPoints::new(dmatrix![
// 1 2 3 4 5
-2.0,-2.0,-1.0, 0.5, 1.5; // x
-1.0, 0.0, 1.0, 1.0, 2.0; // y
0.0, 0.5, 1.5,-0.5,-1.0; // z
]);
let degree = 2;
let knots = knots::methods::uniform(degree, points.segments()).unwrap();
let curve = Curve::new(knots, points).unwrap();
println!("{:?}", curve.evaluate(0.5));
pub fn degree(&self) -> usize
pub fn segments(&self) -> usize
pub fn evaluate(&self, u: f64) -> Result<VecD, CurveError>
pub fn evaluate_derivative(&self, u: f64, k: usize) -> Result<VecD, CurveError>
pub fn max_derivative(&self) -> usize
sourcepub fn prepend(&mut self, other: &Self) -> &mut Self
pub fn prepend(&mut self, other: &Self) -> &mut Self
Prepends another curve.
The end of another curve is attached to the beginning of this curve,
while maintaining continuity of all derivatives
This affects the first and last p
control points of the two curves, respectively,
and removes p
control points in total.
§Examples
use approx::relative_eq;
use nalgebra::dmatrix;
use bsplines::curve::Curve;
use bsplines::curve::generation::generate;
use bsplines::curve::generation::Generation::Manual;
use bsplines::curve::knots::Generation::Uniform;
use bsplines::curve::points::{ControlPoints, Points};
let mut a = generate(Manual {
degree: 2,
points: ControlPoints::new(dmatrix![ 1.0, 2.0, 3.0;]),
knots: Uniform,
}).unwrap();
let b = generate(Manual {
degree: 2,
points: ControlPoints::new(dmatrix![-3.0,-2.0,-1.0;]),
knots: Uniform,
}).unwrap();
let c = a.prepend(&b);
relative_eq!(c.points.matrix(), &dmatrix![-3.0,-2.0, 2.0, 3.0;], epsilon = f64::EPSILON);
sourcepub fn prepend_constrained(
&mut self,
constraints_self: Constraints,
other: &Self,
constraints_other: Constraints
) -> &mut Self
pub fn prepend_constrained( &mut self, constraints_self: Constraints, other: &Self, constraints_other: Constraints ) -> &mut Self
Prepends another curve with maximally p-1
constraints.
sourcepub fn append(&mut self, other: &Self) -> &mut Self
pub fn append(&mut self, other: &Self) -> &mut Self
Appends another curve.
The end of this curve is attached to the beginning of the other curve,
while maintaining continuity of all derivatives
This affects the first and last p
control points of the two curves, respectively,
and removes p
control points in total.
§Examples
use approx::relative_eq;
use nalgebra::dmatrix;
use bsplines::curve::Curve;
use bsplines::curve::generation::generate;
use bsplines::curve::generation::Generation::Manual;
use bsplines::curve::knots::Generation::Uniform;
use bsplines::curve::points::{ControlPoints, Points};
let mut a = generate(Manual {
degree: 2,
points: ControlPoints::new(dmatrix![-3.0,-2.0,-1.0;]),
knots: Uniform,
}).unwrap();
let b = generate(Manual {
degree: 2,
points: ControlPoints::new(dmatrix![ 1.0, 2.0, 3.0;]),
knots: Uniform,
}).unwrap();
let c = a.append(&b);
relative_eq!(c.points.matrix(), &dmatrix![-3.0,-2.0, 2.0, 3.0;], epsilon = f64::EPSILON);
sourcepub fn append_constrained(
&mut self,
constraints_self: Constraints,
other: &Self,
constraints_other: Constraints
) -> &mut Self
pub fn append_constrained( &mut self, constraints_self: Constraints, other: &Self, constraints_other: Constraints ) -> &mut Self
Appends another curve with maximally p-1
constraints.
sourcepub fn split(&self, u: f64) -> Result<(Self, Self), SplitError>
pub fn split(&self, u: f64) -> Result<(Self, Self), SplitError>
Splits a curve into two at parameter u
.
§Arguments
u
- The parameteru
that must lie in the interval(0,1)
.
sourcepub fn insert(&mut self, u: f64) -> Result<&mut Self, InsertError>
pub fn insert(&mut self, u: f64) -> Result<&mut Self, InsertError>
Inserts a knot into the curve at parameter u
.
§Arguments
u
- The parameteru
that must lie in the interval(0,1)
.
sourcepub fn insert_times(
&mut self,
u: f64,
x: usize
) -> Result<&mut Self, InsertError>
pub fn insert_times( &mut self, u: f64, x: usize ) -> Result<&mut Self, InsertError>
Inserts a knot x
times into the curve at parameter u
.
§Arguments
u
- The parameteru
that must lie in the interval(0,1)
.x
- The number of insertions of parameteru
.
sourcepub fn get_derivative_curve(&self, k: usize) -> Self
pub fn get_derivative_curve(&self, k: usize) -> Self
Trait Implementations§
Auto Trait Implementations§
impl RefUnwindSafe for Curve
impl Send for Curve
impl Sync for Curve
impl Unpin for Curve
impl UnwindSafe for Curve
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.