Class NurbsArray

All Implemented Interfaces:
RealValuedDomainOps, VADomainOps

public class NurbsArray extends VectorValuedFunction
Class implementing vector-valued NURBS (Non Uniform Rational B-Splines).

This class supports both periodic and non-periodic NURBS, and is very similar to the BSplineArray class. For purposes of this class, a periodic NURBS array adds additional knots and control points - copies of the ones explicitly specified, so that the spline will be smooth at its end points. The parameter u will be shifted if necessary, always by a multiple of its period, so that the spline's value will be computed using values of the parameter within a specific range. Details regarding the additional control points, weights, and knots for the periodic case are described below.

A NURBS array consists of

  • an increasing finite sequence of real numbers called "knots": u0 ≤ u1 ≤ ... ≤ um
  • a set of basis functions.
  • a set of control points (just numbers for this class) denoted as P0, P1, … Pn.
  • a degree—normally denoted as p. The degree of a NURBS must satisfy p = m - n - 1.
  • a set of weights denoted as w0, w1 … wn.

The basis functions are defined as follows: $$\begin{eqnarray} N_{i,0}(u) & = & \left\{\begin{array}{ll} 1 & \mbox {if $u_i \le u < u_{i+1}$} \\ 0 & \mbox{if $u < u_i$ or $u_{i+1} \le u$} \end{array}\right . \\ N_{i,p}(u) & = & \mbox{$N_{i,p-1}(u)\frac{u-u_i}{u_{i+p}-u_i} + N_{i+1,p-1}(u)\frac{u_{i+p+1}-u}{u_{i+p+1}-u_{i+1}}$ for $p > 0$} \end{eqnarray}$$

  • Ni,0(u) = 1 if ui ≤ u < ui+1.
  • Ni,0(u) = 0 if u < ui or ui+1 ≤ u.
  • Ni,p(u) = Ni,p-1(u) (u-ui) ⁄ (ui+p-ui) + Ni+1,p-1(u) (ui+p+1-u) ⁄ (ui+p+1-ui+1) for p > 0.
The value of the function defined by this spline at a point u is equal to $$f(u) = \sum^n_{i=0} P_iN_{i,p}$$ with a domain [up, um-p] for non-periodic splines and (-∞, ∞) for periodic splines (for a periodic spline, the value of u will be shifted by an appropriate multiple of the period so as to be in the interval [up, um-p], at at the end points of this interval, the values will match, as will their derivatives.

The documentation for the constructor NurbsArray(int,int,double[],double[],boolean) describes how periodic and non-periodic NURBSs are created.

  • Constructor Details

    • NurbsArray

      public NurbsArray(int dim, double[] knots, double[] cpoints) throws IllegalArgumentException
      Constructor for open NURBSs. A full description is provided by the constructor NurbsArray(int,int,double[],double[],boolean). The degree of the NURBS is equal to knots.length - cpoints.length - 1.
      Parameters:
      dim - the length of the array of values
      knots - the knots for the NURBS to be constructed
      cpoints - the control points and weights for the NURBS to be constructed
      Throws:
      IllegalArgumentException
      See Also:
    • NurbsArray

      public NurbsArray(int dim, int degree, double[] knots, double[] cpoints, boolean periodic) throws IllegalArgumentException
      Constructor. There are two cases depending on whether the NURBS will be periodic or non-periodic. For the non-periodic case, if m is the length of the knots array, n is the number of control points, and p is the degree if the NURBS, then the following constraint must be satisfied:
           n + p + 1 = m
      or
           m - n - 1 = p.
      or
           m - p - 1 = n.
      where each control point and weight consists of 1 + <the number of dimension> double-precision numbers. For each control point and weight, the array contains the coordinates of the control point (listed in order), followed by the weight, placed contiguously in the array.

      The degree matches the highest possible degree of the polynomial representation of the basis functions (some authors start the sequence at 1 instead of 0, in which case the degree the smallest integer larger than the degree of the polynomials). The domain of the spline is [us, ue]. where us=knots[degree] and ue=knots[knots.length-p-1].

      For the periodic case, the values of the spline over a range [us,ue] repeat indefinitely in either direction, and the knots array's initial and ending components will be us and ue respectively. As a result, the period is ue-us. For a periodic spline whose degree is p, the length of the control-points array will either be one less than the length of the knots array, or (p-1) larger than the length of the knots array, in both cases multiplied by 1 + <the number of dimensions>. The constructor will augment these arrays as follows:

      • p components will be inserted before the initial component of the knots array, and p components will be inserted after the last component of the knots array. The p components before the last original entry will be copied to the start of the array in the same order as in the original array, with values decreased by the period. The first p components past the initial component of the original array array will be copied to the end of the array, with values increased by the period.
      • When the control-points array's length is one less than the length of the knots array, p components will be inserted before the initial component of the control-points array. The last p components of the original array will be copied to the start of the augmented array in the same order as in the original array.
      Note: Copying of control points must be considered when fitting a periodic spline to a function or a set of data points.
      Parameters:
      dim - the dimension of the vector
      degree - a non-negative integer giving the degree of the NURBS to be constructed
      knots - the knots for the NURBS to be constructed
      cpoints - the control points and weights for the NURBS to be constructed
      periodic - true if the spline is periodic; false if it is open.
      Throws:
      IllegalArgumentException
  • Method Details

    • getDimension

      public int getDimension()
      Get the number of dimensions for the NURBS. This is also the number of dimensions for the control points, excluding their weights.
      Overrides:
      getDimension in class VectorValuedFunctionVA
      Returns:
      the number of dimensions
    • isPeriodic

      public boolean isPeriodic()
      Determine if the spline is a periodic spline.
      Returns:
      true if the spline is periodic; false otherwise.
    • getPeriodStart

      public double getPeriodStart()
      Get the starting value for a period. A periodic NURBS explicitly handles a range of values of the parameters. For other values of the parameter, the parameter is shifted by the period until it falls within this range. For a non-periodic NURBS, the domain minimum is returned.
      Returns:
      the starting value for a period if the spline is periodic; otherwise the domain minimum
    • getPeriodEnd

      public double getPeriodEnd()
      Get the ending value for a period. A periodic NURBS explicitly handles a range of values of the parameters. For other values of the parameter, the parameter is shifted by the period until it falls within this range. For a non-periodic NURBS, the domain maximum is returned.
      Returns:
      the ending value for a period if the spline is periodic; otherwise the domain maximum
    • getPeriod

      public double getPeriod()
      Get the period. A periodic NURBS explicitly handles a range of values of the parameters. For other values of the parameter, the parameter is shifted by the period until it falls within this range. For a periodic NURBS, the period is numerically equal to getPeriodEnd()-getPeriodStart().
      Returns:
      the period for a periodic spline; 0.0 if the spline is not periodic
    • getDegree

      public int getDegree()
      Get the degree if this NURBS. The smallest degree is zero (some authors use 1, in which case the degree will be larger by 1 than the value returned by this method).
      Returns:
      this NURBS' degree.
    • N

      public final double N(int i, int p, double u)
      Compute the value of a NURBS's basis function.
      Parameters:
      i - a integer representing a knot span with a value equal to the index of the knot at the start of a span
      p - the degree of the basis function
      u - the value of the NURBS's parameter
      Returns:
      the value of the basis function at point u
    • getDomainMin

      public double getDomainMin()
      Description copied from interface: RealValuedDomainOps
      Get the minimum value in the domain of the function.
      Specified by:
      getDomainMin in interface RealValuedDomainOps
      Overrides:
      getDomainMin in class VectorValuedFunction
      Returns:
      the minimum value
    • domainMinClosed

      public boolean domainMinClosed()
      Description copied from interface: RealValuedDomainOps
      Determine if the domain minimum is in the domain.
      Specified by:
      domainMinClosed in interface RealValuedDomainOps
      Overrides:
      domainMinClosed in class VectorValuedFunction
      Returns:
      true if the domain minimum is in the domain; false if it is the greatest lower bound for the domain
    • getDomainMax

      public double getDomainMax()
      Description copied from interface: RealValuedDomainOps
      Get the maximum value in the domain of the function.
      Specified by:
      getDomainMax in interface RealValuedDomainOps
      Overrides:
      getDomainMax in class VectorValuedFunction
      Returns:
      the maximum value
    • domainMaxClosed

      public boolean domainMaxClosed()
      Description copied from interface: RealValuedDomainOps
      Determine if the domain maximum is in the domain.
      Specified by:
      domainMaxClosed in interface RealValuedDomainOps
      Overrides:
      domainMaxClosed in class VectorValuedFunction
      Returns:
      true if the domain maximum is in the domain; false if it is the least upper bound for the domain
    • valueAt

      public void valueAt(double[] array, int off, double u) throws IllegalArgumentException
      Description copied from class: VectorValuedFunction
      Call the function, storing the value in an array.
      Specified by:
      valueAt in class VectorValuedFunction
      Parameters:
      array - the array used to store the results of the function call.
      off - the offset into the array at which to store the results of the function call.
      u - the function's argument
      Throws:
      IllegalArgumentException - the function's argument was out of range
    • derivAt

      public void derivAt(double[] array, int off, double u) throws IllegalArgumentException
      Description copied from class: VectorValuedFunction
      Evaluate the function's first derivative, storing the results.
      Overrides:
      derivAt in class VectorValuedFunction
      Parameters:
      array - the array used to store the results.
      off - the offset into the array at which to store the results.
      u - the function's argument
      Throws:
      IllegalArgumentException - the function's argument was out of range
    • secondDerivAt

      public void secondDerivAt(double[] array, int off, double u)
      Description copied from class: VectorValuedFunction
      Evaluate the function's second derivative, storing the results.
      Overrides:
      secondDerivAt in class VectorValuedFunction
      Parameters:
      array - the array used to store the results.
      off - the offset into the array at which to store the results.
      u - the function's argument