Struct truck_modeling::geometry::NURBSCurve [−][src]
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 idx
th 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
Returns the closure of substitution.
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,
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)| < 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));
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
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,
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> NURBSCurve<V> where
V: Homogeneous<f64>,
<V as Homogeneous<f64>>::Point: MetricSpace,
<V as Homogeneous<f64>>::Point: Index<usize>,
<V as Homogeneous<f64>>::Point: Bounded<f64>,
<V as Homogeneous<f64>>::Point: Copy,
<<V as Homogeneous<f64>>::Point as MetricSpace>::Metric == f64,
<<V as Homogeneous<f64>>::Point as Index<usize>>::Output == f64,
impl<V> NURBSCurve<V> where
V: Homogeneous<f64>,
<V as Homogeneous<f64>>::Point: MetricSpace,
<V as Homogeneous<f64>>::Point: Index<usize>,
<V as Homogeneous<f64>>::Point: Bounded<f64>,
<V as Homogeneous<f64>>::Point: Copy,
<<V as Homogeneous<f64>>::Point as MetricSpace>::Metric == f64,
<<V as Homogeneous<f64>>::Point as Index<usize>>::Output == f64,
Returns the bounding box including all control points.
Trait Implementations
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>
The result of concat two curves
pub fn try_concat(
&self,
other: &NURBSCurve<V>
) -> Result<NURBSCurve<V>, ConcatError<<V as Homogeneous<f64>>::Point>>
pub fn try_concat(
&self,
other: &NURBSCurve<V>
) -> Result<NURBSCurve<V>, ConcatError<<V as Homogeneous<f64>>::Point>>
Try concat two curves. Read more
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,
Cuts one curve into two curves. Assigns the former curve to self
and returns the later curve.
pub fn deserialize<__D>(
__deserializer: __D
) -> Result<NURBSCurve<V>, <__D as Deserializer<'de>>::Error> where
__D: Deserializer<'de>,
pub fn deserialize<__D>(
__deserializer: __D
) -> Result<NURBSCurve<V>, <__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
.
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<'a> IncludeCurve<NURBSCurve<Vector4<f64>>> for RevolutedCurve<&'a BSplineCurve<Point3<f64>>>
impl<'a> IncludeCurve<NURBSCurve<Vector4<f64>>> for RevolutedCurve<&'a BSplineCurve<Point3<f64>>>
Returns whether the curve curve
is included in the surface self
.
impl<'a> IncludeCurve<NURBSCurve<Vector4<f64>>> for RevolutedCurve<&'a NURBSCurve<Vector4<f64>>>
impl<'a> IncludeCurve<NURBSCurve<Vector4<f64>>> for RevolutedCurve<&'a NURBSCurve<Vector4<f64>>>
Returns whether the curve curve
is included in the surface self
.
Returns the inverse.
impl<V> ParameterDivision1D for NURBSCurve<V> where
V: ControlPoint<f64, Diff = V> + Homogeneous<f64>,
<V as Homogeneous<f64>>::Point: MetricSpace,
<<V as Homogeneous<f64>>::Point as MetricSpace>::Metric == f64,
impl<V> ParameterDivision1D for NURBSCurve<V> where
V: ControlPoint<f64, Diff = V> + Homogeneous<f64>,
<V as Homogeneous<f64>>::Point: MetricSpace,
<<V as Homogeneous<f64>>::Point as MetricSpace>::Metric == f64,
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,
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
The curve is in the space of Self::Point
.
type Vector = <<V as Homogeneous<f64>>::Point as EuclideanSpace>::Diff
type Vector = <<V as Homogeneous<f64>>::Point as EuclideanSpace>::Diff
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 ==
. Read more
This method tests for !=
.
impl<V> SearchNearestParameter for NURBSCurve<V> where
V: ControlPoint<f64, Diff = V> + Homogeneous<f64>,
<V as Homogeneous<f64>>::Point: MetricSpace,
<<V as Homogeneous<f64>>::Point as EuclideanSpace>::Diff: InnerSpace,
<<V as Homogeneous<f64>>::Point as EuclideanSpace>::Diff: Tolerance,
<<V as Homogeneous<f64>>::Point as MetricSpace>::Metric == f64,
impl<V> SearchNearestParameter for NURBSCurve<V> where
V: ControlPoint<f64, Diff = V> + Homogeneous<f64>,
<V as Homogeneous<f64>>::Point: MetricSpace,
<<V as Homogeneous<f64>>::Point as EuclideanSpace>::Diff: InnerSpace,
<<V as Homogeneous<f64>>::Point as EuclideanSpace>::Diff: Tolerance,
<<V as Homogeneous<f64>>::Point as MetricSpace>::Metric == f64,
pub fn search_nearest_parameter(
&self,
point: <V as Homogeneous<f64>>::Point,
hint: Option<f64>,
trial: usize
) -> Option<f64>
pub fn search_nearest_parameter(
&self,
point: <V as Homogeneous<f64>>::Point,
hint: Option<f64>,
trial: usize
) -> Option<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::*;
// 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
point
impl<V> SearchParameter for NURBSCurve<V> where
V: ControlPoint<f64, Diff = V> + Homogeneous<f64>,
<V as Homogeneous<f64>>::Point: MetricSpace,
<<V as Homogeneous<f64>>::Point as EuclideanSpace>::Diff: InnerSpace,
<<V as Homogeneous<f64>>::Point as EuclideanSpace>::Diff: Tolerance,
<<V as Homogeneous<f64>>::Point as MetricSpace>::Metric == f64,
impl<V> SearchParameter for NURBSCurve<V> where
V: ControlPoint<f64, Diff = V> + Homogeneous<f64>,
<V as Homogeneous<f64>>::Point: MetricSpace,
<<V as Homogeneous<f64>>::Point as EuclideanSpace>::Diff: InnerSpace,
<<V as Homogeneous<f64>>::Point as EuclideanSpace>::Diff: Tolerance,
<<V as Homogeneous<f64>>::Point as MetricSpace>::Metric == f64,
type Point = <V as Homogeneous<f64>>::Point
type Point = <V as Homogeneous<f64>>::Point
point
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<V> RefUnwindSafe for NURBSCurve<V> where
V: RefUnwindSafe,
impl<V> Send for NURBSCurve<V> where
V: Send,
impl<V> Sync for NURBSCurve<V> where
V: Sync,
impl<V> Unpin for NURBSCurve<V> where
V: Unpin,
impl<V> UnwindSafe for NURBSCurve<V> where
V: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more