Struct truck_geometry::nurbs::BSplineCurve[][src]

pub struct BSplineCurve<P> { /* fields omitted */ }
Expand description

B-spline curve

Examples

use truck_geometry::*;

// the knot vector
let knot_vec = KnotVec::from(
    vec![0.0, 0.0, 0.0, 0.25, 0.25, 0.5, 0.5, 0.75, 0.75, 1.0, 1.0, 1.0]
);

// sign up the control points in the vector of all points
let ctrl_pts = vec![ // the vector of the indices of control points
    Vector4::new(0.0, -2.0, 0.0, 2.0),
    Vector4::new(1.0, -1.0, 0.0, 1.0),
    Vector4::new(1.0, 0.0, 0.0, 1.0),
    Vector4::new(1.0, 1.0, 0.0, 1.0),
    Vector4::new(0.0, 2.0, 0.0, 2.0),
    Vector4::new(-1.0, 1.0, 0.0, 1.0),
    Vector4::new(-1.0, 0.0, 0.0, 1.0),
    Vector4::new(-1.0, -1.0, 0.0, 1.0),
    Vector4::new(0.0, -2.0, 0.0, 2.0),
];

// construct the B-spline curve
let bspline = BSplineCurve::new(knot_vec, ctrl_pts);

// This B-spline curve is a nurbs representation of the unit circle.
const N : usize = 100; // sample size in test
for i in 0..N {
    let t = 1.0 / (N as f64) * (i as f64);
    let v = bspline.subs(t); // We can use the instances as a function.
    let c = (v[0] / v[3]).powi(2) + (v[1] / v[3]).powi(2);
    assert_near2!(c, 1.0);
}

Implementations

constructor.

Arguments
  • knot_vec - the knot vector
  • control_points - the vector of the control points
Panics

Panics occurs if:

  • There are no control points.
  • The number of knots is more than the one of control points.
  • The range of the knot vector is zero.

constructor.

Arguments
  • knot_vec - the knot vector
  • control_points - the vector of the control points
Failures

constructor.

Arguments
  • knot_vec - the knot vector
  • control_points - the vector of the control points
Remarks

This method is prepared only for performance-critical development and is not recommended.
This method does NOT check the rules for constructing B-spline curve.
The programmer must guarantee these conditions before using this method.

constructor.

Arguments
  • knot_vec - the knot vector
  • control_points - the vector of the control points
Remarks

This method checks the rules for constructing B-spline curve in the debug mode.
The programmer must guarantee these conditions before using this method.

Returns the reference of the knot vector

Returns the idxth knot

Returns the reference of the control points.

Returns the reference of the control point corresponding to the index idx.

Returns the mutable reference of the control point corresponding to index idx.

Returns the iterator on all control points

Apply the given transformation to all control points.

Returns the degree of B-spline curve

Examples
use truck_geometry::*;
let knot_vec = KnotVec::bezier_knot(2);
let ctrl_pts = vec![Vector2::new(1.0, 2.0), Vector2::new(2.0, 3.0), Vector2::new(3.0, 4.0)];
let bspcurve = BSplineCurve::new(knot_vec, ctrl_pts);
assert_eq!(bspcurve.degree(), 2);

Inverts a curve

Examples
use truck_geometry::*;
let knot_vec = KnotVec::uniform_knot(2, 2);
let ctrl_pts = vec![Vector2::new(1.0, 2.0), Vector2::new(2.0, 3.0), Vector2::new(3.0, 4.0), Vector2::new(4.0, 5.0)];
let bspcurve0 = BSplineCurve::new(knot_vec, ctrl_pts);
let mut bspcurve1 = bspcurve0.clone();
bspcurve1.invert();

const N: usize = 100; // sample size
for i in 0..=N {
    let t = (i as f64) / (N as f64);
    assert_near2!(bspcurve0.subs(t), bspcurve1.subs(1.0 - t));
}

Returns whether the knot vector is clamped or not.

Normalizes the knot vector

Translates the knot vector

Returns the closure of substitution.

Examples

The following test code is the same test with the one of BSplineCurve::subs().

use truck_geometry::*;
let knot_vec = KnotVec::from(vec![-1.0, -1.0, -1.0, 1.0, 1.0, 1.0]);
let ctrl_pts = vec![Vector2::new(-1.0, 1.0), Vector2::new(0.0, -1.0), Vector2::new(1.0, 1.0)];
let bspcurve = BSplineCurve::new(knot_vec, ctrl_pts);

const N: usize = 100; // sample size
let get_t = |i: usize| -1.0 + 2.0 * (i as f64) / (N as f64);
let res: Vec<_> = (0..=N).map(get_t).map(bspcurve.get_closure()).collect();
let ans: Vec<_> = (0..=N).map(get_t).map(|t| Vector2::new(t, t * t)).collect();
res.iter().zip(&ans).for_each(|(v0, v1)| assert_near2!(v0, v1));

Returns the derived B-spline curve.

Examples
use truck_geometry::*;
let knot_vec = KnotVec::bezier_knot(2);
let ctrl_pts = vec![Vector2::new(0.0, 0.0), Vector2::new(0.5, 0.0), Vector2::new(1.0, 1.0)];
let bspcurve = BSplineCurve::new(knot_vec, ctrl_pts);
let derived = bspcurve.derivation();

// `bpscurve = (t, t^2), derived = (1, 2t)`
const N : usize = 100; // sample size
for i in 0..=N {
    let t = 1.0 / (N as f64) * (i as f64);
    assert_near2!(derived.subs(t), Vector2::new(1.0, 2.0 * t));
}

Returns whether all control points are the same or not. If the knot vector is clamped, it means whether the curve is constant or not.

Examples
use truck_geometry::*;

let knot_vec = KnotVec::bezier_knot(2);
let pt = Vector2::new(1.0, 2.0);
let mut ctrl_pts = vec![pt.clone(), pt.clone(), pt.clone()];
let const_bspcurve = BSplineCurve::new(knot_vec.clone(), ctrl_pts.clone());
assert!(const_bspcurve.is_const());

ctrl_pts.push(Vector2::new(2.0, 3.0));
let bspcurve = BSplineCurve::new(knot_vec.clone(), ctrl_pts.clone());
assert!(!bspcurve.is_const());
Remarks

If the knot vector is not clamped and the BSpline basis function is not partition of unity, then perhaps returns true even if the curve is not constant.

use truck_geometry::*;
let knot_vec = KnotVec::uniform_knot(1, 5);
let ctrl_pts = vec![Vector2::new(1.0, 2.0), Vector2::new(1.0, 2.0)];
let bspcurve = BSplineCurve::new(knot_vec, ctrl_pts);

// bspcurve is not constant.
assert_eq!(bspcurve.subs(0.0), Vector2::new(0.0, 0.0));
assert_ne!(bspcurve.subs(0.5), Vector2::new(0.0, 0.0));

// bspcurve.is_const() is true
assert!(bspcurve.is_const());

Adds a knot x, and do not change self as a curve.

Examples
use truck_geometry::*;
let knot_vec = KnotVec::bezier_knot(2);
let ctrl_pts = vec![Vector2::new(-1.0, 1.0), Vector2::new(0.0, -1.0), Vector2::new(1.0, 1.0)];
let mut bspcurve = BSplineCurve::new(knot_vec, ctrl_pts);
let org_curve = bspcurve.clone();

// add 4 knots
bspcurve.add_knot(0.5).add_knot(0.5).add_knot(0.25).add_knot(0.75);
assert_eq!(bspcurve.knot_vec().len(), org_curve.knot_vec().len() + 4);
// bspcurve does not change as a curve
assert!(bspcurve.near2_as_curve(&org_curve));
Remarks

If the added knot x is out of the range of the knot vector, then the knot vector will extended.

use truck_geometry::*;
let knot_vec = KnotVec::bezier_knot(2);
let ctrl_pts = vec![Vector2::new(-1.0, 1.0), Vector2::new(0.0, -1.0), Vector2::new(1.0, 1.0)];
let mut bspcurve = BSplineCurve::new(knot_vec, ctrl_pts);
assert_eq!(bspcurve.knot_vec().range_length(), 1.0);
assert_eq!(bspcurve.front(), Vector2::new(-1.0, 1.0));
assert_eq!(bspcurve.back(), Vector2::new(1.0, 1.0));

// add knots out of the range of the knot vectors.
bspcurve.add_knot(-1.0).add_knot(2.0);
assert_eq!(bspcurve.knot_vec().range_length(), 3.0);
assert_eq!(bspcurve.front(), Vector2::new(0.0, 0.0));
assert_eq!(bspcurve.back(), Vector2::new(0.0, 0.0));

Removes a knot corresponding to the indices idx, and do not change self as a curve. If cannot remove the knot, do not change self and return self.

Examples
use truck_geometry::*;
let knot_vec = KnotVec::bezier_knot(2);
let ctrl_pts = vec![Vector2::new(-1.0, 1.0), Vector2::new(0.0, -1.0), Vector2::new(1.0, 1.0)];
let mut bspcurve = BSplineCurve::new(knot_vec, ctrl_pts);
let org_curve = bspcurve.clone();

// add knots and remove them.
bspcurve.add_knot(0.5).add_knot(0.5).add_knot(0.25).add_knot(0.75);
bspcurve.remove_knot(3).remove_knot(3).remove_knot(3).remove_knot(3);
assert!(bspcurve.near2_as_curve(&org_curve));
assert_eq!(bspcurve.knot_vec().len(), org_curve.knot_vec().len())

Removes a knot corresponding to the indice idx, and do not change self as a curve.
If the knot cannot be removed, returns Error::CannotRemoveKnot.

Examples
use truck_geometry::*;
use errors::Error;
let knot_vec = KnotVec::bezier_knot(2);
let ctrl_pts = vec![Vector2::new(-1.0, 1.0), Vector2::new(0.0, -1.0), Vector2::new(1.0, 1.0)];
let mut bspcurve = BSplineCurve::new(knot_vec, ctrl_pts);
let org_curve = bspcurve.clone();
bspcurve.add_knot(0.5).add_knot(0.5).add_knot(0.25).add_knot(0.75);
assert!(bspcurve.try_remove_knot(3).is_ok());
assert_eq!(bspcurve.try_remove_knot(2), Err(Error::CannotRemoveKnot(2)));

elevate 1 degree.

Examples
use truck_geometry::*;
let knot_vec = KnotVec::bezier_knot(1);
let ctrl_pts = vec![Vector2::new(0.0, 0.0), Vector2::new(1.0, 1.0)];
let mut bspcurve = BSplineCurve::new(knot_vec, ctrl_pts);
bspcurve.elevate_degree();
assert_eq!(bspcurve.degree(), 2);
assert_eq!(bspcurve.knot_vec(), &KnotVec::bezier_knot(2));
assert_eq!(bspcurve.control_point(1), &Vector2::new(0.5, 0.5));

Makes the B-spline curve clamped

Examples
use truck_geometry::*;
let knot_vec = KnotVec::from(vec![0.0, 1.0, 2.0, 3.0, 4.0, 5.0]);
let ctrl_pts = vec![Vector2::new(0.0, 1.0), Vector2::new(1.0, 2.0), Vector2::new(2.0, 3.0)];
let mut bspcurve = BSplineCurve::new(knot_vec, ctrl_pts);
assert!(!bspcurve.is_clamped());
bspcurve.clamp();
assert!(bspcurve.is_clamped());
assert_eq!(bspcurve.knot_vec().len(), 10);

Repeats Self::try_remove_knot() from the back knot in turn until the knot cannot be removed.

Examples
use truck_geometry::*;

let knot_vec = KnotVec::bezier_knot(2);
let ctrl_pts = vec![Vector2::new(1.0, 2.0), Vector2::new(2.0, 3.0), Vector2::new(3.0, 4.0)];
let mut bspcurve = BSplineCurve::new(knot_vec, ctrl_pts);
let org_curve = bspcurve.clone();

// add 4 new knots
bspcurve.add_knot(0.5).add_knot(0.5).add_knot(0.25).add_knot(0.75);
assert_eq!(bspcurve.knot_vec().len(), KnotVec::bezier_knot(2).len() + 4);

// By the optimization, added knots are removed.
bspcurve.optimize();
assert_eq!(bspcurve.knot_vec(), &KnotVec::bezier_knot(2));
assert!(bspcurve.near2_as_curve(&org_curve));

Makes two splines having the same degrees.

Examples
use truck_geometry::*;

let knot_vec0 = KnotVec::bezier_knot(1);
let ctrl_pts0 = vec![Vector2::new(1.0, 2.0), Vector2::new(2.0, 3.0)];
let mut bspcurve0 = BSplineCurve::new(knot_vec0, ctrl_pts0);
let knot_vec1 = KnotVec::bezier_knot(2);
let ctrl_pts1 = vec![Vector2::new(1.0, 2.0), Vector2::new(2.0, 3.0), Vector2::new(3.0, 4.0)];
let mut bspcurve1 = BSplineCurve::new(knot_vec1, ctrl_pts1);
assert_ne!(bspcurve0.degree(), bspcurve1.degree());

let org_curve0 = bspcurve0.clone();
let org_curve1 = bspcurve1.clone();
bspcurve0.syncro_degree(&mut bspcurve1);
assert_eq!(bspcurve0.degree(), bspcurve1.degree());
assert!(bspcurve0.near2_as_curve(&org_curve0));
assert!(bspcurve1.near2_as_curve(&org_curve1));

Makes two splines having the same normalized knot vectors.

Examples
use truck_geometry::*;

let knot_vec0 = KnotVec::from(vec![0.0, 0.0, 0.0, 0.5, 1.0, 1.0, 1.0]);
let ctrl_pts0 = vec![Vector2::new(0.0, 0.0), Vector2::new(1.0, 1.0), Vector2::new(2.0, 2.0), Vector2::new(3.0, 3.0)];
let mut bspcurve0 = BSplineCurve::new(knot_vec0, ctrl_pts0);
let mut org_curve0 = bspcurve0.clone();
let knot_vec1 = KnotVec::from(vec![0.0, 0.0, 1.0, 3.0, 4.0, 4.0]);
let ctrl_pts1 = vec![Vector2::new(0.0, 0.0), Vector2::new(1.0, 1.0), Vector2::new(2.0, 2.0), Vector2::new(3.0, 3.0)];
let mut bspcurve1 = BSplineCurve::new(knot_vec1, ctrl_pts1);
let mut org_curve1 = bspcurve1.clone();

bspcurve0.syncro_knots(&mut bspcurve1);

// The knot vectors are made the same.
assert_eq!(bspcurve0.knot_vec(), bspcurve1.knot_vec());
assert_eq!(
    bspcurve0.knot_vec().as_slice(),
    &[0.0, 0.0, 0.0, 0.25, 0.5, 0.75, 1.0, 1.0, 1.0]
);
// The degrees are not changed.
assert_eq!(bspcurve0.degree(), org_curve0.degree());
assert_eq!(bspcurve1.degree(), org_curve1.degree());
// The knot vector is normalized, however, the shape of curve is not changed.
assert!(bspcurve0.near2_as_curve(org_curve0.knot_normalize()));
assert!(bspcurve1.near2_as_curve(org_curve1.knot_normalize()));

Separates self into Bezier curves by each knots.

Examples
use truck_geometry::*;

let knot_vec = KnotVec::uniform_knot(2, 2);
let ctrl_pts = vec![Vector2::new(0.0, 1.0), Vector2::new(1.0, 2.0), Vector2::new(2.0, 3.0), Vector2::new(3.0, 4.0)];
let bspcurve = BSplineCurve::new(knot_vec, ctrl_pts);
let beziers = bspcurve.bezier_decomposition();

const N: usize = 100;
for i in 0..=N {
    let t = 0.5 * (i as f64) / (N as f64);
    assert_near2!(bspcurve.subs(t), beziers[0].subs(t));
}
for i in 0..=N {
    let t = 0.5 + 0.5 * (i as f64) / (N as f64);
    assert_near2!(bspcurve.subs(t), beziers[1].subs(t));
}

Makes the curve locally injective.

Example
use truck_geometry::*;
const N : usize = 100; // sample size for test

let knot_vec = KnotVec::from(
    vec![0.0, 0.0, 0.0, 1.0, 3.0, 4.0, 4.0, 4.0]
);
let ctrl_pts = vec![
    Vector3::new(1.0, 0.0, 0.0),
    Vector3::new(0.0, 1.0, 0.0),
    Vector3::new(0.0, 1.0, 0.0),
    Vector3::new(0.0, 1.0, 0.0),
    Vector3::new(0.0, 0.0, 1.0),
];

let mut bspcurve = BSplineCurve::new(knot_vec, ctrl_pts);
let mut flag = false;
for i in 0..=N {
    let t = 4.0 * (i as f64) / (N as f64);
    flag = flag || bspcurve.subs(t).near(&bspcurve.subs(t + 1.0 / (N as f64)));
}
// There exists t such that bspcurve(t) == bspcurve(t + 0.01).
assert!(flag);

bspcurve.make_locally_injective().knot_normalize();
let mut flag = false;
for i in 0..=N {
    let t = 1.0 * (i as f64) / (N as f64);
    flag = flag || bspcurve.subs(t).near(&bspcurve.subs(t + 1.0 / (N as f64)));
}
// There does not exist t such that bspcurve(t) == bspcurve(t + 0.01).
assert!(!flag);
Remarks

If self is a constant curve, then does nothing.

use truck_geometry::*;
let knot_vec = KnotVec::from(vec![0.0, 0.0, 0.0, 1.0, 2.0, 2.0, 2.0]);
let ctrl_pts = vec![Vector2::new(1.0, 1.0); 4];
let mut bspcurve = BSplineCurve::new(knot_vec, ctrl_pts);
let org_curve = bspcurve.clone();
bspcurve.make_locally_injective();
assert_eq!(bspcurve, org_curve);

Determine whether self and other is near as the B-spline curves or not.

Divides each knot interval into the number of degree equal parts, and check |self(t) - other(t)| < TOLERANCE for each end points t.

Examples
use truck_geometry::*;
let knot_vec = KnotVec::from(
    vec![0.0, 0.0, 0.0, 1.0, 2.0, 3.0, 4.0, 4.0, 4.0]
);
let ctrl_pts = vec![
    Vector2::new(1.0, 1.0),
    Vector2::new(3.0, 2.0),
    Vector2::new(2.0, 3.0),
    Vector2::new(4.0, 5.0),
    Vector2::new(5.0, 4.0),
    Vector2::new(1.0, 1.0),
];
let bspcurve0 = BSplineCurve::new(knot_vec, ctrl_pts);
let mut bspcurve1 = bspcurve0.clone();
assert!(bspcurve0.near_as_curve(&bspcurve1));
*bspcurve1.control_point_mut(1) += Vector2::new(0.01, 0.0002);
assert!(!bspcurve0.near_as_curve(&bspcurve1));

Determines self and other is near in square order as the B-spline curves or not.

Divide each knot interval into the number of degree equal parts, and check |self(t) - other(t)| < TOLERANCEfor each end points t.

Examples
use truck_geometry::*;
let eps = TOLERANCE;
let knot_vec = KnotVec::from(
    vec![0.0, 0.0, 0.0, 1.0, 2.0, 3.0, 4.0, 4.0, 4.0]
);
let ctrl_pts = vec![
    Vector2::new(1.0, 1.0),
    Vector2::new(3.0, 2.0),
    Vector2::new(2.0, 3.0),
    Vector2::new(4.0, 5.0),
    Vector2::new(5.0, 4.0),
    Vector2::new(1.0, 1.0),
];
let bspcurve0 = BSplineCurve::new(knot_vec, ctrl_pts);
let mut bspcurve1 = bspcurve0.clone();
assert!(bspcurve0.near_as_curve(&bspcurve1));
*bspcurve1.control_point_mut(1) += Vector2::new(eps, 0.0);
assert!(!bspcurve0.near2_as_curve(&bspcurve1));

Determines whether self is an arc of curve by repeating applying Newton method.

The parameter hint is the init value, required that curve.subs(hint) is the front point of self.

If self is an arc of curve, then returns Some(t) such that curve.subs(t) coincides with the back point of self. Otherwise, returns None.

Examples
use truck_geometry::*;
let knot_vec = KnotVec::from(
    vec![0.0, 0.0, 0.0, 1.0, 2.0, 3.0, 3.0, 3.0]
);
let ctrl_pts = vec![
    Point3::new(0.0, 0.0, 0.0),
    Point3::new(1.0, 0.0, 0.0),
    Point3::new(1.0, 1.0, 0.0),
    Point3::new(0.0, 1.0, 0.0),
    Point3::new(0.0, 1.0, 1.0),
];
let bspcurve = BSplineCurve::new(knot_vec, ctrl_pts);

let mut part = bspcurve.clone().cut(0.6);
part.cut(2.8);
let t = part.is_arc_of(&bspcurve, 0.6).unwrap();
assert_near!(t, 2.8);

// hint is required the init value.
assert!(part.is_arc_of(&bspcurve, 0.7).is_none());

// normal failure
*part.control_point_mut(2) += Vector3::new(1.0, 2.0, 3.0);
assert!(part.is_arc_of(&bspcurve, 0.6).is_none());

Returns the bounding box including all control points.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Concats two B-spline curves.

Examples
use truck_geometry::*;
Failure

If the back of the knot vector of self does not coincides with the front of the one of other,

use truck_geometry::*;
use truck_geotrait::traits::ConcatError;

let knot_vec0 = KnotVec::from(vec![0.0, 0.0, 1.0, 1.0]);
let ctrl_pts0 = vec![Vector2::new(0.0, 0.0), Vector2::new(1.0, 1.0)];
let mut bspcurve0 = BSplineCurve::new(knot_vec0, ctrl_pts0);
let knot_vec1 = KnotVec::from(vec![2.0, 2.0, 3.0, 3.0]);
let ctrl_pts1 = vec![Vector2::new(1.0, 1.0), Vector2::new(2.0, 2.0)];
let mut bspcurve1 = BSplineCurve::new(knot_vec1, ctrl_pts1);

assert_eq!(bspcurve0.try_concat(&mut bspcurve1), Err(ConcatError::DisconnectedParameters(1.0, 2.0)));

The result of concat two curves

Try concat two curves. Read more

Cuts one curve into two curves. Assigns the former curve to self and returns the later curve.

Formats the value using the given formatter. Read more

Deserialize this value from the given Serde deserializer. Read more

Performs the conversion.

Returns whether the curve curve is included in the surface self.

Returns whether the curve curve is included in the surface self.

Returns whether the curve curve is included in the surface self.

Returns whether the curve curve is included in the surface self.

Returns whether the curve curve is included in the surface self.

Returns whether the curve curve is included in the surface self.

Returns whether the curve curve is included in the surface self.

Returns whether the curve curve is included in the surface self.

Returns whether the curve curve is included in the surface self.

Inverts self

Returns the inverse.

The curve is in the space of Self::Point.

Creates the curve division (prameters, corresponding points). Read more

parameter range move by affine transformation Read more

parameter range move by affine transformation Read more

Makes the parameter range (0.0, 1.0).

Substitutes to B-spline curve.

Examples
use truck_geometry::*;
let knot_vec = KnotVec::from(vec![-1.0, -1.0, -1.0, 1.0, 1.0, 1.0]);
let ctrl_pts = vec![Vector2::new(-1.0, 1.0), Vector2::new(0.0, -1.0), Vector2::new(1.0, 1.0)];
let bspcurve = BSplineCurve::new(knot_vec, ctrl_pts);

// bspcurve coincides with (t, t * t) in the range [-1.0..1.0].
const N: usize = 100; // sample size
for i in 0..=N {
    let t = -1.0 + 2.0 * (i as f64) / (N as f64);
    assert_near2!(bspcurve.subs(t), Vector2::new(t, t * t));
}

Substitutes to the derived B-spline curve.

Examples
use truck_geometry::*;
let knot_vec = KnotVec::bezier_knot(2);
let ctrl_pts = vec![Vector2::new(0.0, 0.0), Vector2::new(0.5, 0.0), Vector2::new(1.0, 1.0)];
let bspcurve = BSplineCurve::new(knot_vec, ctrl_pts);

// `bpscurve = (t, t^2), derived = (1, 2t)`
const N : usize = 100; // sample size
for i in 0..=N {
    let t = 1.0 / (N as f64) * (i as f64);
    assert_near2!(bspcurve.der(t), Vector2::new(1.0, 2.0 * t));
}

Substitutes to the 2nd-ord derived B-spline curve.

Examples
use truck_geometry::*;
let knot_vec = KnotVec::bezier_knot(3);
let ctrl_pts = vec![
    Vector2::new(0.0, 0.0),
    Vector2::new(1.0, 1.0),
    Vector2::new(0.0, 1.0),
    Vector2::new(1.0, 0.0),
];
let bspcurve = BSplineCurve::new(knot_vec, ctrl_pts);

// bpscurve = (4t^3 - 6t^2 + 3t, -3t^2 + 3t), derived2 = (24t - 12, -6)
const N : usize = 100; // sample size
for i in 0..=N {
    let t = 1.0 / (N as f64) * (i as f64);
    assert_near2!(bspcurve.der2(t), Vector2::new(24.0 * t - 12.0, -6.0));
}

The curve is in the space of Self::Point.

The derivation vector of the curve.

The range of the parameter of the curve.

The front end point of the curve.

The back end point of the curve.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Searches the parameter t which minimize |self(t) - point| by Newton’s method with initial guess hint. Returns None if the number of attempts exceeds trial i.e. if trial == 0, then the trial is only one time.

Examples
use truck_geometry::*;
let knot_vec = KnotVec::from(
    vec![0.0, 0.0, 0.0, 1.0, 2.0, 3.0, 3.0, 3.0]
);
let ctrl_pts = vec![
    Point3::new(0.0, 0.0, 0.0),
    Point3::new(1.0, 0.0, 0.0),
    Point3::new(1.0, 1.0, 0.0),
    Point3::new(0.0, 1.0, 0.0),
    Point3::new(0.0, 1.0, 1.0),
];
let bspcurve = BSplineCurve::new(knot_vec, ctrl_pts);
let pt = ParametricCurve::subs(&bspcurve, 1.2);
let t = bspcurve.search_nearest_parameter(pt, Some(0.8), 100).unwrap();
assert_near!(t, 1.2);
Remarks

It may converge to a local solution depending on the hint.

use truck_geometry::*;
let knot_vec = KnotVec::from(
    vec![0.0, 0.0, 0.0, 1.0, 2.0, 3.0, 3.0, 3.0]
);
let ctrl_pts = vec![
    Point3::new(0.0, 0.0, 0.0),
    Point3::new(1.0, 0.0, 0.0),
    Point3::new(1.0, 1.0, 0.0),
    Point3::new(0.0, 1.0, 0.0),
    Point3::new(0.0, 1.0, 1.0),
];
let bspcurve = BSplineCurve::new(knot_vec, ctrl_pts);
let pt = Point3::new(0.0, 0.5, 1.0);
let t = bspcurve.search_nearest_parameter(pt, Some(0.8), 100).unwrap();
let pt0 = ParametricCurve::subs(&bspcurve, t);
let pt1 = ParametricCurve::subs(&bspcurve, 3.0);
// the point corresponding the obtained parameter is not
// the globally nearest point in the curve.
assert!((pt0 - pt).magnitude() > (pt1 - pt).magnitude());

point

curve => f64, surface => (f64, f64)

point

curve => f64, surface => (f64, f64)

Search parameter t such that self.subs(t) is near point.
Returns None if could not find such parameter. Read more

Serialize this value into the given Serde serializer. Read more

transform by trans.

transformed geometry by trans.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.