115. lib.nurbs_c — Accelerated NURBS functions

This module provides compiled C versions of the pyFormex low level NURBS functions. Internally, the functions use double (float64) as floating point accuracy, but they accept any floating point type as input. Return values are either float or numpy.float64 arrays.

Warning

These functions are not intended for the end user. Using them with invalid input may crash your program. Normally they are invoked from the classes and functions in plugins.nurbs.

115.1. Functions defined in module lib.nurbs_c

lib.nurbs_c.allBernstein(n, u)

Compute the value of all n-th degree Bernstein polynomials. See bernstein() for definition.

Parameters:
  • n (int) – Degree of the polynomials

  • u (float) – Parametric value where the polynomials are evaluated

Returns:

float array (n+1) – The value of all n-th degree Bernstein polynomials B(i,n) at parameter value u.

Notes

Algorithm A1.3 from’The NURBS Book’ p.20.

lib.nurbs_c.basisDerivs(U, u, p, i, n)

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

lib.nurbs_c.bernstein(i, n, u)

Compute the value of a Bernstein polynomial of degree n:

B(i,n) = n! / (i! * (n-i)! * u**i * (1-u)**(n-i)

Usually one needs all the Bernstein polynomials, so allBernstein() is recommend.

Parameters:
  • i (int) – Index of the polynomial (0..n).

  • n (int) – Degree of the polynomial (> 0).

  • u (float) – Parametric value where the polynomial is evaluated

Returns:

float – The value of the Bernstein polynomial B(i,n) at parameter value u.

Notes

Algorithm A1.2 from’The NURBS Book’ p.20.

lib.nurbs_c.binomial()

binomial(n, k)

Compute the binomial coefficient C(n,k). This is the number of different subsets of size k that can be taken from a set of size n:

C(n,k) = n! / (k! * (n-k)!)
Parameters:
  • n (int) – The set size

  • k (int) – The subset size

Returns:

float – The binomial coefficient C(n,k)

Notes

Algorithm from ‘Numerical Recipes in C, 2nd Edition’ p.215.

lib.nurbs_c.cubicSplineInterpolation(Q, t0, t1, U)

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.

Notes

Based on algorithm A9.2 of ‘The Nurbs Book’, p. 373

lib.nurbs_c.curveDecompose(P, U)

Decompose a Nurbs curve in Bezier segments.

Parameters:
  • P (float array (nc, nd)) – The nc control points (with nd being 3 or 4)

  • U (float array (m+1)) – The knot sequence: U[0] .. U[m]

Returns:

float array (nb*p+1, nd) – The control points defining nb Bezier segments of degree p = m - nc.

Notes

Modified algorithm A5.6 from ‘The NURBS Book’ p.173.

lib.nurbs_c.curveDegreeElevate(P, U, t)

Degree elevate a curve t times. This keeps the curve’s shape.

Parameters:
  • P (float array (nc, nd)) – The nc control points (with nd being 3 or 4)

  • U (float array (m+1)) – The knot sequence: U[0] .. U[m]

  • t (int) – The value to increase the degree with

Returns:

  • newP (float array (nq, nd)) – The new control points.

  • newU (float array (nu)) – The new knot sequence.

See also

plugins.nurbs.NurbsCurve.elevateDegree()

the safe way to use this function

curveDegreeReduce

reduce the degree of the curve

Notes

Modified algorithm A5.9 from ‘The NURBS Book’ p.206.

lib.nurbs_c.curveDegreeReduce(P, U)

Reduce the degree of the B-spline with 1.

Parameters:
  • P (float array (nc, nd)) – The nc control points (with nd being 3 or 4)

  • U (float array (m+1)) – The knot sequence: U[0] .. U[m]

Returns:

  • newP (float array (nq, nd)) – The new control points.

  • newU (float array (nu)) – The new knot sequence.

See also

plugins.nurbs.NurbsCurve.reduceDegree()

the safe way to use this function

curveDegreeElevate

elevate the degree of the curve

Notes

Modified algorithm A5.9 from ‘The NURBS Book’ p.206.

lib.nurbs_c.curveDerivs(P, U, u, n)

Compute points and derivatives of a B-spline curve.

Parameters:
  • P (float array (nc, nd)) – The nc control points (with nd being 3 or 4)

  • U (float array (m+1)) – The knot sequence: U[0] .. U[m]

  • u (float array (nu)) – Parametric values where the curve is to be evaluated. All values should be in the range U[0] <= ui <= U[m].

  • n (int) – Highest derivative to compute

Returns:

float array (n+1,nu,nd) – Points and derivatives on the B-spline

See also

plugins.nurbs.NurbsCurve.derivs()

the safe way to use this function

curvePoints

compute points on the B-spline curve

Notes

Modified algorithm A3.2 from ‘The NURBS Book’ p.93.

lib.nurbs_c.curveGlobalInterpolationMatrix(Q, u, p)

Compute the global curve interpolation matrix.

Parameters:
  • Q (float array (nc, nd)) – The points through which the curve should pass (nc,nd), where nc is the number of points = number of control points and nd is the dimension of the points (3 or 4).

  • u (float array (nc)) – The parameter values at the nc points

  • p (int) – The degree of the B-spline to construct.

Returns:

  • U (float array (nu)) – The knot sequence, with nu = np + p + 1.

  • A (float array (nc, 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 safe way to use this function

Notes

Modified algorithm A9.1 from ‘The NURBS Book’ p.369.

lib.nurbs_c.curveKnotRefine(P, U, u)

Add values to the curve knot vector. This does not change the curve shape.

Parameters:
  • P (float array (nc, nd)) – The nc control points (with nd being 3 or 4)

  • U (float array (m+1)) – The knot sequence: U[0] .. U[m]

  • u (float array (nu)) – Parametric values of the new knots to insert. All values should be in the range U[0] <= ui <= U[m].

Returns:

  • newP (float array (nc+nu, nd)) – The new control points

  • newU (float array (m+nu)) – The new knot vector

See also

plugins.nurbs.NurbsCurve.insertKnots()

the safe way to use this function

curveKnotRemove

remove values from the knot vector

Notes

Modified algorithm A5.4 from ‘The NURBS Book’ p.164.

lib.nurbs_c.curveKnotRemove(P, Uv, Um, iv, num)

Remove values from the curve knot vector. This may change the shape of the curve.

Parameters:
  • P (float array (nc, nd)) – The nc control points (with nd being 3 or 4)

  • Uv (float array (nv)) – The unique values in the knot sequence.

  • Um (int array (nv)) – The multiplicity of the Uv values in the knot sequence. Clearly sum(Um) must be equal to the number of values in the curve’s knot vector.

  • iv (int) – The index in Uv of the knot value to remove: 0 <= iv < nv

  • num (int) – The number of times to remove knot value Uv[iv]: num <= Um[iv].

  • tol (float) – Allowable tolerance for deviation of the curve. See NURBS book, p.185

Returns:

  • t (int) – The actual number of times that Uv[iv] was removed

  • newP (float array (nc-num, nd)) – The new control points

  • newU (float array (m-num)) – The new knot vector

See also

plugins.nurbs.NurbsCurve.removeKnot()

the safe way to use this function

curveKnotRefine

add values to the knot vector

Notes

Modified algorithm A5.8 from ‘The NURBS Book’ p.185.

lib.nurbs_c.curvePoints(P, U, u)

Compute a point on a B-spline curve. The B-spline is defined by nc control points P of dimension nd (3 or 4), and m+1 knots U defining the parameter values where the mathematical representation of the curve is discontinuous. The knots form a non-decreasing sequence. Values can be repeated to model discontinuities. The degree of the curve is p = m - nc. The curve is evaluated at nu parametric values u.

Parameters:
  • P (float array (nc, nd)) – The nc control points (with nd being 3 or 4)

  • U (float array (m+1)) – The knot sequence: U[0] .. U[m]

  • u (float array (nu)) – Parametric values where the curve is to be evaluated. All values should be in the range U[0] <= ui <= U[m].

Returns:

float array (nu,nd) – The nu points on the B-spline.

See also

plugins.nurbs.NurbsCurve.pointsAt()

the safe way to use this function

curveDerivs

compute points and derivatives for the B-spline curve

Notes

Modified algorithm A3.1 from ‘The NURBS Book’ p.82.

lib.nurbs_c.horner(a, u)

Compute points on a power base curve using Horner’s rule.

Parameters:
  • a (float64 array (nd, n+1)) – The nd-dimensional coefficients of a polynom of degree n in a scalar variable u. The coefficients start from lowest degree.

  • u (float64 array (nu)) – Parametric values where the polynom is evaluated

Returns:

float64 array (nu, nd) – The nu nd-dimensonal points on the curve

Notes

Extended algorithm A1.1 from’The NURBS Book’ p.7.

lib.nurbs_c.surfaceDerivs(P, U, V, u, mu, mv)

Compute points and derivatives of a B-spline surface.

Parameters:
  • P (float array (ns, nt, nd)) – The grid of ns * nt control points of dimension 3 or 4

  • U (float array (nU)) – The knot sequence in direction u

  • V (float array (nV)) – The knot sequence in direction c

  • u (float array (nu, 2)) – The nu parametric values (u, v) where the surface should be evaluated. All values should be in their respective parameter range.

  • mu (int) – The highest requested derivative in direction u.

  • mv (int) – The highest requested derivative in direction v.

Returns:

float array (mu+1, mv+1, nu, nd) – The nu points on the B-spline surface and the derivatives up to (mu,mv). Thus, the slice [0,0] of the resulting array contains the coordinates of the nu points, slice [1,0] contains the first derivative in direction u, slice [1,1] contains the mixed second derivative: d2 / du.dv, etc.

See also

plugins.nurbs.NurbsSurface.derivs()

the safe way to use this function

surfacePoints

compute points on a B-spline surface

Notes

Modified algorithm A3.6 from ‘The NURBS Book’ p.111.

lib.nurbs_c.surfacePoints(P, U, V, u)

Compute points on a B-spline surface. The B-spline surface is defined by a grid of ns * nt control points P of dimension nd (3 or 4), nU knots U in the first parametric direction and nV knots V in the second parametric direction. The knot valuess define where the mathematical representation of the surface changes. The knot vectors form a non-decreasing sequence. Values can be repeated to model discontinuities. The degree of the surface is p = nU - ns - 1 in the parametric direction u and q = nV - nt - 1 in the parametric direction v. The surface is evaluated at nu parametric values (u,v).

Parameters:
  • P (float array (ns, nt, nd)) – The grid of ns * nt control points of dimension 3 or 4

  • U (float array (nU)) – The knot sequence in direction u

  • V (float array (nV)) – The knot sequence in direction c

  • u (float array (nu, 2)) – The nu parametric values (u, v) where the surface should be evaluated. All values should be in their respective parameter range.

Returns:

float array (nu,nd) – The nu points on the B-spline surface.

See also

plugins.nurbs.NurbsSurface.pointsAt()

the safe way to use this function

curveDerivs

compute points and derivatives for a B-spline surface

Notes

Modified algorithm A3.5 from ‘The NURBS Book’ p.103.