- All Implemented Interfaces:
RealValuedDomainOps
,VADomainOps
This class supports both periodic and non-periodic B-splines, and
is very similar to the BSpline
class: the difference is that
the values it computes are arrays of double-precision numbers instead
of single numbers.
Periodic B-splines can be used to approximate period functions.
Additional control points and knots are added for periodic B-splines.
(see below).
Constructors differ from those in the BSpline
class in two
ways: there is an initial argument giving a dimension (the length
for the arrays that represent the spline's values), and in some
cases, the corresponding argument arrays are larger, scaled up by
the dimension, and stored so that the array components representing
a given point are adjacent.
A B-spline 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 B-spline must satisfy p = m - n - 1.
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}$$ The value of the function $f$ defined by this spline at a point u is defined by $$f(u) = \sum^n_{i=0} P_iN_{i,p}(u)$$ 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]), and at at the end points of this interval, the values will match, as will their derivatives.
The documentation for the constructor
BSplineArray(int,int,double[],double[],boolean)
describes how
periodic and non-periodic B-splines are created.
-
Constructor Summary
ConstructorsConstructorDescriptionBSplineArray
(int dim, double[] knots, double[] cpoints) Constructor for open B-splines.BSplineArray
(int dim, int degree, double[] knots, boolean periodic, double[] x, double[] y) Constructor specifying a B-spline's degree and knots, and fitting the spline to a set of data points.BSplineArray
(int dim, int degree, double[] knots, boolean periodic, double[] x, double[] y, double[] sigma) Constructor specifying a B-spline's degree and knots, and fitting the spline to a set of data points with errors.BSplineArray
(int dim, int degree, double[] knots, double[] cpoints, boolean periodic) Constructor.BSplineArray
(int dim, int degree, int n, BSpline.Mode mode, double[] x, double[] y) Constructor specifying a B-spline's degree, number of control points, mode, and a set of Y values for given X values.BSplineArray
(int dim, int degree, int n, BSpline.Mode mode, double[] x, double[] y, double[] sigma) Constructor specifying a B-spline's degree, number of control points, mode, and a set of Y values and their standard deviations for given X values. -
Method Summary
Modifier and TypeMethodDescriptionvoid
derivAt
(double[] array, int off, double u) Evaluate the function's first derivative, storing the results.boolean
Determine if the domain maximum is in the domain.boolean
Determine if the domain minimum is in the domain.int
Get the degree if this B-spline.int
Get the dimension of the vectors returned by a vector-valued function.double
Get the maximum value in the domain of the function.double
Get the minimum value in the domain of the function.double
Get the period.double
Get the ending value for a period.double
Get the starting value for a period.boolean
Determine if the spline is a periodic spline.final double
N
(int i, int p, double u) Compute the value of a B-Spline's basis function.void
secondDerivAt
(double[] array, int off, double u) Evaluate the function's second derivative, storing the results.void
valueAt
(double[] array, int off, double u) Call the function, storing the value in an array.Methods inherited from class org.bzdev.math.VectorValuedFunction
derivAt, derivAt, domainMaxClosed, domainMinClosed, getDomainMax, getDomainMin, isInDomain, isInDomain, secondDerivAt, secondDerivAt, valueAt, valueAt
Methods inherited from class org.bzdev.math.VectorValuedFunctionVA
derivAt, maxArgLength, minArgLength, secondDerivAt, valueAt
-
Constructor Details
-
BSplineArray
Constructor for open B-splines. A full description is provided by the constructorBSplineArray(int,int,double[],double[],boolean)
. The degree of the B-spline is equal to knots.length - cpoints.length - 1.- Parameters:
dim
- the length of the array of valuesknots
- the knots for the B-spline to be constructedcpoints
- the control points for the B-spline to be constructed- Throws:
IllegalArgumentException
- See Also:
-
BSplineArray
public BSplineArray(int dim, int degree, double[] knots, double[] cpoints, boolean periodic) throws IllegalArgumentException Constructor. There are two cases depending on whether the B-spline 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 B-spline, then the following constraint must be satisfied:n + p + 1 = m
orm - n - 1 = p.
orm - p - 1 = n.
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. 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.
- Parameters:
dim
- the dimenions for this vector-valued functiondegree
- a non-negative integer giving the degree of the B-spline to be constructedknots
- the knots for the B-spline to be constructedcpoints
- the control points for the B-spline to be constructedperiodic
- true if the spline is periodic; false if it is open.- Throws:
IllegalArgumentException
-
BSplineArray
public BSplineArray(int dim, int degree, double[] knots, boolean periodic, double[] x, double[] y) Constructor specifying a B-spline's degree and knots, and fitting the spline to a set of data points. The use of knots is the same as that for the constructorBSplineArray(int,int,double[],double[],boolean)
.- Parameters:
dim
- the length of the array of valuesdegree
- the degree of the B-spline that will be createdknots
- the knots the B-spline usesperiodic
- true if the B-spline is periodic, false otherwisex
- values in the domain of the spliney
- values in the range of the spline
-
BSplineArray
public BSplineArray(int dim, int degree, double[] knots, boolean periodic, double[] x, double[] y, double[] sigma) Constructor specifying a B-spline's degree and knots, and fitting the spline to a set of data points with errors. The use of knots is the same as that for the constructorBSplineArray(int,int,double[],double[],boolean)
.- Parameters:
dim
- the length of the array of valuesdegree
- the degree of the B-spline that will be createdknots
- the knots the B-spline usesperiodic
- true if the B-spline is periodic, false otherwisex
- values in the domain of the spliney
- values in the range of the splinesigma
- the standard deviations for the values provided by the argument y
-
BSplineArray
Constructor specifying a B-spline's degree, number of control points, mode, and a set of Y values for given X values. The number of X,Y data points must be larger than the number of control points.- Parameters:
dim
- the dimenions for this vector-valued functiondegree
- the degree of the B-spline that will be createdn
- the number of control pointsmode
- the mode for the B-spline (either BSpline.Mode.UNCLAMPED, BSpline.Mode.CLAMPED, BSpline.Mode.CLAMPED_LEFT, BSpline.Mode.CLAMPED_RIGHT, or BSpline.Mode.PERIODIC); null for the default (BSplineMode.UNCLAMPED)x
- values in the domain of the spliney
- values in the range of the spline
-
BSplineArray
public BSplineArray(int dim, int degree, int n, BSpline.Mode mode, double[] x, double[] y, double[] sigma) Constructor specifying a B-spline's degree, number of control points, mode, and a set of Y values and their standard deviations for given X values. The number of X,Y data points must be larger than the number of control points.- Parameters:
dim
- the dimenions for this vector-valued functiondegree
- the degree of the B-spline that will be createdn
- the number of control pointsmode
- the mode for the B-spline (either BSpline.Mode.UNCLAMPED, BSpline.Mode.CLAMPED, BSpline.Mode.CLAMPED_LEFT, BSpline.Mode.CLAMPED_RIGHT, or BSpline.Mode.PERIODIC); null for the default (BSplineMode.UNCLAMPED)x
- values in the domain of the spliney
- values in the range of the splinesigma
- the standard deviations for the values provided by the argument y
-
-
Method Details
-
getDimension
public int getDimension()Description copied from class:VectorValuedFunctionVA
Get the dimension of the vectors returned by a vector-valued function.- Overrides:
getDimension
in classVectorValuedFunctionVA
- Returns:
- the dimension of the vectors returned by this vector-valued function
-
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 B-spline 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 B-spline, 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 B-spline 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 B-spline, 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 B-spline 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 B-spline, 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 B-spline. 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 B-spline's degree.
-
N
public final double N(int i, int p, double u) Compute the value of a B-Spline'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 spanp
- the degree of the basis functionu
- the value of the B-spline'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 interfaceRealValuedDomainOps
- Overrides:
getDomainMin
in classVectorValuedFunction
- 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 interfaceRealValuedDomainOps
- Overrides:
domainMinClosed
in classVectorValuedFunction
- 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 interfaceRealValuedDomainOps
- Overrides:
getDomainMax
in classVectorValuedFunction
- 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 interfaceRealValuedDomainOps
- Overrides:
domainMaxClosed
in classVectorValuedFunction
- Returns:
- true if the domain maximum is in the domain; false if it is the least upper bound for the domain
-
valueAt
Description copied from class:VectorValuedFunction
Call the function, storing the value in an array.- Specified by:
valueAt
in classVectorValuedFunction
- 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
Description copied from class:VectorValuedFunction
Evaluate the function's first derivative, storing the results.- Overrides:
derivAt
in classVectorValuedFunction
- 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 classVectorValuedFunction
- 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
-