- All Implemented Interfaces:
DoubleUnaryOperator
,RealValuedDomainOps
,RealValuedFunctOps
,RealValuedFunctVAOps
,VADomainOps
- Direct Known Subclasses:
CubicBezierSpline1
,CubicSpline1
,CubicSpline2
The spline approximates a function f such that y = f(x). When the
knots (the points the spline passes through) are evenly spaced in
terms of their X values, look-up is faster than otherwise. Because
of this, two classes are provided CubicSpline1
for splines based on knots whose X values are evenly spaced and
CubicSpline2
for knots whose X values have an
arbitrarily spacing.
A spline can be created in any of several modes described by
the enumeration CubicSpline.Mode
.
The default mode is "NATURAL", which sets the second derivatives
(but not necessarily the third derivative) to zero at the end
points. For all other modes, a constructor specifying a mode is
required. Some modes base the spline not only on the values at
specific knots, but on the derivatives at all or a subset of these
points.
For all but one of the supported modes, the second derivative of the spline (e.g., the function the spline computes) is a continuous function. The mode HERMITE is an exception: Hermite splines have continuous first derivatives, but second derivatives may have discontinuities.
Methods are available for determining the spline's mode, the minimum and maximum values it can compute, the value at a specified point, the derivative at a specified point, whether the values that define the spline are strictly monotonic, and (if the spline is strictly monotonic) the value of the spline's inverse at a particular point.
- See Also:
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class org.bzdev.math.RealValuedFunctionVA
RealValuedFunctionVA.Linear
-
Field Summary
Fields inherited from class org.bzdev.math.RealValuedFunction
xFunction
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract int
Count the number of knots in this spline.abstract double[]
Get the coefficients βi for the segments of this spline when represented as a sum of Bernstein polynomials $\sum^3_{i=0}\beta_i B_{i,3}(t)$ where t∈[0,1].abstract double
Get the inversion limit.abstract CubicSpline.Mode
getMode()
Get the spline's mode.abstract double
inverseAt
(double y) For a spline that represents the function y = f(x), get the value of its inverse x=f-1(y).abstract boolean
Determine if the values defining a spline form a strictly monotonic sequence of numbers.abstract void
setInversionLimit
(double limit) Set the inversion limit.abstract boolean
verify
(double limit) Verify that the spline's polynomials compute various values consistently to an accuracy given by the argument The cubic polynomials that the spline uses are supposed to compute the same value, first derivative, and second derivative where they meet, and each mode places constraints on the end points.Methods inherited from class org.bzdev.math.RealValuedFunction
deriv, deriv, derivAt, derivAt, domainMaxClosed, domainMaxClosed, domainMinClosed, domainMinClosed, getDomainMax, getDomainMax, getDomainMin, getDomainMin, isInDomain, isInDomain, secondDeriv, secondDerivAt, secondDerivAt, valueAt, valueAt
Methods inherited from class org.bzdev.math.RealValuedFunctionVA
jacobian, jacobian, maxArgLength, minArgLength
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.bzdev.math.RealValuedFunctOps
andThen, andThen, applyAsDouble, compose, compose, maxArgLength, minArgLength
-
Constructor Details
-
CubicSpline
public CubicSpline()
-
-
Method Details
-
getMode
Get the spline's mode.- Returns:
- the mode for the spline.
- See Also:
-
verify
public abstract boolean verify(double limit) Verify that the spline's polynomials compute various values consistently to an accuracy given by the argument The cubic polynomials that the spline uses are supposed to compute the same value, first derivative, and second derivative where they meet, and each mode places constraints on the end points.- Parameters:
limit
- the accuracy limit- Returns:
- true of the tests succeed; false otherwise
-
isStrictlyMonotonic
public abstract boolean isStrictlyMonotonic()Determine if the values defining a spline form a strictly monotonic sequence of numbers.- Returns:
- true if the values are strictly monotonic; false otherwise
-
getInversionLimit
public abstract double getInversionLimit()Get the inversion limit. Computing the inverse in most cases requires solving a cubic equation, with valid solutions being in the range [0, 1]. The inversion limit allows solutions in the range [-inversionLimit, 1+inversionLimit] to be accepted, with values outside of the interval [0, 1] replaced by 0 or 1, whichever is closer. The use of an inversion limit allows for round-off errors.- Returns:
- the inversion limit
-
setInversionLimit
public abstract void setInversionLimit(double limit) Set the inversion limit. Computing the inverse in most cases requires solving a cubic equation, with valid solutions being in the range [0, 1]. The inversion limit allows solutions in the range [-inversionLimit, 1+inversionLimit] to be accepted, with values outside of the interval [0, 1] replaced by 0 or 1, whichever is closer. The use of an inversion limit allows for round-off errors.- Parameters:
limit
- the invrsion limit
-
inverseAt
For a spline that represents the function y = f(x), get the value of its inverse x=f-1(y).- Parameters:
y
- the argument for the inverse function- Returns:
- the inverse evaluated at y
- Throws:
IllegalArgumentException
- an inverse could not be computed.
-
countKnots
public abstract int countKnots()Count the number of knots in this spline.- Returns:
- the number of knots
-
getBernsteinCoefficients
public abstract double[] getBernsteinCoefficients()Get the coefficients βi for the segments of this spline when represented as a sum of Bernstein polynomials $\sum^3_{i=0}\beta_i B_{i,3}(t)$ where t∈[0,1].There are 4 coefficients per segment, but for a spline, the last coefficient of one segment is the first for the next. With the exception of the initial coefficient, the first coefficient for each segment is not listed, to avoid duplications. The value of the coefficients match the points the spline is guaranteed to pass through at indices 0, 3, 6, 9, etc. These represent the i=0 case in the sum given above. For segment j, βi = array[3*j + i] for i ∈ [0,3] and j ∈ [0, n], where n is the number of segments.
One use of this method is to provide the control points for a path - for example, the classes
Path2D
,Path3D
, and their subclasses.- Returns:
- the coefficients
-