@@ -1683,3 +1683,115 @@ def flip(surf, **kwargs):
1683
1683
g .set_ctrlpts (new_cpts , size_u , size_v )
1684
1684
1685
1685
return geom
1686
+
1687
+
1688
+ @export
1689
+ def extract_curve_u (obj , param , ** kwargs ):
1690
+ """ Extracts the curve at the input parametric coordinate on the u-direction.
1691
+
1692
+ Keyword Arguments:
1693
+ * ``find_span_func``: FindSpan implementation. *Default:* :func:`.helpers.find_span_linear`
1694
+ * ``insert_knot_func``: knot insertion algorithm implementation. *Default:* :func:`.operations.insert_knot`
1695
+
1696
+ :param obj: surface
1697
+ :type obj: abstract.Surface
1698
+ :param param: parameter for the u-direction
1699
+ :type param: float
1700
+ :return: a curve
1701
+ :rtype: curve
1702
+ """
1703
+ # Validate input
1704
+ if not isinstance (obj , abstract .Surface ):
1705
+ raise GeomdlException ("Input shape must be an instance of abstract.Surface class" )
1706
+
1707
+ # Keyword arguments
1708
+ span_func = kwargs .get ('find_span_func' , helpers .find_span_linear ) # FindSpan implementation
1709
+ insert_knot_func = kwargs .get ('insert_knot_func' , insert_knot ) # Knot insertion algorithm
1710
+
1711
+ # Find multiplicity of the knot
1712
+ ks = span_func (obj .degree_u , obj .knotvector_u , obj .ctrlpts_size_u , param ) - obj .degree_u + 1
1713
+ s = helpers .find_multiplicity (param , obj .knotvector_u )
1714
+ r = obj .degree_u - s
1715
+
1716
+ # Create backups of the original surface
1717
+ temp_obj = copy .deepcopy (obj )
1718
+
1719
+ # Split the original surface
1720
+ insert_knot_func (temp_obj , [param , None ], num = [r , 0 ], check_num = False )
1721
+
1722
+ # Control points
1723
+ if (param == 0 ):
1724
+ curve_ctrlpts = temp_obj .ctrlpts2d [0 ]
1725
+ elif (param == 1 ):
1726
+ curve_ctrlpts = temp_obj .ctrlpts2d [- 1 ]
1727
+ else :
1728
+ curve_ctrlpts = temp_obj .ctrlpts2d [ks + r - 1 ]
1729
+
1730
+ # Create a new curve
1731
+ from geomdl import NURBS
1732
+ curve = NURBS .Curve ()
1733
+ curve .degree = obj .degree_v
1734
+ curve .ctrlpts = curve_ctrlpts
1735
+ curve .knotvector = obj .knotvector_v
1736
+
1737
+ # Return the new curve
1738
+ return curve
1739
+
1740
+
1741
+ @export
1742
+ def extract_surface_v (obj , param , ** kwargs ):
1743
+ """ Extracts the curve at the input parametric coordinate on the v-direction.
1744
+
1745
+ Keyword Arguments:
1746
+ * ``find_span_func``: FindSpan implementation. *Default:* :func:`.helpers.find_span_linear`
1747
+ * ``insert_knot_func``: knot insertion algorithm implementation. *Default:* :func:`.operations.insert_knot`
1748
+
1749
+ :param obj: surface
1750
+ :type obj: abstract.Surface
1751
+ :param param: parameter for the v-direction
1752
+ :type param: float
1753
+ :return: a curve
1754
+ :rtype: curve
1755
+ """
1756
+ # Validate input
1757
+ if not isinstance (obj , abstract .Surface ):
1758
+ raise GeomdlException ("Input shape must be an instance of abstract.Surface class" )
1759
+
1760
+ # Keyword arguments
1761
+ span_func = kwargs .get ('find_span_func' , helpers .find_span_linear ) # FindSpan implementation
1762
+ insert_knot_func = kwargs .get ('insert_knot_func' , insert_knot ) # Knot insertion algorithm
1763
+
1764
+ # Find multiplicity of the knot
1765
+ ks = span_func (obj .degree_v , obj .knotvector_v , obj .ctrlpts_size_v , param ) - obj .degree_v + 1
1766
+ s = helpers .find_multiplicity (param , obj .knotvector_v )
1767
+ r = obj .degree_v - s
1768
+
1769
+ # Create backups of the original surface
1770
+ temp_obj = copy .deepcopy (obj )
1771
+
1772
+ # Split the original surface
1773
+ insert_knot_func (temp_obj , [None , param ], num = [0 , r ], check_num = False )
1774
+
1775
+ # Control points
1776
+ curve_ctrlpts = []
1777
+ idx = 0
1778
+ if (param == 0 ):
1779
+ idx = 0
1780
+ elif (param == 1 ):
1781
+ idx = - 1
1782
+ else :
1783
+ idx = ks + r - 1
1784
+ for v_row in temp_obj .ctrlpts2d :
1785
+ temp = v_row [idx ]
1786
+ curve_ctrlpts .append (temp )
1787
+
1788
+ # Create a new curve
1789
+ from geomdl import NURBS
1790
+ curve = NURBS .Curve ()
1791
+ curve .degree = obj .degree_u
1792
+ curve .ctrlpts = curve_ctrlpts
1793
+ curve .knotvector = obj .knotvector_u
1794
+
1795
+ # Return the new curve
1796
+ return curve
1797
+
0 commit comments