Struct truck_modeling::geometry::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 vectorcontrol_points
- the vector of the control points
Failures
- If there are no control points, returns
Error::EmptyControlPoint<f64>s
. - If the number of knots is more than the one of control points, returns
Error::TooShortKnotVector
. - If the range of the knot vector is zero, returns
Error::ZeroRange
.
pub const fn new_unchecked(
knot_vec: KnotVec,
control_points: Vec<P, Global>
) -> BSplineCurve<P>
pub const fn new_unchecked(
knot_vec: KnotVec,
control_points: Vec<P, Global>
) -> BSplineCurve<P>
constructor.
Arguments
knot_vec
- the knot vectorcontrol_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.
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)| < TOLERANCE
for 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));
impl<P> BSplineCurve<P> where
P: Tolerance + ControlPoint<f64> + EuclideanSpace<Scalar = f64, Diff = <P as ControlPoint<f64>>::Diff> + MetricSpace<Metric = f64>,
<P as ControlPoint<f64>>::Diff: InnerSpace,
<P as ControlPoint<f64>>::Diff: Tolerance,
<<P as ControlPoint<f64>>::Diff as VectorSpace>::Scalar == f64,
impl<P> BSplineCurve<P> where
P: Tolerance + ControlPoint<f64> + EuclideanSpace<Scalar = f64, Diff = <P as ControlPoint<f64>>::Diff> + MetricSpace<Metric = f64>,
<P as ControlPoint<f64>>::Diff: InnerSpace,
<P as ControlPoint<f64>>::Diff: Tolerance,
<<P as ControlPoint<f64>>::Diff as VectorSpace>::Scalar == f64,
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());
impl<P> BSplineCurve<P> where
P: Index<usize, Output = f64> + Bounded<f64> + Copy + MetricSpace<Metric = f64>,
impl<P> BSplineCurve<P> where
P: Index<usize, Output = f64> + Bounded<f64> + Copy + MetricSpace<Metric = f64>,
Returns the bounding box including all control points.
Trait Implementations
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)));
type Output = BSplineCurve<P>
type Output = BSplineCurve<P>
The result of concat two curves
Cuts one curve into two curves. Assigns the former curve to self
and returns the later curve.
pub fn deserialize<__D>(
__deserializer: __D
) -> Result<BSplineCurve<P>, <__D as Deserializer<'de>>::Error> where
__D: Deserializer<'de>,
pub fn deserialize<__D>(
__deserializer: __D
) -> Result<BSplineCurve<P>, <__D as Deserializer<'de>>::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl<V> From<BSplineCurve<<V as Homogeneous<f64>>::Point>> for NURBSCurve<V> where
V: Homogeneous<f64>,
impl<V> From<BSplineCurve<<V as Homogeneous<f64>>::Point>> for NURBSCurve<V> where
V: Homogeneous<f64>,
Performs the conversion.
Performs the conversion.
Returns whether the curve curve
is included in the surface self
.
impl<'a> IncludeCurve<BSplineCurve<Point3<f64>>> for RevolutedCurve<&'a BSplineCurve<Point3<f64>>>
impl<'a> IncludeCurve<BSplineCurve<Point3<f64>>> for RevolutedCurve<&'a BSplineCurve<Point3<f64>>>
Returns whether the curve curve
is included in the surface self
.
Returns whether the curve curve
is included in the surface self
.
impl<'a> IncludeCurve<BSplineCurve<Point3<f64>>> for RevolutedCurve<&'a NURBSCurve<Vector4<f64>>>
impl<'a> IncludeCurve<BSplineCurve<Point3<f64>>> for RevolutedCurve<&'a NURBSCurve<Vector4<f64>>>
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
.
impl<P> ParameterDivision1D for BSplineCurve<P> where
P: MetricSpace<Metric = f64> + ControlPoint<f64> + EuclideanSpace<Scalar = f64, Diff = <P as ControlPoint<f64>>::Diff>,
impl<P> ParameterDivision1D for BSplineCurve<P> where
P: MetricSpace<Metric = f64> + ControlPoint<f64> + EuclideanSpace<Scalar = f64, Diff = <P as ControlPoint<f64>>::Diff>,
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));
}
type Point = P
type Point = P
The curve is in the space of Self::Point
.
type Vector = <P as ControlPoint<f64>>::Diff
type Vector = <P as ControlPoint<f64>>::Diff
The derivation vector of the curve.
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
This method tests for !=
.
impl<P> SearchNearestParameter for BSplineCurve<P> where
P: Tolerance + ControlPoint<f64> + EuclideanSpace<Scalar = f64, Diff = <P as ControlPoint<f64>>::Diff> + MetricSpace<Metric = f64>,
<P as ControlPoint<f64>>::Diff: InnerSpace,
<P as ControlPoint<f64>>::Diff: Tolerance,
<<P as ControlPoint<f64>>::Diff as VectorSpace>::Scalar == f64,
impl<P> SearchNearestParameter for BSplineCurve<P> where
P: Tolerance + ControlPoint<f64> + EuclideanSpace<Scalar = f64, Diff = <P as ControlPoint<f64>>::Diff> + MetricSpace<Metric = f64>,
<P as ControlPoint<f64>>::Diff: InnerSpace,
<P as ControlPoint<f64>>::Diff: Tolerance,
<<P as ControlPoint<f64>>::Diff as VectorSpace>::Scalar == f64,
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());
type Point = P
type Point = P
point
impl<P> SearchParameter for BSplineCurve<P> where
P: ControlPoint<f64> + EuclideanSpace<Scalar = f64, Diff = <P as ControlPoint<f64>>::Diff> + MetricSpace<Metric = f64>,
<P as ControlPoint<f64>>::Diff: InnerSpace,
<P as ControlPoint<f64>>::Diff: Tolerance,
<<P as ControlPoint<f64>>::Diff as VectorSpace>::Scalar == f64,
impl<P> SearchParameter for BSplineCurve<P> where
P: ControlPoint<f64> + EuclideanSpace<Scalar = f64, Diff = <P as ControlPoint<f64>>::Diff> + MetricSpace<Metric = f64>,
<P as ControlPoint<f64>>::Diff: InnerSpace,
<P as ControlPoint<f64>>::Diff: Tolerance,
<<P as ControlPoint<f64>>::Diff as VectorSpace>::Scalar == f64,
pub fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error> where
__S: Serializer,
pub fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error> where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
transform by trans
.
transformed geometry by trans
.
Auto Trait Implementations
impl<P> RefUnwindSafe for BSplineCurve<P> where
P: RefUnwindSafe,
impl<P> Send for BSplineCurve<P> where
P: Send,
impl<P> Sync for BSplineCurve<P> where
P: Sync,
impl<P> Unpin for BSplineCurve<P> where
P: Unpin,
impl<P> UnwindSafe for BSplineCurve<P> where
P: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more