Struct truck_modeling::geometry::NURBSCurve
source · pub struct NURBSCurve<V>(_);
Expand description
NURBS curve
Implementations§
source§impl<V> NURBSCurve<V>
impl<V> NURBSCurve<V>
sourcepub const fn new(curve: BSplineCurve<V>) -> NURBSCurve<V>
pub const fn new(curve: BSplineCurve<V>) -> NURBSCurve<V>
Constructs the rationalized B-spline curve.
sourcepub const fn non_rationalized(&self) -> &BSplineCurve<V>
pub const fn non_rationalized(&self) -> &BSplineCurve<V>
Returns the BSpline curve before rationalized.
sourcepub fn into_non_rationalized(self) -> BSplineCurve<V>
pub fn into_non_rationalized(self) -> BSplineCurve<V>
Returns the BSpline curve before rationalized.
sourcepub const fn knot_vec(&self) -> &KnotVec
pub const fn knot_vec(&self) -> &KnotVec
Returns the reference of the knot vector.
cf.BSplineCurve::knot_vec
sourcepub fn knot(&self, idx: usize) -> f64
pub fn knot(&self, idx: usize) -> f64
Returns the idx
th knot.
cf.BSplineCurve::knot
sourcepub const fn control_points(&self) -> &Vec<V, Global> ⓘ
pub const fn control_points(&self) -> &Vec<V, Global> ⓘ
Returns the reference of the control points.
cf.BSplineCurve::control_points
sourcepub fn control_point(&self, idx: usize) -> &V
pub fn control_point(&self, idx: usize) -> &V
Returns the reference of the control point corresponding to the index idx
.
cf.BSplineCurve::control_point
sourcepub fn control_point_mut(&mut self, idx: usize) -> &mut V
pub fn control_point_mut(&mut self, idx: usize) -> &mut V
Returns the mutable reference of the control point corresponding to index idx
.
cf.BSplineCurve::control_point_mut
sourcepub fn control_points_mut(&mut self) -> impl Iterator<Item = &mut V>
pub fn control_points_mut(&mut self) -> impl Iterator<Item = &mut V>
Returns the iterator on all control points
cf.BSplineCurve::control_points_mut
sourcepub fn transform_control_points<F>(&mut self, f: F)where
F: FnMut(&mut V),
pub fn transform_control_points<F>(&mut self, f: F)where
F: FnMut(&mut V),
Apply the given transformation to all control points.
cf.BSplineCurve::transform_control_points
sourcepub fn degree(&self) -> usize
pub fn degree(&self) -> usize
Returns the degree of NURBS curve.
cf.BSplineCurve::degree
sourcepub fn invert(&mut self) -> &mut NURBSCurve<V>
pub fn invert(&mut self) -> &mut NURBSCurve<V>
Inverts a curve.
cf.BSplineCurve::invert
sourcepub fn is_clamped(&self) -> bool
pub fn is_clamped(&self) -> bool
Returns whether the knot vector is clamped or not.
cf.BSplineCurve::is_clamped
sourcepub fn knot_normalize(&mut self) -> &mut NURBSCurve<V>
pub fn knot_normalize(&mut self) -> &mut NURBSCurve<V>
Normalizes the knot vector.
cf.BSplineCurve::knot_normalize
sourcepub fn knot_translate(&mut self, x: f64) -> &mut NURBSCurve<V>
pub fn knot_translate(&mut self, x: f64) -> &mut NURBSCurve<V>
Translates the knot vector.
cf.BSplineCurve::knot_translate
source§impl<V> NURBSCurve<V>where
V: Homogeneous<f64>,
impl<V> NURBSCurve<V>where
V: Homogeneous<f64>,
sourcepub fn try_from_bspline_and_weights(
curve: BSplineCurve<<V as Homogeneous<f64>>::Point>,
weights: Vec<f64, Global>
) -> Result<NURBSCurve<V>, Error>
pub fn try_from_bspline_and_weights(
curve: BSplineCurve<<V as Homogeneous<f64>>::Point>,
weights: Vec<f64, Global>
) -> Result<NURBSCurve<V>, Error>
Constructs a rationalization curve from the curves and weights.
Failures
the length of curve.control_points()
and weights
must be the same.
source§impl<V> NURBSCurve<V>where
V: Homogeneous<f64> + ControlPoint<f64, Diff = V>,
impl<V> NURBSCurve<V>where
V: Homogeneous<f64> + ControlPoint<f64, Diff = V>,
sourcepub fn get_closure(&self) -> impl Fn(f64)
pub fn get_closure(&self) -> impl Fn(f64)
Returns the closure of substitution.
source§impl<V> NURBSCurve<V>where
V: Homogeneous<f64> + ControlPoint<f64, Diff = V>,
<V as Homogeneous<f64>>::Point: Tolerance,
impl<V> NURBSCurve<V>where
V: Homogeneous<f64> + ControlPoint<f64, Diff = V>,
<V as Homogeneous<f64>>::Point: Tolerance,
sourcepub fn is_const(&self) -> bool
pub fn is_const(&self) -> bool
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());
sourcepub fn near_as_curve(&self, other: &NURBSCurve<V>) -> bool
pub fn near_as_curve(&self, other: &NURBSCurve<V>) -> bool
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));
sourcepub fn near2_as_curve(&self, other: &NURBSCurve<V>) -> bool
pub fn near2_as_curve(&self, other: &NURBSCurve<V>) -> bool
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));
source§impl<V> NURBSCurve<V>where
V: Homogeneous<f64> + ControlPoint<f64, Diff = V> + Tolerance,
impl<V> NURBSCurve<V>where
V: Homogeneous<f64> + ControlPoint<f64, Diff = V> + Tolerance,
sourcepub fn add_knot(&mut self, x: f64) -> &mut NURBSCurve<V>
pub fn add_knot(&mut self, x: f64) -> &mut NURBSCurve<V>
Adds a knot x
, and do not change self
as a curve.
cf.BSplineCurve::add_knot
sourcepub fn remove_knot(&mut self, idx: usize) -> &mut NURBSCurve<V>
pub fn remove_knot(&mut self, idx: usize) -> &mut NURBSCurve<V>
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
sourcepub fn try_remove_knot(
&mut self,
idx: usize
) -> Result<&mut NURBSCurve<V>, Error>
pub fn try_remove_knot(
&mut self,
idx: usize
) -> Result<&mut NURBSCurve<V>, Error>
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
sourcepub fn elevate_degree(&mut self) -> &mut NURBSCurve<V>
pub fn elevate_degree(&mut self) -> &mut NURBSCurve<V>
Elevates 1 degree.
cf.BSplineCurve::elevate_degree
sourcepub fn clamp(&mut self) -> &mut NURBSCurve<V>
pub fn clamp(&mut self) -> &mut NURBSCurve<V>
Makes the NURBS curve clamped
cf.BSplineCurve::clamp
sourcepub fn optimize(&mut self) -> &mut NURBSCurve<V>
pub fn optimize(&mut self) -> &mut NURBSCurve<V>
Repeats Self::try_remove_knot()
from the back knot in turn until the knot cannot be removed.
cf.BSplineCurve::optimize
sourcepub fn syncro_degree(&mut self, other: &mut NURBSCurve<V>)
pub fn syncro_degree(&mut self, other: &mut NURBSCurve<V>)
Makes two splines having the same degrees.
cf.BSplineCurve::syncro_degree
sourcepub fn syncro_knots(&mut self, other: &mut NURBSCurve<V>)
pub fn syncro_knots(&mut self, other: &mut NURBSCurve<V>)
Makes two splines having the same normalized knot vectors.
cf.BSplineCurve::syncro_knots
source§impl<V> NURBSCurve<V>where
V: Homogeneous<f64> + ControlPoint<f64, Diff = V> + Tolerance,
<V as Homogeneous<f64>>::Point: Tolerance,
impl<V> NURBSCurve<V>where
V: Homogeneous<f64> + ControlPoint<f64, Diff = V> + Tolerance,
<V as Homogeneous<f64>>::Point: Tolerance,
sourcepub fn make_locally_injective(&mut self) -> &mut NURBSCurve<V>
pub fn make_locally_injective(&mut self) -> &mut NURBSCurve<V>
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);
source§impl<V> NURBSCurve<V>where
<V as Homogeneous<f64>>::Point: MetricSpace<Metric = f64> + Index<usize, Output = f64> + Bounded<f64> + Copy,
V: Homogeneous<f64>,
impl<V> NURBSCurve<V>where
<V as Homogeneous<f64>>::Point: MetricSpace<Metric = f64> + Index<usize, Output = f64> + Bounded<f64> + Copy,
V: Homogeneous<f64>,
sourcepub fn roughly_bounding_box(
&self
) -> BoundingBox<<V as Homogeneous<f64>>::Point>
pub fn roughly_bounding_box(
&self
) -> BoundingBox<<V as Homogeneous<f64>>::Point>
Returns the bounding box including all control points.
Trait Implementations§
source§impl<V> BoundedCurve for NURBSCurve<V>where
V: Homogeneous<f64> + ControlPoint<f64, Diff = V>,
impl<V> BoundedCurve for NURBSCurve<V>where
V: Homogeneous<f64> + ControlPoint<f64, Diff = V>,
source§impl<V> Clone for NURBSCurve<V>where
V: Clone,
impl<V> Clone for NURBSCurve<V>where
V: Clone,
source§fn clone(&self) -> NURBSCurve<V>
fn clone(&self) -> NURBSCurve<V>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<V> Concat<NURBSCurve<V>> for NURBSCurve<V>where
V: Homogeneous<f64> + ControlPoint<f64, Diff = V> + Tolerance,
<V as Homogeneous<f64>>::Point: Debug,
impl<V> Concat<NURBSCurve<V>> for NURBSCurve<V>where
V: Homogeneous<f64> + ControlPoint<f64, Diff = V> + Tolerance,
<V as Homogeneous<f64>>::Point: Debug,
§type Output = NURBSCurve<V>
type Output = NURBSCurve<V>
source§fn try_concat(
&self,
other: &NURBSCurve<V>
) -> Result<NURBSCurve<V>, ConcatError<<V as Homogeneous<f64>>::Point>>
fn try_concat(
&self,
other: &NURBSCurve<V>
) -> Result<NURBSCurve<V>, ConcatError<<V as Homogeneous<f64>>::Point>>
source§impl<V> Cut for NURBSCurve<V>where
V: Homogeneous<f64> + ControlPoint<f64, Diff = V> + Tolerance,
impl<V> Cut for NURBSCurve<V>where
V: Homogeneous<f64> + ControlPoint<f64, Diff = V> + Tolerance,
source§fn cut(&mut self, t: f64) -> NURBSCurve<V>
fn cut(&mut self, t: f64) -> NURBSCurve<V>
self
and returns the later curve.source§impl<V> Debug for NURBSCurve<V>where
V: Debug,
impl<V> Debug for NURBSCurve<V>where
V: Debug,
source§impl<'de, V> Deserialize<'de> for NURBSCurve<V>where
V: Deserialize<'de>,
impl<'de, V> Deserialize<'de> for NURBSCurve<V>where
V: Deserialize<'de>,
source§fn deserialize<__D>(
__deserializer: __D
) -> Result<NURBSCurve<V>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D
) -> Result<NURBSCurve<V>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
source§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>,
source§fn from(bspcurve: BSplineCurve<<V as Homogeneous<f64>>::Point>) -> NURBSCurve<V>
fn from(bspcurve: BSplineCurve<<V as Homogeneous<f64>>::Point>) -> NURBSCurve<V>
source§impl IncludeCurve<NURBSCurve<Vector3<f64>>> for NURBSSurface<Vector3<f64>>
impl IncludeCurve<NURBSCurve<Vector3<f64>>> for NURBSSurface<Vector3<f64>>
source§impl IncludeCurve<NURBSCurve<Vector4<f64>>> for BSplineSurface<Point3<f64>>
impl IncludeCurve<NURBSCurve<Vector4<f64>>> for BSplineSurface<Point3<f64>>
source§impl IncludeCurve<NURBSCurve<Vector4<f64>>> for NURBSSurface<Vector4<f64>>
impl IncludeCurve<NURBSCurve<Vector4<f64>>> for NURBSSurface<Vector4<f64>>
source§impl IncludeCurve<NURBSCurve<Vector4<f64>>> for Plane
impl IncludeCurve<NURBSCurve<Vector4<f64>>> for Plane
source§impl<'a> IncludeCurve<NURBSCurve<Vector4<f64>>> for RevolutedCurve<&'a BSplineCurve<Point3<f64>>>
impl<'a> IncludeCurve<NURBSCurve<Vector4<f64>>> for RevolutedCurve<&'a BSplineCurve<Point3<f64>>>
source§impl<'a> IncludeCurve<NURBSCurve<Vector4<f64>>> for RevolutedCurve<&'a NURBSCurve<Vector4<f64>>>
impl<'a> IncludeCurve<NURBSCurve<Vector4<f64>>> for RevolutedCurve<&'a NURBSCurve<Vector4<f64>>>
source§impl IncludeCurve<NURBSCurve<Vector4<f64>>> for RevolutedCurve<BSplineCurve<Point3<f64>>>
impl IncludeCurve<NURBSCurve<Vector4<f64>>> for RevolutedCurve<BSplineCurve<Point3<f64>>>
source§impl IncludeCurve<NURBSCurve<Vector4<f64>>> for RevolutedCurve<NURBSCurve<Vector4<f64>>>
impl IncludeCurve<NURBSCurve<Vector4<f64>>> for RevolutedCurve<NURBSCurve<Vector4<f64>>>
source§impl IncludeCurve<NURBSCurve<Vector4<f64>>> for Sphere
impl IncludeCurve<NURBSCurve<Vector4<f64>>> for Sphere
source§impl<V> Invertible for NURBSCurve<V>where
V: Clone,
impl<V> Invertible for NURBSCurve<V>where
V: Clone,
source§impl<V> ParameterDivision1D for NURBSCurve<V>where
V: ControlPoint<f64, Diff = V> + Homogeneous<f64>,
<V as Homogeneous<f64>>::Point: MetricSpace<Metric = f64> + HashGen<f64>,
impl<V> ParameterDivision1D for NURBSCurve<V>where
V: ControlPoint<f64, Diff = V> + Homogeneous<f64>,
<V as Homogeneous<f64>>::Point: MetricSpace<Metric = f64> + HashGen<f64>,
source§impl<V> ParameterTransform for NURBSCurve<V>where
V: Homogeneous<f64> + ControlPoint<f64, Diff = V> + Tolerance,
impl<V> ParameterTransform for NURBSCurve<V>where
V: Homogeneous<f64> + ControlPoint<f64, Diff = V> + Tolerance,
source§fn parameter_transform(&mut self, scalar: f64, move: f64) -> &mut NURBSCurve<V>
fn parameter_transform(&mut self, scalar: f64, move: f64) -> &mut NURBSCurve<V>
source§fn parameter_transformed(&self, scalar: f64, move: f64) -> Self
fn parameter_transformed(&self, scalar: f64, move: f64) -> Self
source§fn parameter_normalization(&mut self) -> &mut Self
fn parameter_normalization(&mut self) -> &mut Self
(0.0, 1.0)
.source§impl<V> ParametricCurve for NURBSCurve<V>where
V: Homogeneous<f64> + ControlPoint<f64, Diff = V>,
impl<V> ParametricCurve for NURBSCurve<V>where
V: Homogeneous<f64> + ControlPoint<f64, Diff = V>,
§type Point = <V as Homogeneous<f64>>::Point
type Point = <V as Homogeneous<f64>>::Point
Self::Point
.§type Vector = <<V as Homogeneous<f64>>::Point as EuclideanSpace>::Diff
type Vector = <<V as Homogeneous<f64>>::Point as EuclideanSpace>::Diff
source§fn subs(&self, t: f64) -> <NURBSCurve<V> as ParametricCurve>::Point
fn subs(&self, t: f64) -> <NURBSCurve<V> as ParametricCurve>::Point
t
.source§fn der(&self, t: f64) -> <NURBSCurve<V> as ParametricCurve>::Vector
fn der(&self, t: f64) -> <NURBSCurve<V> as ParametricCurve>::Vector
source§fn der2(&self, t: f64) -> <NURBSCurve<V> as ParametricCurve>::Vector
fn der2(&self, t: f64) -> <NURBSCurve<V> as ParametricCurve>::Vector
source§impl<V> PartialEq<NURBSCurve<V>> for NURBSCurve<V>where
V: PartialEq<V>,
impl<V> PartialEq<NURBSCurve<V>> for NURBSCurve<V>where
V: PartialEq<V>,
source§fn eq(&self, other: &NURBSCurve<V>) -> bool
fn eq(&self, other: &NURBSCurve<V>) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<V> SearchNearestParameter<D1> for NURBSCurve<V>where
V: ControlPoint<f64, Diff = V> + Homogeneous<f64>,
<V as Homogeneous<f64>>::Point: MetricSpace<Metric = f64>,
<<V as Homogeneous<f64>>::Point as EuclideanSpace>::Diff: InnerSpace + Tolerance,
impl<V> SearchNearestParameter<D1> for NURBSCurve<V>where
V: ControlPoint<f64, Diff = V> + Homogeneous<f64>,
<V as Homogeneous<f64>>::Point: MetricSpace<Metric = f64>,
<<V as Homogeneous<f64>>::Point as EuclideanSpace>::Diff: InnerSpace + Tolerance,
source§fn search_nearest_parameter<H>(
&self,
point: <V as Homogeneous<f64>>::Point,
hint: H,
trial: usize
) -> Option<f64>where
H: Into<SPHint1D>,
fn search_nearest_parameter<H>(
&self,
point: <V as Homogeneous<f64>>::Point,
hint: H,
trial: usize
) -> Option<f64>where
H: Into<SPHint1D>,
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());
§type Point = <V as Homogeneous<f64>>::Point
type Point = <V as Homogeneous<f64>>::Point
source§impl<V> SearchParameter<D1> for NURBSCurve<V>where
V: ControlPoint<f64, Diff = V> + Homogeneous<f64>,
<V as Homogeneous<f64>>::Point: MetricSpace<Metric = f64>,
<<V as Homogeneous<f64>>::Point as EuclideanSpace>::Diff: InnerSpace + Tolerance,
impl<V> SearchParameter<D1> for NURBSCurve<V>where
V: ControlPoint<f64, Diff = V> + Homogeneous<f64>,
<V as Homogeneous<f64>>::Point: MetricSpace<Metric = f64>,
<<V as Homogeneous<f64>>::Point as EuclideanSpace>::Diff: InnerSpace + Tolerance,
source§impl<V> Serialize for NURBSCurve<V>where
V: Serialize,
impl<V> Serialize for NURBSCurve<V>where
V: Serialize,
source§fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
source§impl<M, V> Transformed<M> for NURBSCurve<V>where
V: Copy,
M: Copy + Mul<V, Output = V>,
impl<M, V> Transformed<M> for NURBSCurve<V>where
V: Copy,
M: Copy + Mul<V, Output = V>,
source§fn transform_by(&mut self, trans: M)
fn transform_by(&mut self, trans: M)
trans
.source§fn transformed(&self, trans: T) -> Self
fn transformed(&self, trans: T) -> Self
trans
.