NURBS#
NURBS Fitting#
Provides curve and surface fitting functions.
This module provides functions for working with Non-Uniform Rational B-Splines (NURBS) geometries. Some functions are based on the geomdl open-source library (MIT license), originally created by the geomdl authors: orbingol/NURBS-Python.
We also use as main reference Les Piegl and Wayne Tiller. The NURBS Book. Springer Science & Business Media, 1997
For more information on NURBs and their use in geometric modeling, please refer to the literature in the field. The authors of this module make no warranty or guarantee as to the accuracy or suitability of this code for any particular purpose.
- volmdlr.nurbs.fitting.approximate_curve(points: np.ndarray[np.double_t, ndim == 2], degree: cython.int, **kwargs)#
Curve approximation using least squares method with fixed number of control points.
Please refer to The NURBS Book (2nd Edition), pp.410-413 for details.
- Keyword Arguments:
centripetal: activates centripetal parametrization method. Default: Falsectrlpts_size: number of control points. Default: len(points) - 1
- Parameters:
points (list, tuple) – data points
degree (int) – degree of the output parametric curve
- Returns:
approximated B-Spline curve
- Return type:
BSpline.Curve
- volmdlr.nurbs.fitting.approximate_surface(points: np.ndarray[np.double_t, ndim == 2], size_u: cython.int, size_v: cython.int, degree_u: cython.int, degree_v: cython.int, **kwargs)#
Surface approximation using least squares method with fixed number of control points.
This algorithm interpolates the corner control points and approximates the remaining control points. Please refer to Algorithm A9.7 of The NURBS Book (2nd Edition), pp.422-423 for details.
- Keyword Arguments:
centripetal: activates centripetal parametrization method. Default: Falsectrlpts_size_u: number of control points on the u-direction. Default: size_u - 1ctrlpts_size_v: number of control points on the v-direction. Default: size_v - 1
- Parameters:
points (list, tuple) – data points
size_u (int) – number of data points on the u-direction, \(r\)
size_v (int) – number of data points on the v-direction, \(s\)
degree_u (int) – degree of the output surface for the u-direction
degree_v (int) – degree of the output surface for the v-direction
- Returns:
approximated B-Spline surface
- Return type:
BSpline.Surface
- volmdlr.nurbs.fitting.interpolate_curve(points: np.ndarray[np.double_t, ndim == 2], degree: cython.int, centripetal: cython.bint)#
Curve interpolation through the data points.
Please refer to Algorithm A9.1 on The NURBS Book (2nd Edition), pp.369-370 for details.
- Keyword Arguments:
centripetal: activates centripetal parametrization method. Default: False
- Parameters:
points (list, tuple) – data points
degree (int) – degree of the output parametric curve
- Returns:
interpolated B-Spline curve
- Return type:
BSpline.Curve
- volmdlr.nurbs.fitting.interpolate_surface(points: np.ndarray[np.double_t, ndim == 2], size_u: cython.int, size_v: cython.int, degree_u: cython.int, degree_v: cython.int, **kwargs)#
Surface interpolation through the data points.
Please refer to the Algorithm A9.4 on The NURBS Book (2nd Edition), pp.380 for details.
- Keyword Arguments:
centripetal: activates centripetal parametrization method. Default: False
- Parameters:
points (list, tuple) – data points
size_u (int) – number of data points on the u-direction
size_v (int) – number of data points on the v-direction
degree_u (int) – degree of the output surface for the u-direction
degree_v (int) – degree of the output surface for the v-direction
- Returns:
interpolated B-Spline surface
- Return type:
BSpline.Surface
NURBS Operations#
Nurbs main operations algorithms.
- volmdlr.nurbs.operations.construct_split_curve(obj, curve1_kv, curve2_kv, knot_span, insertion_count)#
Instantiate split curve.
- volmdlr.nurbs.operations.construct_split_surfaces(obj, knotvectors, direction, knot_span, insertion_count)#
Construct split surfaces.
- volmdlr.nurbs.operations.ctrlpts2d_to_ctrlpts(control_points_table)#
Transform the control_points m x n.
- volmdlr.nurbs.operations.decompose_curve(obj, return_params: bool = False, number_max_patches: int | None = None, **kwargs)#
Decompose the curve into Bézier curve segments of the same degree.
Generator
- Parameters:
obj (BSplineCurve) – Curve to be decomposed
return_params (bool) – If True, returns the parameters from start and end of each Bézier patch with respect to the input curve.
number_max_patches – number max of patches, if limiting is needed.
- Type:
int
- Returns:
a generator element with a Bezier segment.
- Return type:
Generator element.
- volmdlr.nurbs.operations.decompose_surface(obj, return_params, **kwargs)#
Decomposes the surface into Bezier surface patches of the same degree.
- Parameters:
obj (BSplineSurface3D) – surface
return_params (bool) – If True, returns the parameters from start and end of each Bézier patch with respect to the input curve.
- Returns:
a list of Bezier patches
- Return type:
list
- volmdlr.nurbs.operations.extract_surface_curve_u(obj, param, curve_class, **kwargs)#
Extract an isocurve from the surface at the input parametric coordinate on the u-direction.
This method works by inserting knots to the surface so that from the new control points created we can extract the curve. Under the hood this method performs an incomplete process of splitting the surface.
- Keyword Arguments:
find_span_func: FindSpan implementation. Default:helpers.find_span_linear()
- Parameters:
obj (volmdlr.surfaces.BSplineSurface3D) – surface
param (float) – parameter for the u-direction
curve_class (volmdlr.edges.BSplineCurve3D) – BSpline curve object
- Returns:
The bspline curve at the specified parameter
- Return type:
- volmdlr.nurbs.operations.extract_surface_curve_v(obj, param, curve_class, **kwargs)#
Extract an isocurve from the surface at the input parametric coordinate on the v-direction.
This method works by inserting knots to the surface so that from the new control points created we can extract the curve. Under the hood this method performs an incomplete process of splitting the surface.
- Keyword Arguments:
find_span_func: FindSpan implementation. Default:helpers.find_span_linear()
- Parameters:
obj (volmdlr.surfaces.BSplineSurface3D) – surface
param (float) – parameter for the u-direction
curve_class (volmdlr.edges.BSplineCurve3D) – BSpline curve object
- Returns:
The bspline curve at the specified parameter
- Return type:
- volmdlr.nurbs.operations.flip_ctrlpts_u(ctrlpts, size_u, size_v)#
Flips a list of 1-dimensional control points from u-row order to v-row order.
u-row order: each row corresponds to a list of u values
v-row order: each row corresponds to a list of v values
- Parameters:
ctrlpts (list, tuple) – control points in u-row order
size_u (int) – size in u-direction
size_v (int) – size in v-direction
- Returns:
control points in v-row order
- Return type:
list
- volmdlr.nurbs.operations.get_knots_and_multiplicities(knotvector)#
Get knots and multiplicities from knotvector in u and v direction.
- volmdlr.nurbs.operations.helper_decompose(srf, idx, split_func, return_params, other_direction_params=None, **kws)#
Decompose surface.
- volmdlr.nurbs.operations.helper_split_knot_vectors(degree, knotvector, num_ctrlpts, param, span_func)#
Compute knot vectors to split object into two pieces.
- volmdlr.nurbs.operations.insert_control_points_surface_u(obj, param, num, **kwargs)#
Calculate the control points equivalent to inserts knot n-times to a spline geometry.
- Keyword Arguments:
check_num: enables/disables operation validity checks. Default: True
- Parameters:
obj – spline geometry
param (list, tuple) – knot to be inserted in u direction
num (list, tuple) – number of knot insertions
- Returns:
a list with the control points
- volmdlr.nurbs.operations.insert_control_points_surface_v(obj, param, num, **kwargs)#
Calculate the control points equivalent to inserts knot n-times to a spline geometry.
- Keyword Arguments:
check_num: enables/disables operation validity checks. Default: True
- Parameters:
obj – spline geometry
param (list, tuple) – knot to be inserted in v direction
num (list, tuple) – number of knot insertions
- Returns:
a list with the control points
- volmdlr.nurbs.operations.insert_knot_curve(obj, param, num, **kwargs)#
Insert knots n-times to a spline geometry.
- Keyword Arguments:
check_num: enables/disables operation validity checks. Default: True
- Parameters:
obj – spline geometry
param (list, tuple) – knot(s) to be inserted in [u, v, w] format
num (list, tuple) – number of knot insertions in [num_u, num_v, num_w] format
- Returns:
updated spline geometry
- volmdlr.nurbs.operations.insert_knot_surface(obj, param, num, **kwargs)#
Insert knots n-times to a spline geometry.
- Keyword Arguments:
check_num: enables/disables operation validity checks. Default: True
- Parameters:
obj – spline geometry
param (list, tuple) – knot(s) to be inserted in [u, v] format
num (list, tuple) – number of knot insertions in [num_u, num_v] format
- Returns:
updated spline geometry
- volmdlr.nurbs.operations.knot_insertion(degree, knotvector, ctrlpts, u, **kwargs)#
Compute the control points of the rational/non-rational spline after knot insertion.
Part of Algorithm A5.1 of The NURBS Book by Piegl & Tiller, 2nd Edition.
- Keyword Arguments:
num: number of knot insertions. Default: 1s: multiplicity of the knot. Default: computed via :func:`.find_multiplicity`span: knot span. Default: computed via :func:`.find_span_linear`
- Parameters:
degree (int) – degree
knotvector (list, tuple) – knot vector
ctrlpts (list) – control points
u (float) – knot to be inserted
- Returns:
updated control points
- Return type:
list
- volmdlr.nurbs.operations.knot_insertion_alpha(u, knotvector, span, idx, leg)#
Compute alpha coefficient for knot insertion algorithm.
- Parameters:
u (float) – knot
knotvector (tuple) – knot vector
span (int) – knot span
idx (int) – index value (degree-dependent)
leg (int) – i-th leg of the control points polygon
- Returns:
coefficient value
- Return type:
float
- volmdlr.nurbs.operations.knot_insertion_kv(knotvector, u, span, num_insertions)#
Compute the knot vector of the rational/non-rational spline after knot insertion.
Part of Algorithm A5.1 of The NURBS Book by Piegl & Tiller, 2nd Edition.
- Parameters:
knotvector (list, tuple) – knot vector
u (float) – knot
span (int) – knot span
num_insertions (int) – number of knot insertions
- Returns:
updated knot vector
- Return type:
list
- volmdlr.nurbs.operations.link_curves(curves, tol: float = 1e-07, validate: bool = True)#
Links the input curves together.
The end control point of the curve k has to be the same with the start control point of the curve k + 1.
- Returns:
a tuple containing: knots, knots multiplicities, control points and weights vector
- volmdlr.nurbs.operations.refine_knot_vector_surface(obj, u, v, **kwargs)#
Split the surface at the input parametric coordinate on the u-direction.
This method splits the surface into two pieces at the given parametric coordinate on the u-direction, generates two different surface objects and returns them. It does not modify the input surface.
- Keyword Arguments:
find_span_func: FindSpan implementation. Default:helpers.find_span_linear()insert_knot_func: knot insertion algorithm implementation. Default:operations.insert_knot()
- Parameters:
obj (abstract.Surface) – surface
param (float) – parameter for the u-direction
- Returns:
a list of surface patches
- Return type:
list
- volmdlr.nurbs.operations.separate_ctrlpts_weights(ctrlptsw)#
Divide weighted control points by weights to generate unweighted control points and weights vector.
This function is dimension agnostic, i.e. control points can be in any dimension but the last element of the array should indicate the weight.
- Parameters:
ctrlptsw (list, tuple) – weighted control points
- Returns:
unweighted control points and weights vector
- Return type:
list
- volmdlr.nurbs.operations.split_curve(obj, param, **kwargs)#
Split the curve at the input parametric coordinate.
This method splits the curve into two pieces at the given parametric coordinate, generates two different curve objects and returns them. It does not modify the input curve.
- Keyword Arguments:
find_span_func: FindSpan implementation. Default:helpers.find_span_linear()insert_knot_func: knot insertion algorithm implementation. Default:operations.insert_knot()
- Parameters:
obj (abstract.Curve) – Curve to be split
param (float) – parameter
- Returns:
a list of curve segments
- Return type:
list
- volmdlr.nurbs.operations.split_surface_u(obj, param, **kwargs)#
Split the surface at the input parametric coordinate on the u-direction.
This method splits the surface into two pieces at the given parametric coordinate on the u-direction, generates two different surface objects and returns them. It does not modify the input surface.
- Keyword Arguments:
find_span_func: FindSpan implementation. Default:helpers.find_span_linear()insert_knot_func: knot insertion algorithm implementation. Default:operations.insert_knot()
- Parameters:
obj (abstract.Surface) – surface
param (float) – parameter for the u-direction
- Returns:
a list of surface patches
- Return type:
list
- volmdlr.nurbs.operations.split_surface_v(obj, param, **kwargs)#
Split the surface at the input parametric coordinate on the v-direction.
This method splits the surface into two pieces at the given parametric coordinate on the v-direction, generates two different surface objects and returns them. It does not modify the input surface.
- Keyword Arguments:
find_span_func: FindSpan implementation. Default:helpers.find_span_linear()insert_knot_func: knot insertion algorithm implementation. Default:operations.insert_knot()
- Parameters:
obj (abstract.Surface) – surface
param (float) – parameter for the v-direction
- Returns:
a list of surface patches
- Return type:
list