Struct bsplines::curve::Curve

source ·
pub struct Curve {
    pub knots: Knots,
    pub points: ControlPoints,
}
Expand description

Fields§

§knots: Knots§points: ControlPoints

Implementations§

source§

impl Curve

source

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));
source

pub fn degree(&self) -> usize

source

pub fn segments(&self) -> usize

source

pub fn dimension(&self) -> usize

Returns the dimension of the curve.

source

pub fn evaluate(&self, u: f64) -> Result<VecD, CurveError>

source

pub fn evaluate_derivative(&self, u: f64, k: usize) -> Result<VecD, CurveError>

source

pub fn max_derivative(&self) -> usize

source

pub fn reverse(&mut self) -> &mut Self

Reverses the curve.

source

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);
source

pub fn prepend_constrained( &mut self, constraints_self: Constraints, other: &Self, constraints_other: Constraints ) -> &mut Self

Prepends another curve with maximally p-1 constraints.

source

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);
source

pub fn append_constrained( &mut self, constraints_self: Constraints, other: &Self, constraints_other: Constraints ) -> &mut Self

Appends another curve with maximally p-1 constraints.

source

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).
source

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).
source

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 parameter u.
source

pub fn get_derivative_curve(&self, k: usize) -> Self

Returns the curve describing the k-th derivative of the current one.

§Arguments
  • k - The derivative

Trait Implementations§

source§

impl Clone for Curve

source§

fn clone(&self) -> Curve

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Curve

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.