116. lib.nurbs_e
— Python equivalents of the functions in lib.nurbs_c¶
The functions in this module should be exact emulations of the external functions in the compiled library. Currently however this module only contains a few of the functions in lib.nurbs_c, making nurbs functionality in pyFormex currently only available when using the compiled lib.
116.1. Functions defined in module lib.nurbs_e¶
- lib.nurbs_e.allBernstein(n, u)[source]¶
Compute the value of all n-th degree Bernstein polynomials.
Parameters:
n: int, degree of the polynomials
u: float, parametric value where the polynomials are evaluated
Returns: an (n+1,) shaped float array with the value of all n-th degree Bernstein polynomials B(i,n) at parameter value u.
Algorithm A1.3 from ‘The NURBS Book’ p20.
- lib.nurbs_e.find_span(U, u, p, n)[source]¶
Find the knot span index of the parametric point u.
- Parameters:
- Returns:
int – The index of the knot span.
Notes
Algorithm A2.1 from ‘The NURBS Book’ p.68.
- lib.nurbs_e.basis_funs(U, u, p, i)[source]¶
Compute the nonvanishing B-spline basis functions for index span i.
- Parameters:
- Returns:
float array (p+1) – The (p+1) values of nonzero basis functions at u.
Notes
Algorithm A2.2 from ‘The NURBS Book’ p.70.
- lib.nurbs_e.basis_derivs(U, u, p, i, n)[source]¶
Compute the nonvanishing B-spline basis functions and derivatives.
- Parameters:
U (float array (m+1,)) – The knot sequence: U[0] .. U[m], non-descending.
u (float) – The parametric value U[0] <= u <= U[m] where to compute the functions.
p (int) – Degree of the B-spline basis functions
i (int) – Index of the knot span for value u (from find_span())
n (int) – Number of derivatives to compute (n <= p)
- Returns:
float array (n+1, p+1) – The (n+1, p+1) values of the nonzero basis functions and their first n derivatives at u
Notes
Algorithm A2.3 from ‘The NURBS Book’ p.72.
- lib.nurbs_e.curveDegreeElevate(Pw, U, t)[source]¶
Elevate the degree of the Nurbs curve.
Parameters:
Pw: float array (nk,nd): nk=n+1 control points
U: int array(nu): nu=m+1 knot values
t: int: how much to elevate the degree
Returns a tuple:
Qw: nh+1 new control points
Uh: mh+1 new knot values
nh: highest control point index
mh: highest knot index
This is based on algorithm A5.9 from ‘The NURBS Book’ pg206.
- lib.nurbs_e.BezDegreeReduce(Q, return_errfunc=False)[source]¶
Degree reduce a Bezier curve.
- Parameters:
Q (float array (nk, nd)) – The control points of a Bezier curve of degree p = nk-1
return_errfunc (bool) – If True, also returns a function to evaluate the error along the parametric values.
- Returns:
P (float array (nk-1, nd)) – The control points of a Bezier curve of degree p-1 that is as close as possible to the original curve.
maxerr (float) – An upper bound on the error introduced by the degree reduction.
errfunc (function) – A callable to evaluate the error as function of the parameter u. Only returned if return_errfunc is True.
Notes
Based on The NURBS Book 5.6.
- lib.nurbs_e.curveDegreeReduce(Qw, U, tol=1.0)[source]¶
Reduce the degree of the Nurbs curve.
- Parameters:
Qw (float array (nc, nd)) – The nc control points of the Nurbs curve
U (float array (nu)) – The nu knot values of the Nurbs curve
- Returns:
Pw (float array (nctrl, nd)) – The new control points
U (float array (nknots)) – The new knot vector
err (float array (nerr)) – The error vector
This is algorithm A5.11 from ‘The NURBS Book’ pg223.
- lib.nurbs_e.curveUnclamp(P, U)[source]¶
Unclamp a clamped curve.
Input: P,U Output: P,U
Note: this changes P and U inplace.
Based on algorithm A12.1 of The NURBS Book.
- lib.nurbs_e.curveGlobalInterpolationMatrix(u, p, t0, t1)[source]¶
Compute the global curve interpolation matrix.
- Parameters:
u (float array (nc)) – The parameter values at the nc points Q to be interpolated
p (int) – The degree of the B-spline to construct.
t0 (0 | 1) – 1 if the tangent at the start of the curve is specified
t1 (0 | 1) – 1 if the tangent at the end of the curve is specified
- Returns:
U (float array (nU)) – The knot sequence, with nU = nu + p + 1, nu = nc + t0 + t1
A (float array (nu, nu)) – The coefficient matrix for the interpolation. The control points P can be found by solving the system of linear equations: A * P = Q.
See also
plugins.nurbs.globalInterpolationCurve()
the normal way to use this
Notes
Modified algorithm A9.1 from ‘The NURBS Book’ p.369.
- lib.nurbs_e.curveGlobalInterpolationMatrix2(Q, D, u, p)[source]¶
Compute the global curve interpolation matrix for all tangents given.
- Parameters:
Q (float array (nc)) –
D (float array(nc)) –
u (float array (nc)) – The parameter values at the nc points Q to be interpolated
p (2 | 3) – The degree of the B-spline to construct.
- Returns:
U (float array (nU)) – The knot sequence, with nU = 2*nc + p + 1
A (float array (2*nc, 2*nc)) – The coefficient matrix for the interpolation. The control points P can be found by solving the system of linear equations: A * P = Q.
See also
plugins.nurbs.globalInterpolationCurve()
the normal way to use this
Notes
Modified algorithm A9.1 from ‘The NURBS Book’ p.369.
- lib.nurbs_e.cubicSplineInterpolation(Q, t0, t1, U)[source]¶
Compute the control points of a cubic spline interpolate.
- Parameters:
Q (float array (nc, 3)) – The nc points where the curve should pass through.
t0 (float array (3,)) – The tangent to the curve at the start point Q[0]
t1 (float array (3,)) – The tangent to the curve at the end point Q[nc-1]
U (float array (nc+6,)) – The clamped knot vector: 3 zeros, the nc parameter values for the points, 3 ones.
- Returns:
float array (nc+2, 3) – The control points of the curve. With the given knots they will create a 3-rd degree NURBS curve that passes through the points Q and has derivatives t0 and t1 at its end.
Based on algorithm A9.2 of ‘The Nurbs Book’, p. 373