Struct truck_geometry::nurbs::NURBSSurface
source · pub struct NURBSSurface<V>(_);
Expand description
NURBS surface
Implementations§
source§impl<V> NURBSSurface<V>
impl<V> NURBSSurface<V>
sourcepub const fn new(bspsurface: BSplineSurface<V>) -> Self
pub const fn new(bspsurface: BSplineSurface<V>) -> Self
constructor
Examples found in repository?
More examples
sourcepub const fn non_rationalized(&self) -> &BSplineSurface<V>
pub const fn non_rationalized(&self) -> &BSplineSurface<V>
Returns the nurbs surface before rationalized
sourcepub fn non_rationalized_mut(&mut self) -> &mut BSplineSurface<V>
pub fn non_rationalized_mut(&mut self) -> &mut BSplineSurface<V>
Returns the nurbs surface before rationalized
sourcepub fn into_non_rationalized(self) -> BSplineSurface<V>
pub fn into_non_rationalized(self) -> BSplineSurface<V>
Returns the nurbs surface before rationalized
sourcepub const fn uknot_vec(&self) -> &KnotVec
pub const fn uknot_vec(&self) -> &KnotVec
Returns the u knot vector.
Examples found in repository?
656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756
fn include(&self, curve: &NURBSCurve<Vector3>) -> bool {
let pt = curve.subs(curve.knot_vec()[0]);
let mut hint = match self.search_parameter(pt, None, INCLUDE_CURVE_TRIALS) {
Some(got) => got,
None => return false,
};
let uknot_vec = self.uknot_vec();
let vknot_vec = self.vknot_vec();
let degree = curve.degree() * 6;
let (knots, _) = curve.knot_vec().to_single_multi();
for i in 1..knots.len() {
for j in 1..=degree {
let p = j as f64 / degree as f64;
let t = knots[i - 1] * (1.0 - p) + knots[i] * p;
let pt = curve.subs(t);
hint = match self.search_parameter(pt, Some(hint), INCLUDE_CURVE_TRIALS) {
Some(got) => got,
None => return false,
};
if !self.subs(hint.0, hint.1).near(&pt)
|| hint.0 < uknot_vec[0] - TOLERANCE
|| hint.0 - uknot_vec[0] > uknot_vec.range_length() + TOLERANCE
|| hint.1 < vknot_vec[0] - TOLERANCE
|| hint.1 - vknot_vec[0] > vknot_vec.range_length() + TOLERANCE
{
return false;
}
}
}
true
}
}
impl IncludeCurve<BSplineCurve<Point3>> for NURBSSurface<Vector4> {
#[inline(always)]
fn include(&self, curve: &BSplineCurve<Point3>) -> bool {
let pt = curve.front();
let mut hint = match self.search_parameter(pt, None, INCLUDE_CURVE_TRIALS) {
Some(got) => got,
None => return false,
};
let uknot_vec = self.uknot_vec();
let vknot_vec = self.vknot_vec();
let degree = curve.degree() * 6;
let (knots, _) = curve.knot_vec().to_single_multi();
for i in 1..knots.len() {
for j in 1..=degree {
let p = j as f64 / degree as f64;
let t = knots[i - 1] * (1.0 - p) + knots[i] * p;
let pt = curve.subs(t);
hint = match self.search_parameter(pt, Some(hint), INCLUDE_CURVE_TRIALS) {
Some(got) => got,
None => return false,
};
if !self.subs(hint.0, hint.1).near(&pt)
|| hint.0 < uknot_vec[0] - TOLERANCE
|| hint.0 - uknot_vec[0] > uknot_vec.range_length() + TOLERANCE
|| hint.1 < vknot_vec[0] - TOLERANCE
|| hint.1 - vknot_vec[0] > vknot_vec.range_length() + TOLERANCE
{
return false;
}
}
}
true
}
}
impl IncludeCurve<NURBSCurve<Vector4>> for NURBSSurface<Vector4> {
#[inline(always)]
fn include(&self, curve: &NURBSCurve<Vector4>) -> bool {
let pt = curve.front();
let mut hint = match self.search_parameter(pt, None, INCLUDE_CURVE_TRIALS) {
Some(got) => got,
None => return false,
};
let uknot_vec = self.uknot_vec();
let vknot_vec = self.vknot_vec();
let degree = curve.degree() * 6;
let (knots, _) = curve.knot_vec().to_single_multi();
for i in 1..knots.len() {
for j in 1..=degree {
let p = j as f64 / degree as f64;
let t = knots[i - 1] * (1.0 - p) + knots[i] * p;
let pt = curve.subs(t);
hint = match self.search_parameter(pt, Some(hint), INCLUDE_CURVE_TRIALS) {
Some(got) => got,
None => return false,
};
if !self.subs(hint.0, hint.1).near(&pt)
|| hint.0 < uknot_vec[0] - TOLERANCE
|| hint.0 - uknot_vec[0] > uknot_vec.range_length() + TOLERANCE
|| hint.1 < vknot_vec[0] - TOLERANCE
|| hint.1 - vknot_vec[0] > vknot_vec.range_length() + TOLERANCE
{
return false;
}
}
}
true
}
sourcepub const fn vknot_vec(&self) -> &KnotVec
pub const fn vknot_vec(&self) -> &KnotVec
Returns the v knot vector.
Examples found in repository?
656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756
fn include(&self, curve: &NURBSCurve<Vector3>) -> bool {
let pt = curve.subs(curve.knot_vec()[0]);
let mut hint = match self.search_parameter(pt, None, INCLUDE_CURVE_TRIALS) {
Some(got) => got,
None => return false,
};
let uknot_vec = self.uknot_vec();
let vknot_vec = self.vknot_vec();
let degree = curve.degree() * 6;
let (knots, _) = curve.knot_vec().to_single_multi();
for i in 1..knots.len() {
for j in 1..=degree {
let p = j as f64 / degree as f64;
let t = knots[i - 1] * (1.0 - p) + knots[i] * p;
let pt = curve.subs(t);
hint = match self.search_parameter(pt, Some(hint), INCLUDE_CURVE_TRIALS) {
Some(got) => got,
None => return false,
};
if !self.subs(hint.0, hint.1).near(&pt)
|| hint.0 < uknot_vec[0] - TOLERANCE
|| hint.0 - uknot_vec[0] > uknot_vec.range_length() + TOLERANCE
|| hint.1 < vknot_vec[0] - TOLERANCE
|| hint.1 - vknot_vec[0] > vknot_vec.range_length() + TOLERANCE
{
return false;
}
}
}
true
}
}
impl IncludeCurve<BSplineCurve<Point3>> for NURBSSurface<Vector4> {
#[inline(always)]
fn include(&self, curve: &BSplineCurve<Point3>) -> bool {
let pt = curve.front();
let mut hint = match self.search_parameter(pt, None, INCLUDE_CURVE_TRIALS) {
Some(got) => got,
None => return false,
};
let uknot_vec = self.uknot_vec();
let vknot_vec = self.vknot_vec();
let degree = curve.degree() * 6;
let (knots, _) = curve.knot_vec().to_single_multi();
for i in 1..knots.len() {
for j in 1..=degree {
let p = j as f64 / degree as f64;
let t = knots[i - 1] * (1.0 - p) + knots[i] * p;
let pt = curve.subs(t);
hint = match self.search_parameter(pt, Some(hint), INCLUDE_CURVE_TRIALS) {
Some(got) => got,
None => return false,
};
if !self.subs(hint.0, hint.1).near(&pt)
|| hint.0 < uknot_vec[0] - TOLERANCE
|| hint.0 - uknot_vec[0] > uknot_vec.range_length() + TOLERANCE
|| hint.1 < vknot_vec[0] - TOLERANCE
|| hint.1 - vknot_vec[0] > vknot_vec.range_length() + TOLERANCE
{
return false;
}
}
}
true
}
}
impl IncludeCurve<NURBSCurve<Vector4>> for NURBSSurface<Vector4> {
#[inline(always)]
fn include(&self, curve: &NURBSCurve<Vector4>) -> bool {
let pt = curve.front();
let mut hint = match self.search_parameter(pt, None, INCLUDE_CURVE_TRIALS) {
Some(got) => got,
None => return false,
};
let uknot_vec = self.uknot_vec();
let vknot_vec = self.vknot_vec();
let degree = curve.degree() * 6;
let (knots, _) = curve.knot_vec().to_single_multi();
for i in 1..knots.len() {
for j in 1..=degree {
let p = j as f64 / degree as f64;
let t = knots[i - 1] * (1.0 - p) + knots[i] * p;
let pt = curve.subs(t);
hint = match self.search_parameter(pt, Some(hint), INCLUDE_CURVE_TRIALS) {
Some(got) => got,
None => return false,
};
if !self.subs(hint.0, hint.1).near(&pt)
|| hint.0 < uknot_vec[0] - TOLERANCE
|| hint.0 - uknot_vec[0] > uknot_vec.range_length() + TOLERANCE
|| hint.1 < vknot_vec[0] - TOLERANCE
|| hint.1 - vknot_vec[0] > vknot_vec.range_length() + TOLERANCE
{
return false;
}
}
}
true
}
sourcepub const fn control_points(&self) -> &Vec<Vec<V>> ⓘ
pub const fn control_points(&self) -> &Vec<Vec<V>> ⓘ
Returns the reference of the vector of the control points
sourcepub fn control_point(&self, idx0: usize, idx1: usize) -> &V
pub fn control_point(&self, idx0: usize, idx1: usize) -> &V
Returns the reference of the control point corresponding to the index (idx0, idx1)
.
sourcepub fn transform_control_points<F: FnMut(&mut V)>(&mut self, f: F)
pub fn transform_control_points<F: FnMut(&mut V)>(&mut self, f: F)
Apply the given transformation to all control points.
sourcepub fn ctrl_pts_row_iter(
&self,
column_idx: usize
) -> impl ExactSizeIterator<Item = &V> + FusedIterator<Item = &V>
pub fn ctrl_pts_row_iter(
&self,
column_idx: usize
) -> impl ExactSizeIterator<Item = &V> + FusedIterator<Item = &V>
Returns the iterator over the control points in the column_idx
th row.
Examples
use truck_geometry::*;
let uknot_vec = KnotVec::bezier_knot(1);
let vknot_vec = KnotVec::bezier_knot(2);
let knot_vecs = (uknot_vec, vknot_vec);
let ctrl_pts = vec![
vec![Vector3::new(0.0, 0.0, 0.0), Vector3::new(1.0, 0.0, 1.0), Vector3::new(2.0, 0.0, 2.0)],
vec![Vector3::new(0.0, 1.0, 0.0), Vector3::new(1.0, 1.0, 1.0), Vector3::new(2.0, 1.0, 2.0)],
];
let bspsurface = BSplineSurface::new(knot_vecs, ctrl_pts);
let mut iter = bspsurface.ctrl_pts_row_iter(1);
assert_eq!(iter.next(), Some(&Vector3::new(1.0, 0.0, 1.0)));
assert_eq!(iter.next(), Some(&Vector3::new(1.0, 1.0, 1.0)));
assert_eq!(iter.next(), None);
sourcepub fn ctrl_pts_column_iter(&self, row_idx: usize) -> Iter<'_, V>
pub fn ctrl_pts_column_iter(&self, row_idx: usize) -> Iter<'_, V>
Returns the iterator over the control points in the row_idx
th row.
Examples
use truck_geometry::*;
let uknot_vec = KnotVec::bezier_knot(1);
let vknot_vec = KnotVec::bezier_knot(2);
let knot_vecs = (uknot_vec, vknot_vec);
let ctrl_pts = vec![
vec![Vector3::new(0.0, 0.0, 0.0), Vector3::new(1.0, 0.0, 1.0), Vector3::new(2.0, 0.0, 2.0)],
vec![Vector3::new(0.0, 1.0, 0.0), Vector3::new(1.0, 1.0, 1.0), Vector3::new(2.0, 1.0, 2.0)],
];
let bspsurface = BSplineSurface::new(knot_vecs, ctrl_pts);
let mut iter = bspsurface.ctrl_pts_column_iter(1);
assert_eq!(iter.next(), Some(&Vector3::new(0.0, 1.0, 0.0)));
assert_eq!(iter.next(), Some(&Vector3::new(1.0, 1.0, 1.0)));
assert_eq!(iter.next(), Some(&Vector3::new(2.0, 1.0, 2.0)));
assert_eq!(iter.next(), None);
sourcepub fn control_point_mut(&mut self, idx0: usize, idx1: usize) -> &mut V
pub fn control_point_mut(&mut self, idx0: usize, idx1: usize) -> &mut V
Returns the mutable reference of the control point corresponding to index (idx0, idx1)
.
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
sourcepub fn udegree(&self) -> usize
pub fn udegree(&self) -> usize
Returns the degrees of B-spline surface
Examples
use truck_geometry::*;
let uknot_vec = KnotVec::from(vec![0.0, 0.0, 1.0, 1.0]);
let vknot_vec = KnotVec::from(vec![0.0, 0.0, 0.0, 1.0, 1.0, 1.0]);
let knot_vecs = (uknot_vec, vknot_vec);
let ctrl_pts = vec![
vec![Vector3::new(0.0, 0.0, 0.0), Vector3::new(1.0, 0.0, 1.0), Vector3::new(2.0, 0.0, 2.0)],
vec![Vector3::new(0.0, 1.0, 0.0), Vector3::new(1.0, 1.0, 1.0), Vector3::new(2.0, 1.0, 2.0)],
];
let bspsurface = BSplineSurface::new(knot_vecs, ctrl_pts);
assert_eq!(bspsurface.udegree(), 1);
sourcepub fn vdegree(&self) -> usize
pub fn vdegree(&self) -> usize
Returns the degrees of B-spline surface
Examples
use truck_geometry::*;
let uknot_vec = KnotVec::from(vec![0.0, 0.0, 1.0, 1.0]);
let vknot_vec = KnotVec::from(vec![0.0, 0.0, 0.0, 1.0, 1.0, 1.0]);
let knot_vecs = (uknot_vec, vknot_vec);
let ctrl_pts = vec![
vec![Vector3::new(0.0, 0.0, 0.0), Vector3::new(1.0, 0.0, 1.0), Vector3::new(2.0, 0.0, 2.0)],
vec![Vector3::new(0.0, 1.0, 0.0), Vector3::new(1.0, 1.0, 1.0), Vector3::new(2.0, 1.0, 2.0)],
];
let bspsurface = BSplineSurface::new(knot_vecs, ctrl_pts);
assert_eq!(bspsurface.vdegree(), 2);
sourcepub fn degrees(&self) -> (usize, usize)
pub fn degrees(&self) -> (usize, usize)
Returns the degrees of B-spline surface
Examples
use truck_geometry::*;
let uknot_vec = KnotVec::from(vec![0.0, 0.0, 1.0, 1.0]);
let vknot_vec = KnotVec::from(vec![0.0, 0.0, 0.0, 1.0, 1.0, 1.0]);
let knot_vecs = (uknot_vec, vknot_vec);
let ctrl_pts = vec![
vec![Vector3::new(0.0, 0.0, 0.0), Vector3::new(1.0, 0.0, 1.0), Vector3::new(2.0, 0.0, 2.0)],
vec![Vector3::new(0.0, 1.0, 0.0), Vector3::new(1.0, 1.0, 1.0), Vector3::new(2.0, 1.0, 2.0)],
];
let bspsurface = BSplineSurface::new(knot_vecs, ctrl_pts);
assert_eq!(bspsurface.degrees(), (1, 2));
sourcepub fn is_clamped(&self) -> bool
pub fn is_clamped(&self) -> bool
Returns whether the knot vectors are clamped or not.
sourcepub fn parameter_range(&self) -> ((f64, f64), (f64, f64))
pub fn parameter_range(&self) -> ((f64, f64), (f64, f64))
The range of the parameter of the surface.
Examples found in repository?
518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809
fn search_nearest_parameter<H: Into<SPHint2D>>(
&self,
point: V::Point,
hint: H,
trials: usize,
) -> Option<(f64, f64)> {
let hint = match hint.into() {
SPHint2D::Parameter(x, y) => (x, y),
SPHint2D::Range(range0, range1) => {
algo::surface::presearch(self, point, (range0, range1), PRESEARCH_DIVISION)
}
SPHint2D::None => {
algo::surface::presearch(self, point, self.parameter_range(), PRESEARCH_DIVISION)
}
};
algo::surface::search_nearest_parameter(self, point, hint, trials)
}
}
impl<V> NURBSSurface<V>
where
V: Homogeneous<f64>,
V::Point:
MetricSpace<Metric = f64> + std::ops::Index<usize, Output = f64> + Bounded<f64> + Copy,
{
/// Returns the bounding box including all control points.
#[inline(always)]
pub fn roughly_bounding_box(&self) -> BoundingBox<V::Point> {
self.0
.control_points
.iter()
.flatten()
.map(|pt| pt.to_point())
.collect()
}
}
impl SearchParameter<D2> for NURBSSurface<Vector3> {
type Point = Point2;
/// Search the parameter `(u, v)` such that `self.subs(u, v).rational_projection()` is near `pt`.
/// If cannot find, then return `None`.
/// # Examples
/// ```
/// use truck_geometry::*;
/// let knot_vec = KnotVec::uniform_knot(2, 2);
/// let ctrl_pts = vec![
/// vec![Vector3::new(0.0, 0.0, 1.0), Vector3::new(0.1, 0.0, 0.5), Vector3::new(0.5, 0.0, 0.3), Vector3::new(1.0, 0.0, 1.0)],
/// vec![Vector3::new(0.0, 0.1, 0.1), Vector3::new(0.2, 0.2, 0.1), Vector3::new(0.4, 0.3, 0.4), Vector3::new(1.0, 0.3, 0.7)],
/// vec![Vector3::new(0.0, 0.5, 0.4), Vector3::new(0.3, 0.6, 0.5), Vector3::new(0.6, 0.4, 1.0), Vector3::new(1.0, 0.5, 0.4)],
/// vec![Vector3::new(0.0, 1.0, 1.0), Vector3::new(0.1, 1.0, 1.0), Vector3::new(0.5, 1.0, 0.5), Vector3::new(1.0, 1.0, 0.3)],
/// ];
/// let bspsurface = BSplineSurface::new((knot_vec.clone(), knot_vec), ctrl_pts);
/// let surface = NURBSSurface::new(bspsurface);
///
/// let pt = surface.subs(0.3, 0.7);
/// let (u, v) = surface.search_parameter(pt, Some((0.5, 0.5)), 100).unwrap();
/// assert_near!(surface.subs(u, v), pt);
/// ```
#[inline(always)]
fn search_parameter<H: Into<SPHint2D>>(
&self,
point: Point2,
hint: H,
trials: usize,
) -> Option<(f64, f64)> {
let hint = match hint.into() {
SPHint2D::Parameter(x, y) => (x, y),
SPHint2D::Range(range0, range1) => {
algo::surface::presearch(self, point, (range0, range1), PRESEARCH_DIVISION)
}
SPHint2D::None => {
algo::surface::presearch(self, point, self.parameter_range(), PRESEARCH_DIVISION)
}
};
algo::surface::search_parameter2d(self, point, hint, trials)
}
}
impl<V: Clone> Invertible for NURBSSurface<V> {
#[inline(always)]
fn invert(&mut self) { self.swap_axes(); }
#[inline(always)]
fn inverse(&self) -> Self {
let mut surface = self.clone();
surface.swap_axes();
surface
}
}
impl<V: Homogeneous<f64> + ControlPoint<f64, Diff = V>> ParametricSurface for NURBSSurface<V> {
type Point = V::Point;
type Vector = <V::Point as EuclideanSpace>::Diff;
#[inline(always)]
fn subs(&self, u: f64, v: f64) -> Self::Point { self.subs(u, v) }
#[inline(always)]
fn uder(&self, u: f64, v: f64) -> Self::Vector { self.uder(u, v) }
#[inline(always)]
fn vder(&self, u: f64, v: f64) -> Self::Vector { self.vder(u, v) }
#[inline(always)]
fn uuder(&self, u: f64, v: f64) -> Self::Vector { self.uuder(u, v) }
#[inline(always)]
fn uvder(&self, u: f64, v: f64) -> Self::Vector { self.uvder(u, v) }
#[inline(always)]
fn vvder(&self, u: f64, v: f64) -> Self::Vector { self.vvder(u, v) }
}
impl ParametricSurface3D for NURBSSurface<Vector4> {
#[inline(always)]
fn normal(&self, u: f64, v: f64) -> Vector3 {
let pt = self.0.subs(u, v);
let ud = self.0.uder(u, v);
let vd = self.0.vder(u, v);
pt.rat_der(ud).cross(pt.rat_der(vd)).normalize()
}
}
impl<V: Homogeneous<f64> + ControlPoint<f64, Diff = V>> ParameterDivision2D for NURBSSurface<V>
where V::Point: MetricSpace<Metric = f64> + HashGen<f64>
{
#[inline(always)]
fn parameter_division(
&self,
range: ((f64, f64), (f64, f64)),
tol: f64,
) -> (Vec<f64>, Vec<f64>) {
algo::surface::parameter_division(self, range, tol)
}
}
impl<V> BoundedSurface for NURBSSurface<V>
where Self: ParametricSurface
{
#[inline(always)]
fn parameter_range(&self) -> ((f64, f64), (f64, f64)) { self.parameter_range() }
}
impl IncludeCurve<NURBSCurve<Vector3>> for NURBSSurface<Vector3> {
#[inline(always)]
fn include(&self, curve: &NURBSCurve<Vector3>) -> bool {
let pt = curve.subs(curve.knot_vec()[0]);
let mut hint = match self.search_parameter(pt, None, INCLUDE_CURVE_TRIALS) {
Some(got) => got,
None => return false,
};
let uknot_vec = self.uknot_vec();
let vknot_vec = self.vknot_vec();
let degree = curve.degree() * 6;
let (knots, _) = curve.knot_vec().to_single_multi();
for i in 1..knots.len() {
for j in 1..=degree {
let p = j as f64 / degree as f64;
let t = knots[i - 1] * (1.0 - p) + knots[i] * p;
let pt = curve.subs(t);
hint = match self.search_parameter(pt, Some(hint), INCLUDE_CURVE_TRIALS) {
Some(got) => got,
None => return false,
};
if !self.subs(hint.0, hint.1).near(&pt)
|| hint.0 < uknot_vec[0] - TOLERANCE
|| hint.0 - uknot_vec[0] > uknot_vec.range_length() + TOLERANCE
|| hint.1 < vknot_vec[0] - TOLERANCE
|| hint.1 - vknot_vec[0] > vknot_vec.range_length() + TOLERANCE
{
return false;
}
}
}
true
}
}
impl IncludeCurve<BSplineCurve<Point3>> for NURBSSurface<Vector4> {
#[inline(always)]
fn include(&self, curve: &BSplineCurve<Point3>) -> bool {
let pt = curve.front();
let mut hint = match self.search_parameter(pt, None, INCLUDE_CURVE_TRIALS) {
Some(got) => got,
None => return false,
};
let uknot_vec = self.uknot_vec();
let vknot_vec = self.vknot_vec();
let degree = curve.degree() * 6;
let (knots, _) = curve.knot_vec().to_single_multi();
for i in 1..knots.len() {
for j in 1..=degree {
let p = j as f64 / degree as f64;
let t = knots[i - 1] * (1.0 - p) + knots[i] * p;
let pt = curve.subs(t);
hint = match self.search_parameter(pt, Some(hint), INCLUDE_CURVE_TRIALS) {
Some(got) => got,
None => return false,
};
if !self.subs(hint.0, hint.1).near(&pt)
|| hint.0 < uknot_vec[0] - TOLERANCE
|| hint.0 - uknot_vec[0] > uknot_vec.range_length() + TOLERANCE
|| hint.1 < vknot_vec[0] - TOLERANCE
|| hint.1 - vknot_vec[0] > vknot_vec.range_length() + TOLERANCE
{
return false;
}
}
}
true
}
}
impl IncludeCurve<NURBSCurve<Vector4>> for NURBSSurface<Vector4> {
#[inline(always)]
fn include(&self, curve: &NURBSCurve<Vector4>) -> bool {
let pt = curve.front();
let mut hint = match self.search_parameter(pt, None, INCLUDE_CURVE_TRIALS) {
Some(got) => got,
None => return false,
};
let uknot_vec = self.uknot_vec();
let vknot_vec = self.vknot_vec();
let degree = curve.degree() * 6;
let (knots, _) = curve.knot_vec().to_single_multi();
for i in 1..knots.len() {
for j in 1..=degree {
let p = j as f64 / degree as f64;
let t = knots[i - 1] * (1.0 - p) + knots[i] * p;
let pt = curve.subs(t);
hint = match self.search_parameter(pt, Some(hint), INCLUDE_CURVE_TRIALS) {
Some(got) => got,
None => return false,
};
if !self.subs(hint.0, hint.1).near(&pt)
|| hint.0 < uknot_vec[0] - TOLERANCE
|| hint.0 - uknot_vec[0] > uknot_vec.range_length() + TOLERANCE
|| hint.1 < vknot_vec[0] - TOLERANCE
|| hint.1 - vknot_vec[0] > vknot_vec.range_length() + TOLERANCE
{
return false;
}
}
}
true
}
}
impl<M, V: Copy> Transformed<M> for NURBSSurface<V>
where M: Copy + std::ops::Mul<V, Output = V>
{
#[inline(always)]
fn transform_by(&mut self, trans: M) {
self.0
.control_points
.iter_mut()
.flatten()
.for_each(move |v| *v = trans * *v)
}
}
impl SearchParameter<D2> for NURBSSurface<Vector4> {
type Point = Point3;
/// Search the parameter `(u, v)` such that `self.subs(u, v).rational_projection()` is near `pt`.
/// If cannot find, then return `None`.
/// # Examples
/// ```
/// use truck_geometry::*;
/// let knot_vec = KnotVec::uniform_knot(2, 2);
/// let ctrl_pts = vec![
/// vec![Vector4::new(0.0, 0.0, 0.0, 1.0), Vector4::new(0.1, 0.0, 0.5, 0.4), Vector4::new(1.0, 0.0, 0.6, 2.0), Vector4::new(0.4, 0.0, 0.4, 0.4)],
/// vec![Vector4::new(0.0, 0.2, 0.2, 2.0), Vector4::new(0.24, 0.24, 0.1, 1.2), Vector4::new(2.4, 1.8, 2.4, 0.6), Vector4::new(1.4, 0.42, 0.98, 1.4)],
/// vec![Vector4::new(0.0, 1.5, 1.2, 3.0), Vector4::new(1.02, 2.04, 1.7, 3.4), Vector4::new(0.42, 0.28, 0.7, 0.7), Vector4::new(0.6, 0.3, 0.0, 0.6)],
/// vec![Vector4::new(0.0, 1.0, 1.0, 1.0), Vector4::new(0.2, 2.0, 2.0, 2.0), Vector4::new(0.85, 1.7, 0.85, 1.7), Vector4::new(1.0, 1.0, 0.3, 1.0)],
/// ];
/// let bspsurface = BSplineSurface::new((knot_vec.clone(), knot_vec), ctrl_pts);
/// let surface = NURBSSurface::new(bspsurface);
///
/// let pt = surface.subs(0.3, 0.7);
/// let (u, v) = surface.search_parameter(pt, Some((0.5, 0.5)), 100).unwrap();
/// assert_near!(surface.subs(u, v), pt);
/// ```
fn search_parameter<H: Into<SPHint2D>>(
&self,
point: Point3,
hint: H,
trials: usize,
) -> Option<(f64, f64)> {
let hint = match hint.into() {
SPHint2D::Parameter(x, y) => (x, y),
SPHint2D::Range(range0, range1) => {
algo::surface::presearch(self, point, (range0, range1), PRESEARCH_DIVISION)
}
SPHint2D::None => {
algo::surface::presearch(self, point, self.parameter_range(), PRESEARCH_DIVISION)
}
};
algo::surface::search_parameter3d(self, point, hint, trials)
}
sourcepub fn column_curve(&self, row_idx: usize) -> NURBSCurve<V>where
V: Clone,
pub fn column_curve(&self, row_idx: usize) -> NURBSCurve<V>where
V: Clone,
Creates the curve whose control points are the idx
th column control points of self
.
sourcepub fn row_curve(&self, column_idx: usize) -> NURBSCurve<V>where
V: Clone,
pub fn row_curve(&self, column_idx: usize) -> NURBSCurve<V>where
V: Clone,
Creates the column sectional curve.
source§impl<V: Homogeneous<f64> + ControlPoint<f64, Diff = V>> NURBSSurface<V>
impl<V: Homogeneous<f64> + ControlPoint<f64, Diff = V>> NURBSSurface<V>
sourcepub fn subs(&self, u: f64, v: f64) -> V::Point
pub fn subs(&self, u: f64, v: f64) -> V::Point
Substitutes to a NURBS surface.
Examples found in repository?
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756
pub fn get_closure(&self) -> impl Fn(f64, f64) -> V::Point + '_ { move |u, v| self.subs(u, v) }
}
impl<V: Homogeneous<f64> + ControlPoint<f64, Diff = V>> NURBSSurface<V>
where V::Point: Tolerance
{
/// Returns whether constant curve or not, i.e. all control points are same or not.
/// # Examples
/// ```
/// use truck_geometry::*;
/// let uknot_vec = KnotVec::bezier_knot(1);
/// let vknot_vec = KnotVec::bezier_knot(2);
/// let pt = Vector3::new(1.0, 2.0, 1.0);
/// // allows differences upto scalars
/// let ctrl_pts = vec![
/// vec![pt.clone(), pt.clone() * 2.0, pt.clone() * 3.0],
/// vec![pt.clone() * 0.5, pt.clone() * 0.25, pt.clone() * 0.125],
/// ];
/// let mut surface = NURBSSurface::new(BSplineSurface::new((uknot_vec, vknot_vec), ctrl_pts));
/// assert!(surface.is_const());
///
/// *surface.control_point_mut(1, 2) = Vector3::new(2.0, 3.0, 1.0);
/// assert!(!surface.is_const());
/// ```
#[inline(always)]
pub fn is_const(&self) -> bool {
let pt = self.0.control_points[0][0].to_point();
for vec in self.0.control_points.iter().flat_map(|pts| pts.iter()) {
if !vec.to_point().near(&pt) {
return false;
}
}
true
}
/// Determines whether `self` and `other` is near as the B-spline rational surfaces or not.
///
/// Divides each knot domain into the number of degree equal parts,
/// and check `|self(u, v) - other(u, v)| < TOLERANCE` for each end points `(u, v)`.
/// # Examples
/// ```
/// use truck_geometry::*;
/// let knot_vecs = (KnotVec::bezier_knot(3), KnotVec::bezier_knot(2));
/// let ctrl_pts = vec![
/// vec![Vector3::new(0.0, 0.0, 1.0), Vector3::new(0.5, -1.0, 2.0), Vector3::new(1.0, 0.0, 1.0)],
/// vec![Vector3::new(0.0, 1.0, 1.0), Vector3::new(0.5, 1.0, 1.0), Vector3::new(1.0, 1.0, 1.0)],
/// vec![Vector3::new(0.0, 2.0, 1.0), Vector3::new(0.5, 2.0, 3.0), Vector3::new(1.0, 2.0, 1.0)],
/// vec![Vector3::new(0.0, 3.0, 1.0), Vector3::new(0.5, 3.5, 2.0), Vector3::new(1.0, 3.0, 1.0)],
/// ];
/// let surface0 = NURBSSurface::new(BSplineSurface::new(knot_vecs, ctrl_pts));
/// let mut surface1 = surface0.clone();
/// assert!(surface0.near_as_surface(&surface1));
///
/// *surface1.control_point_mut(1, 1) = Vector3::new(0.5, 1.0, 0.9);
/// assert!(!surface0.near_as_surface(&surface1));
/// ```
#[inline(always)]
pub fn near_as_surface(&self, other: &Self) -> bool {
self.0
.sub_near_as_surface(&other.0, 2, move |x, y| x.to_point().near(&y.to_point()))
}
/// Determines whether `self` and `other` is near in square order as the B-spline rational
/// surfaces or not.
///
/// Divides each knot domain into the number of degree equal parts,
/// and check `|self(u, v) - other(u, v)| < TOLERANCE` for each end points `(u, v)`.
/// # Examples
/// ```
/// use truck_geometry::*;
/// let eps = TOLERANCE;
/// let knot_vecs = (KnotVec::bezier_knot(3), KnotVec::bezier_knot(2));
/// let ctrl_pts = vec![
/// vec![Vector3::new(0.0, 0.0, 1.0), Vector3::new(0.5, -1.0, 2.0), Vector3::new(1.0, 0.0, 1.0)],
/// vec![Vector3::new(0.0, 1.0, 1.0), Vector3::new(0.5, 1.0, 1.0), Vector3::new(1.0, 1.0, 1.0)],
/// vec![Vector3::new(0.0, 2.0, 1.0), Vector3::new(0.5, 2.0, 3.0), Vector3::new(1.0, 2.0, 1.0)],
/// vec![Vector3::new(0.0, 3.0, 1.0), Vector3::new(0.5, 3.5, 2.0), Vector3::new(1.0, 3.0, 1.0)],
/// ];
/// let surface0 = NURBSSurface::new(BSplineSurface::new(knot_vecs, ctrl_pts));
/// let mut surface1 = surface0.clone();
/// assert!(surface0.near_as_surface(&surface1));
///
/// *surface1.control_point_mut(1, 1) = Vector3::new(0.5, 1.0, 1.0 - eps);
/// assert!(surface0.near_as_surface(&surface1));
/// assert!(!surface0.near2_as_surface(&surface1));
/// ```
#[inline(always)]
pub fn near2_as_surface(&self, other: &Self) -> bool {
self.0
.sub_near_as_surface(&other.0, 2, move |x, y| x.to_point().near2(&y.to_point()))
}
}
impl<V: Homogeneous<f64> + ControlPoint<f64, Diff = V> + Tolerance> NURBSSurface<V> {
/// Adds a knot `x` of the first parameter `u`, and do not change `self` as a surface.
#[inline(always)]
pub fn add_uknot(&mut self, x: f64) -> &mut Self {
self.0.add_uknot(x);
self
}
/// Adds a knot `x` of the first parameter `u`, and do not change `self` as a surface.
#[inline(always)]
pub fn add_vknot(&mut self, x: f64) -> &mut Self {
self.0.add_vknot(x);
self
}
/// Removes the uknot corresponding to the indice `idx`, and do not change `self` as a curve.
/// If the knot cannot be removed, returns
/// [`Error::CannotRemoveKnot`](./errors/enum.Error.html#variant.CannotRemoveKnot).
#[inline(always)]
pub fn try_remove_uknot(&mut self, idx: usize) -> Result<&mut Self> {
match self.0.try_remove_uknot(idx) {
Ok(_) => Ok(self),
Err(error) => Err(error),
}
}
/// Removes the uknot 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`.
#[inline(always)]
pub fn remove_uknot(&mut self, idx: usize) -> &mut Self {
self.0.remove_uknot(idx);
self
}
/// Removes the uknot corresponding to the indice `idx`, and do not change `self` as a curve.
/// If the knot cannot be removed, returns
/// [`Error::CannotRemoveKnot`](./errors/enum.Error.html#variant.CannotRemoveKnot).
#[inline(always)]
pub fn try_remove_vknot(&mut self, idx: usize) -> Result<&mut Self> {
match self.0.try_remove_vknot(idx) {
Ok(_) => Ok(self),
Err(error) => Err(error),
}
}
/// Removes the uknot 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`.
#[inline(always)]
pub fn remove_vknot(&mut self, idx: usize) -> &mut Self {
self.0.remove_vknot(idx);
self
}
/// Elevates the udegree.
#[inline(always)]
pub fn elevate_udegree(&mut self) -> &mut Self {
self.0.elevate_udegree();
self
}
/// Elevates the vdegree.
#[inline(always)]
pub fn elevate_vdegree(&mut self) -> &mut Self {
self.0.elevate_vdegree();
self
}
/// Aligns the udegree with the same degrees.
#[inline(always)]
pub fn syncro_uvdegrees(&mut self) -> &mut Self {
self.0.syncro_uvdegrees();
self
}
/// Makes the uknot vector and the vknot vector the same knot vector.
#[inline(always)]
pub fn syncro_uvknots(&mut self) -> &mut Self {
self.0.syncro_uvknots();
self
}
/// Cuts the surface into two surfaces at the parameter `u`
#[inline(always)]
pub fn ucut(&mut self, u: f64) -> Self { Self::new(self.0.ucut(u)) }
/// Cuts the surface into two surfaces at the parameter `v`
#[inline(always)]
pub fn vcut(&mut self, v: f64) -> Self { Self::new(self.0.vcut(v)) }
/// Normalizes the knot vectors
#[inline(always)]
pub fn knot_normalize(&mut self) -> &mut Self {
self.0.knot_normalize();
self
}
/// Translates the knot vectors.
#[inline(always)]
pub fn knot_translate(&mut self, x: f64, y: f64) -> &mut Self {
self.0.knot_translate(x, y);
self
}
/// Removes knots in order from the back
#[inline(always)]
pub fn optimize(&mut self) -> &mut Self {
self.0.optimize();
self
}
/// Get the boundary by four splitted curves.
/// # Example
/// ```
/// use truck_geometry::*;
/// let knot_vecs = (KnotVec::bezier_knot(3), KnotVec::bezier_knot(2));
/// let ctrl_pts = vec![
/// vec![Vector3::new(0.0, 0.0, 1.0), Vector3::new(0.5, -1.0, 2.0), Vector3::new(1.0, 0.0, 1.0)],
/// vec![Vector3::new(0.0, 1.0, 2.0), Vector3::new(0.5, 1.0, 3.0), Vector3::new(1.0, 1.0, 2.0)],
/// vec![Vector3::new(0.0, 2.0, 2.0), Vector3::new(0.5, 2.0, 3.0), Vector3::new(1.0, 2.0, 2.0)],
/// vec![Vector3::new(0.0, 3.0, 1.0), Vector3::new(0.5, 3.5, 2.0), Vector3::new(1.0, 3.0, 1.0)],
/// ];
/// let bspsurface = NURBSSurface::new(BSplineSurface::new(knot_vecs, ctrl_pts));
/// let curves = bspsurface.splitted_boundary();
/// assert_eq!(
/// curves[0].control_points(),
/// &vec![
/// Vector3::new(0.0, 0.0, 1.0),
/// Vector3::new(0.0, 1.0, 2.0),
/// Vector3::new(0.0, 2.0, 2.0),
/// Vector3::new(0.0, 3.0, 1.0),
/// ],
/// );
/// assert_eq!(
/// curves[1].control_points(),
/// &vec![
/// Vector3::new(0.0, 3.0, 1.0),
/// Vector3::new(0.5, 3.5, 2.0),
/// Vector3::new(1.0, 3.0, 1.0),
/// ],
/// );
/// assert_eq!(
/// curves[2].control_points(),
/// &vec![
/// Vector3::new(1.0, 3.0, 1.0),
/// Vector3::new(1.0, 2.0, 2.0),
/// Vector3::new(1.0, 1.0, 2.0),
/// Vector3::new(1.0, 0.0, 1.0),
/// ],
/// );
/// assert_eq!(
/// curves[3].control_points(),
/// &vec![
/// Vector3::new(1.0, 0.0, 1.0),
/// Vector3::new(0.5, -1.0, 2.0),
/// Vector3::new(0.0, 0.0, 1.0),
/// ],
/// );
/// ```
#[inline(always)]
pub fn splitted_boundary(&self) -> [NURBSCurve<V>; 4] {
std::convert::TryFrom::try_from(
self.0
.splitted_boundary()
.iter()
.cloned()
.map(NURBSCurve::new)
.collect::<Vec<_>>(),
)
.unwrap()
}
/// Extracts the boundary of surface
#[inline(always)]
pub fn boundary(&self) -> NURBSCurve<V> { NURBSCurve::new(self.0.boundary()) }
}
impl<V: Homogeneous<f64>> SearchNearestParameter<D2> for NURBSSurface<V>
where
Self: ParametricSurface<Point = V::Point, Vector = <V::Point as EuclideanSpace>::Diff>,
V::Point: EuclideanSpace<Scalar = f64> + MetricSpace<Metric = f64>,
<V::Point as EuclideanSpace>::Diff: InnerSpace<Scalar = f64> + Tolerance,
{
type Point = V::Point;
/// Searches the parameter `(u, v)` which minimize `|self(u, v) - point|` by Newton's method
/// with initial guess `(u0, v0)`. If the repeated trial does not converge, then returns `None`.
/// # Examples
/// ```
/// use truck_geometry::*;
/// let knot_vecs = (KnotVec::bezier_knot(3), KnotVec::bezier_knot(2));
/// let ctrl_pts = vec![
/// vec![Vector3::new(0.0, 0.0, 1.0), Vector3::new(1.0, -2.0, 2.0), Vector3::new(1.0, 0.0, 1.0)],
/// vec![Vector3::new(0.0, 2.0, 2.0), Vector3::new(2.0, 4.0, 4.0), Vector3::new(2.0, 2.0, 2.0)],
/// vec![Vector3::new(0.0, 4.0, 2.0), Vector3::new(2.0, 8.0, 4.0), Vector3::new(2.0, 4.0, 2.0)],
/// vec![Vector3::new(0.0, 3.0, 1.0), Vector3::new(1.0, 7.0, 2.0), Vector3::new(1.0, 3.0, 1.0)],
/// ];
/// let surface = NURBSSurface::new(BSplineSurface::new(knot_vecs, ctrl_pts));
/// let pt = surface.subs(0.3, 0.7);
/// let (u, v) = surface.search_nearest_parameter(pt, Some((0.5, 0.5)), 100).unwrap();
/// assert!(u.near(&0.3) && v.near(&0.7));
/// ```
/// # Remarks
/// It may converge to a local solution depending on the hint.
/// cf. [`BSplineCurve::search_rational_nearest_parameter`](struct.BSplineCurve.html#method.search_rational_nearest_parameter)
#[inline(always)]
fn search_nearest_parameter<H: Into<SPHint2D>>(
&self,
point: V::Point,
hint: H,
trials: usize,
) -> Option<(f64, f64)> {
let hint = match hint.into() {
SPHint2D::Parameter(x, y) => (x, y),
SPHint2D::Range(range0, range1) => {
algo::surface::presearch(self, point, (range0, range1), PRESEARCH_DIVISION)
}
SPHint2D::None => {
algo::surface::presearch(self, point, self.parameter_range(), PRESEARCH_DIVISION)
}
};
algo::surface::search_nearest_parameter(self, point, hint, trials)
}
}
impl<V> NURBSSurface<V>
where
V: Homogeneous<f64>,
V::Point:
MetricSpace<Metric = f64> + std::ops::Index<usize, Output = f64> + Bounded<f64> + Copy,
{
/// Returns the bounding box including all control points.
#[inline(always)]
pub fn roughly_bounding_box(&self) -> BoundingBox<V::Point> {
self.0
.control_points
.iter()
.flatten()
.map(|pt| pt.to_point())
.collect()
}
}
impl SearchParameter<D2> for NURBSSurface<Vector3> {
type Point = Point2;
/// Search the parameter `(u, v)` such that `self.subs(u, v).rational_projection()` is near `pt`.
/// If cannot find, then return `None`.
/// # Examples
/// ```
/// use truck_geometry::*;
/// let knot_vec = KnotVec::uniform_knot(2, 2);
/// let ctrl_pts = vec![
/// vec![Vector3::new(0.0, 0.0, 1.0), Vector3::new(0.1, 0.0, 0.5), Vector3::new(0.5, 0.0, 0.3), Vector3::new(1.0, 0.0, 1.0)],
/// vec![Vector3::new(0.0, 0.1, 0.1), Vector3::new(0.2, 0.2, 0.1), Vector3::new(0.4, 0.3, 0.4), Vector3::new(1.0, 0.3, 0.7)],
/// vec![Vector3::new(0.0, 0.5, 0.4), Vector3::new(0.3, 0.6, 0.5), Vector3::new(0.6, 0.4, 1.0), Vector3::new(1.0, 0.5, 0.4)],
/// vec![Vector3::new(0.0, 1.0, 1.0), Vector3::new(0.1, 1.0, 1.0), Vector3::new(0.5, 1.0, 0.5), Vector3::new(1.0, 1.0, 0.3)],
/// ];
/// let bspsurface = BSplineSurface::new((knot_vec.clone(), knot_vec), ctrl_pts);
/// let surface = NURBSSurface::new(bspsurface);
///
/// let pt = surface.subs(0.3, 0.7);
/// let (u, v) = surface.search_parameter(pt, Some((0.5, 0.5)), 100).unwrap();
/// assert_near!(surface.subs(u, v), pt);
/// ```
#[inline(always)]
fn search_parameter<H: Into<SPHint2D>>(
&self,
point: Point2,
hint: H,
trials: usize,
) -> Option<(f64, f64)> {
let hint = match hint.into() {
SPHint2D::Parameter(x, y) => (x, y),
SPHint2D::Range(range0, range1) => {
algo::surface::presearch(self, point, (range0, range1), PRESEARCH_DIVISION)
}
SPHint2D::None => {
algo::surface::presearch(self, point, self.parameter_range(), PRESEARCH_DIVISION)
}
};
algo::surface::search_parameter2d(self, point, hint, trials)
}
}
impl<V: Clone> Invertible for NURBSSurface<V> {
#[inline(always)]
fn invert(&mut self) { self.swap_axes(); }
#[inline(always)]
fn inverse(&self) -> Self {
let mut surface = self.clone();
surface.swap_axes();
surface
}
}
impl<V: Homogeneous<f64> + ControlPoint<f64, Diff = V>> ParametricSurface for NURBSSurface<V> {
type Point = V::Point;
type Vector = <V::Point as EuclideanSpace>::Diff;
#[inline(always)]
fn subs(&self, u: f64, v: f64) -> Self::Point { self.subs(u, v) }
#[inline(always)]
fn uder(&self, u: f64, v: f64) -> Self::Vector { self.uder(u, v) }
#[inline(always)]
fn vder(&self, u: f64, v: f64) -> Self::Vector { self.vder(u, v) }
#[inline(always)]
fn uuder(&self, u: f64, v: f64) -> Self::Vector { self.uuder(u, v) }
#[inline(always)]
fn uvder(&self, u: f64, v: f64) -> Self::Vector { self.uvder(u, v) }
#[inline(always)]
fn vvder(&self, u: f64, v: f64) -> Self::Vector { self.vvder(u, v) }
}
impl ParametricSurface3D for NURBSSurface<Vector4> {
#[inline(always)]
fn normal(&self, u: f64, v: f64) -> Vector3 {
let pt = self.0.subs(u, v);
let ud = self.0.uder(u, v);
let vd = self.0.vder(u, v);
pt.rat_der(ud).cross(pt.rat_der(vd)).normalize()
}
}
impl<V: Homogeneous<f64> + ControlPoint<f64, Diff = V>> ParameterDivision2D for NURBSSurface<V>
where V::Point: MetricSpace<Metric = f64> + HashGen<f64>
{
#[inline(always)]
fn parameter_division(
&self,
range: ((f64, f64), (f64, f64)),
tol: f64,
) -> (Vec<f64>, Vec<f64>) {
algo::surface::parameter_division(self, range, tol)
}
}
impl<V> BoundedSurface for NURBSSurface<V>
where Self: ParametricSurface
{
#[inline(always)]
fn parameter_range(&self) -> ((f64, f64), (f64, f64)) { self.parameter_range() }
}
impl IncludeCurve<NURBSCurve<Vector3>> for NURBSSurface<Vector3> {
#[inline(always)]
fn include(&self, curve: &NURBSCurve<Vector3>) -> bool {
let pt = curve.subs(curve.knot_vec()[0]);
let mut hint = match self.search_parameter(pt, None, INCLUDE_CURVE_TRIALS) {
Some(got) => got,
None => return false,
};
let uknot_vec = self.uknot_vec();
let vknot_vec = self.vknot_vec();
let degree = curve.degree() * 6;
let (knots, _) = curve.knot_vec().to_single_multi();
for i in 1..knots.len() {
for j in 1..=degree {
let p = j as f64 / degree as f64;
let t = knots[i - 1] * (1.0 - p) + knots[i] * p;
let pt = curve.subs(t);
hint = match self.search_parameter(pt, Some(hint), INCLUDE_CURVE_TRIALS) {
Some(got) => got,
None => return false,
};
if !self.subs(hint.0, hint.1).near(&pt)
|| hint.0 < uknot_vec[0] - TOLERANCE
|| hint.0 - uknot_vec[0] > uknot_vec.range_length() + TOLERANCE
|| hint.1 < vknot_vec[0] - TOLERANCE
|| hint.1 - vknot_vec[0] > vknot_vec.range_length() + TOLERANCE
{
return false;
}
}
}
true
}
}
impl IncludeCurve<BSplineCurve<Point3>> for NURBSSurface<Vector4> {
#[inline(always)]
fn include(&self, curve: &BSplineCurve<Point3>) -> bool {
let pt = curve.front();
let mut hint = match self.search_parameter(pt, None, INCLUDE_CURVE_TRIALS) {
Some(got) => got,
None => return false,
};
let uknot_vec = self.uknot_vec();
let vknot_vec = self.vknot_vec();
let degree = curve.degree() * 6;
let (knots, _) = curve.knot_vec().to_single_multi();
for i in 1..knots.len() {
for j in 1..=degree {
let p = j as f64 / degree as f64;
let t = knots[i - 1] * (1.0 - p) + knots[i] * p;
let pt = curve.subs(t);
hint = match self.search_parameter(pt, Some(hint), INCLUDE_CURVE_TRIALS) {
Some(got) => got,
None => return false,
};
if !self.subs(hint.0, hint.1).near(&pt)
|| hint.0 < uknot_vec[0] - TOLERANCE
|| hint.0 - uknot_vec[0] > uknot_vec.range_length() + TOLERANCE
|| hint.1 < vknot_vec[0] - TOLERANCE
|| hint.1 - vknot_vec[0] > vknot_vec.range_length() + TOLERANCE
{
return false;
}
}
}
true
}
}
impl IncludeCurve<NURBSCurve<Vector4>> for NURBSSurface<Vector4> {
#[inline(always)]
fn include(&self, curve: &NURBSCurve<Vector4>) -> bool {
let pt = curve.front();
let mut hint = match self.search_parameter(pt, None, INCLUDE_CURVE_TRIALS) {
Some(got) => got,
None => return false,
};
let uknot_vec = self.uknot_vec();
let vknot_vec = self.vknot_vec();
let degree = curve.degree() * 6;
let (knots, _) = curve.knot_vec().to_single_multi();
for i in 1..knots.len() {
for j in 1..=degree {
let p = j as f64 / degree as f64;
let t = knots[i - 1] * (1.0 - p) + knots[i] * p;
let pt = curve.subs(t);
hint = match self.search_parameter(pt, Some(hint), INCLUDE_CURVE_TRIALS) {
Some(got) => got,
None => return false,
};
if !self.subs(hint.0, hint.1).near(&pt)
|| hint.0 < uknot_vec[0] - TOLERANCE
|| hint.0 - uknot_vec[0] > uknot_vec.range_length() + TOLERANCE
|| hint.1 < vknot_vec[0] - TOLERANCE
|| hint.1 - vknot_vec[0] > vknot_vec.range_length() + TOLERANCE
{
return false;
}
}
}
true
}
sourcepub fn uder(&self, u: f64, v: f64) -> <V::Point as EuclideanSpace>::Diff
pub fn uder(&self, u: f64, v: f64) -> <V::Point as EuclideanSpace>::Diff
Substitutes derived NURBS surface by the first parameter u
.
sourcepub fn vder(&self, u: f64, v: f64) -> <V::Point as EuclideanSpace>::Diff
pub fn vder(&self, u: f64, v: f64) -> <V::Point as EuclideanSpace>::Diff
Substitutes derived NURBS surface by the first parameter v
.
sourcepub fn uuder(&self, u: f64, v: f64) -> <V::Point as EuclideanSpace>::Diff
pub fn uuder(&self, u: f64, v: f64) -> <V::Point as EuclideanSpace>::Diff
Substitutes 2nd-ord derived NURBS surface by the first parameter u
.
sourcepub fn vvder(&self, u: f64, v: f64) -> <V::Point as EuclideanSpace>::Diff
pub fn vvder(&self, u: f64, v: f64) -> <V::Point as EuclideanSpace>::Diff
Substitutes 2nd-ord derived NURBS surface by the first parameter v
.
source§impl<V: Homogeneous<f64> + ControlPoint<f64, Diff = V>> NURBSSurface<V>where
V::Point: Tolerance,
impl<V: Homogeneous<f64> + ControlPoint<f64, Diff = V>> NURBSSurface<V>where
V::Point: Tolerance,
sourcepub fn is_const(&self) -> bool
pub fn is_const(&self) -> bool
Returns whether constant curve or not, i.e. all control points are same or not.
Examples
use truck_geometry::*;
let uknot_vec = KnotVec::bezier_knot(1);
let vknot_vec = KnotVec::bezier_knot(2);
let pt = Vector3::new(1.0, 2.0, 1.0);
// allows differences upto scalars
let ctrl_pts = vec![
vec![pt.clone(), pt.clone() * 2.0, pt.clone() * 3.0],
vec![pt.clone() * 0.5, pt.clone() * 0.25, pt.clone() * 0.125],
];
let mut surface = NURBSSurface::new(BSplineSurface::new((uknot_vec, vknot_vec), ctrl_pts));
assert!(surface.is_const());
*surface.control_point_mut(1, 2) = Vector3::new(2.0, 3.0, 1.0);
assert!(!surface.is_const());
sourcepub fn near_as_surface(&self, other: &Self) -> bool
pub fn near_as_surface(&self, other: &Self) -> bool
Determines whether self
and other
is near as the B-spline rational surfaces or not.
Divides each knot domain into the number of degree equal parts,
and check |self(u, v) - other(u, v)| < TOLERANCE
for each end points (u, v)
.
Examples
use truck_geometry::*;
let knot_vecs = (KnotVec::bezier_knot(3), KnotVec::bezier_knot(2));
let ctrl_pts = vec![
vec![Vector3::new(0.0, 0.0, 1.0), Vector3::new(0.5, -1.0, 2.0), Vector3::new(1.0, 0.0, 1.0)],
vec![Vector3::new(0.0, 1.0, 1.0), Vector3::new(0.5, 1.0, 1.0), Vector3::new(1.0, 1.0, 1.0)],
vec![Vector3::new(0.0, 2.0, 1.0), Vector3::new(0.5, 2.0, 3.0), Vector3::new(1.0, 2.0, 1.0)],
vec![Vector3::new(0.0, 3.0, 1.0), Vector3::new(0.5, 3.5, 2.0), Vector3::new(1.0, 3.0, 1.0)],
];
let surface0 = NURBSSurface::new(BSplineSurface::new(knot_vecs, ctrl_pts));
let mut surface1 = surface0.clone();
assert!(surface0.near_as_surface(&surface1));
*surface1.control_point_mut(1, 1) = Vector3::new(0.5, 1.0, 0.9);
assert!(!surface0.near_as_surface(&surface1));
sourcepub fn near2_as_surface(&self, other: &Self) -> bool
pub fn near2_as_surface(&self, other: &Self) -> bool
Determines whether self
and other
is near in square order as the B-spline rational
surfaces or not.
Divides each knot domain into the number of degree equal parts,
and check |self(u, v) - other(u, v)| < TOLERANCE
for each end points (u, v)
.
Examples
use truck_geometry::*;
let eps = TOLERANCE;
let knot_vecs = (KnotVec::bezier_knot(3), KnotVec::bezier_knot(2));
let ctrl_pts = vec![
vec![Vector3::new(0.0, 0.0, 1.0), Vector3::new(0.5, -1.0, 2.0), Vector3::new(1.0, 0.0, 1.0)],
vec![Vector3::new(0.0, 1.0, 1.0), Vector3::new(0.5, 1.0, 1.0), Vector3::new(1.0, 1.0, 1.0)],
vec![Vector3::new(0.0, 2.0, 1.0), Vector3::new(0.5, 2.0, 3.0), Vector3::new(1.0, 2.0, 1.0)],
vec![Vector3::new(0.0, 3.0, 1.0), Vector3::new(0.5, 3.5, 2.0), Vector3::new(1.0, 3.0, 1.0)],
];
let surface0 = NURBSSurface::new(BSplineSurface::new(knot_vecs, ctrl_pts));
let mut surface1 = surface0.clone();
assert!(surface0.near_as_surface(&surface1));
*surface1.control_point_mut(1, 1) = Vector3::new(0.5, 1.0, 1.0 - eps);
assert!(surface0.near_as_surface(&surface1));
assert!(!surface0.near2_as_surface(&surface1));
source§impl<V: Homogeneous<f64> + ControlPoint<f64, Diff = V> + Tolerance> NURBSSurface<V>
impl<V: Homogeneous<f64> + ControlPoint<f64, Diff = V> + Tolerance> NURBSSurface<V>
sourcepub fn add_uknot(&mut self, x: f64) -> &mut Self
pub fn add_uknot(&mut self, x: f64) -> &mut Self
Adds a knot x
of the first parameter u
, and do not change self
as a surface.
sourcepub fn add_vknot(&mut self, x: f64) -> &mut Self
pub fn add_vknot(&mut self, x: f64) -> &mut Self
Adds a knot x
of the first parameter u
, and do not change self
as a surface.
sourcepub fn try_remove_uknot(&mut self, idx: usize) -> Result<&mut Self>
pub fn try_remove_uknot(&mut self, idx: usize) -> Result<&mut Self>
Removes the uknot corresponding to the indice idx
, and do not change self
as a curve.
If the knot cannot be removed, returns
Error::CannotRemoveKnot
.
sourcepub fn remove_uknot(&mut self, idx: usize) -> &mut Self
pub fn remove_uknot(&mut self, idx: usize) -> &mut Self
Removes the uknot 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
.
sourcepub fn try_remove_vknot(&mut self, idx: usize) -> Result<&mut Self>
pub fn try_remove_vknot(&mut self, idx: usize) -> Result<&mut Self>
Removes the uknot corresponding to the indice idx
, and do not change self
as a curve.
If the knot cannot be removed, returns
Error::CannotRemoveKnot
.
sourcepub fn remove_vknot(&mut self, idx: usize) -> &mut Self
pub fn remove_vknot(&mut self, idx: usize) -> &mut Self
Removes the uknot 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
.
sourcepub fn elevate_udegree(&mut self) -> &mut Self
pub fn elevate_udegree(&mut self) -> &mut Self
Elevates the udegree.
sourcepub fn elevate_vdegree(&mut self) -> &mut Self
pub fn elevate_vdegree(&mut self) -> &mut Self
Elevates the vdegree.
sourcepub fn syncro_uvdegrees(&mut self) -> &mut Self
pub fn syncro_uvdegrees(&mut self) -> &mut Self
Aligns the udegree with the same degrees.
sourcepub fn syncro_uvknots(&mut self) -> &mut Self
pub fn syncro_uvknots(&mut self) -> &mut Self
Makes the uknot vector and the vknot vector the same knot vector.
sourcepub fn knot_normalize(&mut self) -> &mut Self
pub fn knot_normalize(&mut self) -> &mut Self
Normalizes the knot vectors
sourcepub fn knot_translate(&mut self, x: f64, y: f64) -> &mut Self
pub fn knot_translate(&mut self, x: f64, y: f64) -> &mut Self
Translates the knot vectors.
sourcepub fn splitted_boundary(&self) -> [NURBSCurve<V>; 4]
pub fn splitted_boundary(&self) -> [NURBSCurve<V>; 4]
Get the boundary by four splitted curves.
Example
use truck_geometry::*;
let knot_vecs = (KnotVec::bezier_knot(3), KnotVec::bezier_knot(2));
let ctrl_pts = vec![
vec![Vector3::new(0.0, 0.0, 1.0), Vector3::new(0.5, -1.0, 2.0), Vector3::new(1.0, 0.0, 1.0)],
vec![Vector3::new(0.0, 1.0, 2.0), Vector3::new(0.5, 1.0, 3.0), Vector3::new(1.0, 1.0, 2.0)],
vec![Vector3::new(0.0, 2.0, 2.0), Vector3::new(0.5, 2.0, 3.0), Vector3::new(1.0, 2.0, 2.0)],
vec![Vector3::new(0.0, 3.0, 1.0), Vector3::new(0.5, 3.5, 2.0), Vector3::new(1.0, 3.0, 1.0)],
];
let bspsurface = NURBSSurface::new(BSplineSurface::new(knot_vecs, ctrl_pts));
let curves = bspsurface.splitted_boundary();
assert_eq!(
curves[0].control_points(),
&vec![
Vector3::new(0.0, 0.0, 1.0),
Vector3::new(0.0, 1.0, 2.0),
Vector3::new(0.0, 2.0, 2.0),
Vector3::new(0.0, 3.0, 1.0),
],
);
assert_eq!(
curves[1].control_points(),
&vec![
Vector3::new(0.0, 3.0, 1.0),
Vector3::new(0.5, 3.5, 2.0),
Vector3::new(1.0, 3.0, 1.0),
],
);
assert_eq!(
curves[2].control_points(),
&vec![
Vector3::new(1.0, 3.0, 1.0),
Vector3::new(1.0, 2.0, 2.0),
Vector3::new(1.0, 1.0, 2.0),
Vector3::new(1.0, 0.0, 1.0),
],
);
assert_eq!(
curves[3].control_points(),
&vec![
Vector3::new(1.0, 0.0, 1.0),
Vector3::new(0.5, -1.0, 2.0),
Vector3::new(0.0, 0.0, 1.0),
],
);
sourcepub fn boundary(&self) -> NURBSCurve<V>
pub fn boundary(&self) -> NURBSCurve<V>
Extracts the boundary of surface
source§impl<V> NURBSSurface<V>where
V: Homogeneous<f64>,
V::Point: MetricSpace<Metric = f64> + Index<usize, Output = f64> + Bounded<f64> + Copy,
impl<V> NURBSSurface<V>where
V: Homogeneous<f64>,
V::Point: MetricSpace<Metric = f64> + Index<usize, Output = f64> + Bounded<f64> + Copy,
sourcepub fn roughly_bounding_box(&self) -> BoundingBox<V::Point>
pub fn roughly_bounding_box(&self) -> BoundingBox<V::Point>
Returns the bounding box including all control points.
Trait Implementations§
source§impl<V> BoundedSurface for NURBSSurface<V>where
Self: ParametricSurface,
impl<V> BoundedSurface for NURBSSurface<V>where
Self: ParametricSurface,
source§impl<V: Clone> Clone for NURBSSurface<V>
impl<V: Clone> Clone for NURBSSurface<V>
source§fn clone(&self) -> NURBSSurface<V>
fn clone(&self) -> NURBSSurface<V>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<V: Debug> Debug for NURBSSurface<V>
impl<V: Debug> Debug for NURBSSurface<V>
source§impl<'de, V> Deserialize<'de> for NURBSSurface<V>where
V: Deserialize<'de>,
impl<'de, V> Deserialize<'de> for NURBSSurface<V>where
V: Deserialize<'de>,
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl IncludeCurve<BSplineCurve<Point3<f64>>> for NURBSSurface<Vector4>
impl IncludeCurve<BSplineCurve<Point3<f64>>> for NURBSSurface<Vector4>
source§impl IncludeCurve<NURBSCurve<Vector3<f64>>> for NURBSSurface<Vector3>
impl IncludeCurve<NURBSCurve<Vector3<f64>>> for NURBSSurface<Vector3>
source§impl IncludeCurve<NURBSCurve<Vector4<f64>>> for NURBSSurface<Vector4>
impl IncludeCurve<NURBSCurve<Vector4<f64>>> for NURBSSurface<Vector4>
source§impl<V: Clone> Invertible for NURBSSurface<V>
impl<V: Clone> Invertible for NURBSSurface<V>
source§impl<V: Homogeneous<f64> + ControlPoint<f64, Diff = V>> ParameterDivision2D for NURBSSurface<V>where
V::Point: MetricSpace<Metric = f64> + HashGen<f64>,
impl<V: Homogeneous<f64> + ControlPoint<f64, Diff = V>> ParameterDivision2D for NURBSSurface<V>where
V::Point: MetricSpace<Metric = f64> + HashGen<f64>,
source§impl<V: Homogeneous<f64> + ControlPoint<f64, Diff = V>> ParametricSurface for NURBSSurface<V>
impl<V: Homogeneous<f64> + ControlPoint<f64, Diff = V>> ParametricSurface for NURBSSurface<V>
source§impl ParametricSurface3D for NURBSSurface<Vector4>
impl ParametricSurface3D for NURBSSurface<Vector4>
source§impl<V: PartialEq> PartialEq<NURBSSurface<V>> for NURBSSurface<V>
impl<V: PartialEq> PartialEq<NURBSSurface<V>> for NURBSSurface<V>
source§fn eq(&self, other: &NURBSSurface<V>) -> bool
fn eq(&self, other: &NURBSSurface<V>) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<V: Homogeneous<f64>> SearchNearestParameter<D2> for NURBSSurface<V>where
Self: ParametricSurface<Point = V::Point, Vector = <V::Point as EuclideanSpace>::Diff>,
V::Point: EuclideanSpace<Scalar = f64> + MetricSpace<Metric = f64>,
<V::Point as EuclideanSpace>::Diff: InnerSpace<Scalar = f64> + Tolerance,
impl<V: Homogeneous<f64>> SearchNearestParameter<D2> for NURBSSurface<V>where
Self: ParametricSurface<Point = V::Point, Vector = <V::Point as EuclideanSpace>::Diff>,
V::Point: EuclideanSpace<Scalar = f64> + MetricSpace<Metric = f64>,
<V::Point as EuclideanSpace>::Diff: InnerSpace<Scalar = f64> + Tolerance,
source§fn search_nearest_parameter<H: Into<SPHint2D>>(
&self,
point: V::Point,
hint: H,
trials: usize
) -> Option<(f64, f64)>
fn search_nearest_parameter<H: Into<SPHint2D>>(
&self,
point: V::Point,
hint: H,
trials: usize
) -> Option<(f64, f64)>
Searches the parameter (u, v)
which minimize |self(u, v) - point|
by Newton’s method
with initial guess (u0, v0)
. If the repeated trial does not converge, then returns None
.
Examples
use truck_geometry::*;
let knot_vecs = (KnotVec::bezier_knot(3), KnotVec::bezier_knot(2));
let ctrl_pts = vec![
vec![Vector3::new(0.0, 0.0, 1.0), Vector3::new(1.0, -2.0, 2.0), Vector3::new(1.0, 0.0, 1.0)],
vec![Vector3::new(0.0, 2.0, 2.0), Vector3::new(2.0, 4.0, 4.0), Vector3::new(2.0, 2.0, 2.0)],
vec![Vector3::new(0.0, 4.0, 2.0), Vector3::new(2.0, 8.0, 4.0), Vector3::new(2.0, 4.0, 2.0)],
vec![Vector3::new(0.0, 3.0, 1.0), Vector3::new(1.0, 7.0, 2.0), Vector3::new(1.0, 3.0, 1.0)],
];
let surface = NURBSSurface::new(BSplineSurface::new(knot_vecs, ctrl_pts));
let pt = surface.subs(0.3, 0.7);
let (u, v) = surface.search_nearest_parameter(pt, Some((0.5, 0.5)), 100).unwrap();
assert!(u.near(&0.3) && v.near(&0.7));
Remarks
It may converge to a local solution depending on the hint.
cf. BSplineCurve::search_rational_nearest_parameter
§type Point = <V as Homogeneous<f64>>::Point
type Point = <V as Homogeneous<f64>>::Point
source§impl SearchParameter<D2> for NURBSSurface<Vector3>
impl SearchParameter<D2> for NURBSSurface<Vector3>
source§fn search_parameter<H: Into<SPHint2D>>(
&self,
point: Point2,
hint: H,
trials: usize
) -> Option<(f64, f64)>
fn search_parameter<H: Into<SPHint2D>>(
&self,
point: Point2,
hint: H,
trials: usize
) -> Option<(f64, f64)>
Search the parameter (u, v)
such that self.subs(u, v).rational_projection()
is near pt
.
If cannot find, then return None
.
Examples
use truck_geometry::*;
let knot_vec = KnotVec::uniform_knot(2, 2);
let ctrl_pts = vec![
vec![Vector3::new(0.0, 0.0, 1.0), Vector3::new(0.1, 0.0, 0.5), Vector3::new(0.5, 0.0, 0.3), Vector3::new(1.0, 0.0, 1.0)],
vec![Vector3::new(0.0, 0.1, 0.1), Vector3::new(0.2, 0.2, 0.1), Vector3::new(0.4, 0.3, 0.4), Vector3::new(1.0, 0.3, 0.7)],
vec![Vector3::new(0.0, 0.5, 0.4), Vector3::new(0.3, 0.6, 0.5), Vector3::new(0.6, 0.4, 1.0), Vector3::new(1.0, 0.5, 0.4)],
vec![Vector3::new(0.0, 1.0, 1.0), Vector3::new(0.1, 1.0, 1.0), Vector3::new(0.5, 1.0, 0.5), Vector3::new(1.0, 1.0, 0.3)],
];
let bspsurface = BSplineSurface::new((knot_vec.clone(), knot_vec), ctrl_pts);
let surface = NURBSSurface::new(bspsurface);
let pt = surface.subs(0.3, 0.7);
let (u, v) = surface.search_parameter(pt, Some((0.5, 0.5)), 100).unwrap();
assert_near!(surface.subs(u, v), pt);
source§impl SearchParameter<D2> for NURBSSurface<Vector4>
impl SearchParameter<D2> for NURBSSurface<Vector4>
source§fn search_parameter<H: Into<SPHint2D>>(
&self,
point: Point3,
hint: H,
trials: usize
) -> Option<(f64, f64)>
fn search_parameter<H: Into<SPHint2D>>(
&self,
point: Point3,
hint: H,
trials: usize
) -> Option<(f64, f64)>
Search the parameter (u, v)
such that self.subs(u, v).rational_projection()
is near pt
.
If cannot find, then return None
.
Examples
use truck_geometry::*;
let knot_vec = KnotVec::uniform_knot(2, 2);
let ctrl_pts = vec![
vec![Vector4::new(0.0, 0.0, 0.0, 1.0), Vector4::new(0.1, 0.0, 0.5, 0.4), Vector4::new(1.0, 0.0, 0.6, 2.0), Vector4::new(0.4, 0.0, 0.4, 0.4)],
vec![Vector4::new(0.0, 0.2, 0.2, 2.0), Vector4::new(0.24, 0.24, 0.1, 1.2), Vector4::new(2.4, 1.8, 2.4, 0.6), Vector4::new(1.4, 0.42, 0.98, 1.4)],
vec![Vector4::new(0.0, 1.5, 1.2, 3.0), Vector4::new(1.02, 2.04, 1.7, 3.4), Vector4::new(0.42, 0.28, 0.7, 0.7), Vector4::new(0.6, 0.3, 0.0, 0.6)],
vec![Vector4::new(0.0, 1.0, 1.0, 1.0), Vector4::new(0.2, 2.0, 2.0, 2.0), Vector4::new(0.85, 1.7, 0.85, 1.7), Vector4::new(1.0, 1.0, 0.3, 1.0)],
];
let bspsurface = BSplineSurface::new((knot_vec.clone(), knot_vec), ctrl_pts);
let surface = NURBSSurface::new(bspsurface);
let pt = surface.subs(0.3, 0.7);
let (u, v) = surface.search_parameter(pt, Some((0.5, 0.5)), 100).unwrap();
assert_near!(surface.subs(u, v), pt);
source§impl<V> Serialize for NURBSSurface<V>where
V: Serialize,
impl<V> Serialize for NURBSSurface<V>where
V: Serialize,
source§impl<M, V: Copy> Transformed<M> for NURBSSurface<V>where
M: Copy + Mul<V, Output = V>,
impl<M, V: Copy> Transformed<M> for NURBSSurface<V>where
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
.