Struct truck_geometry::NURBSCurve [−][src]
NURBS curve
Implementations
impl<V> NURBSCurve<V>
[src]
pub const fn new(curve: BSplineCurve<V>) -> Self
[src]
Constructs the rationalized B-spline curve.
pub fn non_rationalized(&self) -> &BSplineCurve<V>
[src]
Returns the BSpline curve before rationalized.
pub fn into_non_rationalized(self) -> BSplineCurve<V>
[src]
Returns the BSpline curve before rationalized.
pub fn knot_vec(&self) -> &KnotVec
[src]
Returns the reference of the knot vector.
cf.BSplineCurve::knot_vec
pub fn knot(&self, idx: usize) -> f64
[src]
Returns the idx
th knot.
cf.BSplineCurve::knot
pub fn control_points(&self) -> &Vec<V>ⓘ
[src]
Returns the reference of the control points.
cf.BSplineCurve::control_points
pub fn control_point(&self, idx: usize) -> &V
[src]
Returns the reference of the control point corresponding to the index idx
.
cf.BSplineCurve::control_point
pub fn control_point_mut(&mut self, idx: usize) -> &mut V
[src]
Returns the mutable reference of the control point corresponding to index idx
.
cf.BSplineCurve::control_point_mut
pub fn control_points_mut(&mut self) -> impl Iterator<Item = &mut V>
[src]
Returns the iterator on all control points
cf.BSplineCurve::control_points_mut
pub fn transform_control_points<F: FnMut(&mut V)>(&mut self, f: F)
[src]
Apply the given transformation to all control points.
cf.BSplineCurve::transform_control_points
pub fn degree(&self) -> usize
[src]
Returns the degree of NURBS curve.
cf.BSplineCurve::degree
pub fn invert(&mut self) -> &mut Self
[src]
Inverts a curve.
cf.BSplineCurve::invert
pub fn is_clamped(&self) -> bool
[src]
Returns whether the knot vector is clamped or not.
cf.BSplineCurve::is_clamped
pub fn knot_normalize(&mut self) -> &mut Self
[src]
Normalizes the knot vector.
cf.BSplineCurve::knot_normalize
pub fn knot_translate(&mut self, x: f64) -> &mut Self
[src]
Translates the knot vector.
cf.BSplineCurve::knot_translate
impl<V: Homogeneous<f64>> NURBSCurve<V>
[src]
pub fn get_closure(&self) -> impl Fn(f64) -> V::Point + '_
[src]
Returns the closure of substitution.
impl<V: Homogeneous<f64>> NURBSCurve<V> where
V::Point: Tolerance,
[src]
V::Point: Tolerance,
pub fn is_const(&self) -> bool
[src]
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());
pub fn near_as_curve(&self, other: &Self) -> bool
[src]
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));
pub fn near2_as_curve(&self, other: &Self) -> bool
[src]
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 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));
impl<V: Homogeneous<f64> + Tolerance> NURBSCurve<V>
[src]
pub fn add_knot(&mut self, x: f64) -> &mut Self
[src]
Adds a knot x
, and do not change self
as a curve.
cf.BSplineCurve::add_knot
pub fn remove_knot(&mut self, idx: usize) -> &mut Self
[src]
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
pub fn try_remove_knot(&mut self, idx: usize) -> Result<&mut Self>
[src]
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
pub fn elevate_degree(&mut self) -> &mut Self
[src]
Elevates 1 degree.
cf.BSplineCurve::elevate_degree
pub fn clamp(&mut self) -> &mut Self
[src]
Makes the NURBS curve clamped
cf.BSplineCurve::clamp
pub fn optimize(&mut self) -> &mut Self
[src]
Repeats Self::try_remove_knot()
from the back knot in turn until the knot cannot be removed.
cf.BSplineCurve::optimize
pub fn syncro_degree(&mut self, other: &mut Self)
[src]
Makes two splines having the same degrees.
cf.BSplineCurve::syncro_degree
pub fn syncro_knots(&mut self, other: &mut Self)
[src]
Makes two splines having the same normalized knot vectors.
cf.BSplineCurve::syncro_knots
pub fn cut(&mut self, t: f64) -> Self
[src]
Cuts the curve to two curves at the parameter t
.
cf.BSplineCurve::syncro_knots
pub fn try_concat(&mut self, other: &mut Self) -> Result<&mut Self>
[src]
Concats two NURBS curves.
cf.BSplineCurve::try_concat
pub fn concat(&mut self, other: &mut Self) -> &mut Self
[src]
Concats two NURBS curves.
cf.BSplineCurve::concat
impl<V: Homogeneous<f64> + Tolerance> NURBSCurve<V> where
V::Point: Tolerance,
[src]
V::Point: Tolerance,
pub fn make_locally_injective(&mut self) -> &mut Self
[src]
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);
impl<V: Homogeneous<f64>> NURBSCurve<V> where
<V::Point as EuclideanSpace>::Diff: InnerSpace,
[src]
<V::Point as EuclideanSpace>::Diff: InnerSpace,
pub fn search_nearest_parameter(
&self,
point: V::Point,
hint: f64
) -> Option<f64>
[src]
&self,
point: V::Point,
hint: f64
) -> Option<f64>
Searches the parameter t
which minimize |self(t) - point|
by Newton's method with initial guess hint
.
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.6; let t = curve.search_nearest_parameter(pt, hint).unwrap(); // check the answer let res = curve.subs(t); let ans = Point2::from_vec(pt.to_vec().normalize()); Point2::assert_near2(&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, hint).is_none());
Trait Implementations
impl<V: Clone> Clone for NURBSCurve<V>
[src]
fn clone(&self) -> NURBSCurve<V>
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<V: Homogeneous<f64>> Curve for NURBSCurve<V>
[src]
type Point = V::Point
The curve is in the space of Self::Point
.
type Vector = <V::Point as EuclideanSpace>::Diff
The derivation vector of the curve.
fn subs(&self, t: f64) -> Self::Point
[src]
fn der(&self, t: f64) -> Self::Vector
[src]
fn parameter_range(&self) -> (f64, f64)
[src]
fn inverse(&self) -> Self
[src]
pub fn front(&self) -> Self::Point
[src]
pub fn back(&self) -> Self::Point
[src]
impl<V: Debug> Debug for NURBSCurve<V>
[src]
impl<'de, V> Deserialize<'de> for NURBSCurve<V> where
V: Deserialize<'de>,
[src]
V: Deserialize<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
impl<V: Homogeneous<f64>> ParameterDivision1D for NURBSCurve<V> where
V::Point: MetricSpace<Metric = f64>,
[src]
V::Point: MetricSpace<Metric = f64>,
fn parameter_division(&self, tol: f64) -> Vec<f64>ⓘ
[src]
impl<V: PartialEq> PartialEq<NURBSCurve<V>> for NURBSCurve<V>
[src]
fn eq(&self, other: &NURBSCurve<V>) -> bool
[src]
fn ne(&self, other: &NURBSCurve<V>) -> bool
[src]
impl<V> Serialize for NURBSCurve<V> where
V: Serialize,
[src]
V: Serialize,
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
[src]
__S: Serializer,
impl<V> StructuralPartialEq for NURBSCurve<V>
[src]
Auto Trait Implementations
impl<V> RefUnwindSafe for NURBSCurve<V> where
V: RefUnwindSafe,
[src]
V: RefUnwindSafe,
impl<V> Send for NURBSCurve<V> where
V: Send,
[src]
V: Send,
impl<V> Sync for NURBSCurve<V> where
V: Sync,
[src]
V: Sync,
impl<V> Unpin for NURBSCurve<V> where
V: Unpin,
[src]
V: Unpin,
impl<V> UnwindSafe for NURBSCurve<V> where
V: UnwindSafe,
[src]
V: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,