pub struct NURBSCurve<V>(_);
Expand description

NURBS curve

Implementations§

Constructs the rationalized B-spline curve.

Returns the BSpline curve before rationalized.

Returns the BSpline curve before rationalized.

Returns the reference of the knot vector.
cf.BSplineCurve::knot_vec

Returns the idxth knot.
cf.BSplineCurve::knot

Returns the reference of the control points.
cf.BSplineCurve::control_points

Returns the reference of the control point corresponding to the index idx.
cf.BSplineCurve::control_point

Returns the mutable reference of the control point corresponding to index idx.
cf.BSplineCurve::control_point_mut

Returns the iterator on all control points
cf.BSplineCurve::control_points_mut

Apply the given transformation to all control points.
cf.BSplineCurve::transform_control_points

Returns the degree of NURBS curve.
cf.BSplineCurve::degree

Inverts a curve.
cf.BSplineCurve::invert

Returns whether the knot vector is clamped or not.
cf.BSplineCurve::is_clamped

Normalizes the knot vector.
cf.BSplineCurve::knot_normalize

Translates the knot vector.
cf.BSplineCurve::knot_translate

Constructs a rationalization curve from the curves and weights.

Failures

the length of curve.control_points() and weights must be the same.

Returns the closure of substitution.

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 = Vector3::new(1.0, 2.0, 1.0);
// allows differences upto scalars
let mut ctrl_pts = vec![pt.clone(), pt.clone() * 2.0, pt.clone() * 3.0];
let bspcurve = BSplineCurve::new(knot_vec.clone(), ctrl_pts.clone());
assert!(!bspcurve.is_const());
let const_curve = NURBSCurve::new(bspcurve);
assert!(const_curve.is_const());

ctrl_pts.push(Vector3::new(2.0, 3.0, 1.0));
let curve = NURBSCurve::new(BSplineCurve::new(knot_vec.clone(), ctrl_pts.clone()));
assert!(!curve.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());

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![
    Vector3::new(1.0, 1.0, 1.0),
    Vector3::new(3.0, 2.0, 2.0),
    Vector3::new(2.0, 3.0, 1.0),
    Vector3::new(4.0, 5.0, 2.0),
    Vector3::new(5.0, 4.0, 1.0),
    Vector3::new(1.0, 1.0, 2.0),
];
let curve0 = NURBSCurve::new(BSplineCurve::new(knot_vec, ctrl_pts));
let mut curve1 = curve0.clone();
assert!(curve0.near_as_curve(&curve1));
*curve1.control_point_mut(1) += Vector3::new(0.01, 0.0002, 0.0);
assert!(!curve0.near_as_curve(&curve1));

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 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![
    Vector3::new(1.0, 1.0, 1.0),
    Vector3::new(3.0, 2.0, 2.0),
    Vector3::new(2.0, 3.0, 1.0),
    Vector3::new(4.0, 5.0, 2.0),
    Vector3::new(5.0, 4.0, 1.0),
    Vector3::new(1.0, 1.0, 2.0),
];
let curve0 = NURBSCurve::new(BSplineCurve::new(knot_vec, ctrl_pts));
let mut curve1 = curve0.clone();
assert!(curve0.near_as_curve(&curve1));
*curve1.control_point_mut(1) += Vector3::new(0.01, TOLERANCE, 0.0);
assert!(!curve0.near2_as_curve(&curve1));

Adds a knot x, and do not change self as a curve.
cf.BSplineCurve::add_knot

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.
cf.BSplineCurve::remove_knot

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.
cf.BSplineCurve::try_remove_knot

Elevates 1 degree.
cf.BSplineCurve::elevate_degree

Makes the NURBS curve clamped
cf.BSplineCurve::clamp

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

Makes two splines having the same degrees.
cf.BSplineCurve::syncro_degree

Makes two splines having the same normalized knot vectors.
cf.BSplineCurve::syncro_knots

Makes the rational 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 control_points = vec![
    Vector4::new(1.0, 0.0, 0.0, 1.0),
    Vector4::new(0.0, 1.0, 0.0, 1.0),
    Vector4::new(0.0, 2.0, 0.0, 2.0),
    Vector4::new(0.0, 3.0, 0.0, 3.0),
    Vector4::new(0.0, 0.0, 3.0, 3.0),
];

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

curve.make_locally_injective().knot_normalize();
let mut flag = false;
for i in 0..N {
    let t = 1.0 * (i as f64) / (N as f64);
    let pt0 = curve.subs(t);
    let pt1 = curve.subs(t + 1.0 / (N as f64));
    flag = flag || pt0.near(&pt1);
}
// 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![
    Vector3::new(1.0, 1.0, 1.0),
    Vector3::new(2.0, 2.0, 2.0),
    Vector3::new(3.0, 3.0, 3.0),
    Vector3::new(4.0, 4.0, 4.0),
];
let mut curve = NURBSCurve::new(BSplineCurve::new(knot_vec, ctrl_pts));
let org_curve = curve.clone();
curve.make_locally_injective();
assert_eq!(curve, org_curve);

Returns the bounding box including all control points.

Trait Implementations§

The range of the parameter of the curve.
The front end point of the curve.
The back end point of the curve.
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
The result of concat two curves
Try concat two curves. Read more
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
Converts to this type from the input type.
Converts to this type from the input type.
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 (parameters, 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).
The curve is in the space of Self::Point.
The derivation vector of the curve.
Substitutes the parameter t.
Returns the derivation.
Returns the 2nd-order derivation.
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

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::*;

// Defines the half unit circle in x > 0.
let knot_vec = KnotVec::bezier_knot(2);
let ctrl_pts = vec![Vector3::new(0.0, -1.0, 1.0), Vector3::new(1.0, 0.0, 0.0), Vector3::new(0.0, 1.0, 1.0)];
let curve = NURBSCurve::new(BSplineCurve::new(knot_vec, ctrl_pts));

// search rational nearest parameter
let pt = Point2::new(1.0, 2.0);
let hint = 0.8;
let t = curve.search_nearest_parameter(pt, Some(hint), 100).unwrap();

// check the answer
let res = curve.subs(t);
let ans = Point2::from_vec(pt.to_vec().normalize());
assert_near!(res, ans);
Remarks

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

use truck_geometry::*;

// Same curve and point as above example
let knot_vec = KnotVec::bezier_knot(2);
let ctrl_pts = vec![Vector3::new(0.0, -1.0, 1.0), Vector3::new(1.0, 0.0, 0.0), Vector3::new(0.0, 1.0, 1.0)];
let curve = NURBSCurve::new(BSplineCurve::new(knot_vec, ctrl_pts));
let pt = Point2::new(1.0, 2.0);

// another hint
let hint = 0.5;

// Newton's method is vibration divergent.
assert!(curve.search_nearest_parameter(pt, Some(hint), 100).is_none());
point
point
Search parameter t such that self.subs(t) is near point.
Returns None if could not find such parameter.
Serialize this value into the given Serde serializer. Read more
transform by trans.
transformed geometry by trans.
The type returned in the event of a conversion error.
Performs the conversion.

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

Returns the argument unchanged.

Calls U::from(self).

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

The alignment of pointer.
The type for initializers.
Initializes a with the given initializer. Read more
Dereferences the given pointer. Read more
Mutably dereferences the given pointer. Read more
Drops the object pointed to by the given pointer. Read more
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
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.