public class CubicHermiteSpline1d extends Diff1Function1x1Base implements java.lang.Iterable<CubicHermiteSpline1d.Knot>
x/y
plane. The spline is described by a series of segments, each
specifying an interval of x
within which y
is interpolated
cubicly. The spline is defined by a sequence of knots delimiting the
boundaries of these segments, with each knot specifying y
and its
derivative for a given value of x
.Modifier and Type | Class and Description |
---|---|
static class |
CubicHermiteSpline1d.Knot
Describes a single knot for a specific value of x.
|
Constructor and Description |
---|
CubicHermiteSpline1d()
Creates a empty spline
|
CubicHermiteSpline1d(CubicHermiteSpline1d spline)
Creates a spline from a copy of an existing one.
|
CubicHermiteSpline1d(double[] values)
Creates a spline from data containing the x, y and y derivative values
for each knot point.
|
CubicHermiteSpline1d(double[] x,
double[] y,
double[] dy)
Creates a spline from data containing the x, y and y derivative values
for each knot point.
|
Modifier and Type | Method and Description |
---|---|
CubicHermiteSpline1d.Knot |
addKnot(double x,
double y,
double dy)
Adds another knot point to this cubic hermite spline, consisting of an x
coordinate, along with y and y derivative values.
|
void |
addKnot(int idx,
CubicHermiteSpline1d.Knot knot) |
void |
clearKnots() |
CubicHermiteSpline1d |
clone() |
CubicHermiteSpline1d |
copy()
Creates a copy of this spline.
|
boolean |
equals(CubicHermiteSpline1d curve) |
double |
eval(double x)
Evaluates the function at a prescribed input value.
|
double |
eval(DoubleHolder deriv,
double x)
Evaluates both the value and first derivative of this function at a
specified input value.
|
double |
evalDeriv(double x)
Evaluates first derivative of this function at a
specified input value.
|
double |
evalDy(double x)
Evaluates the y derivative value at a specific x value.
|
double |
evalDy(double x,
double alpha)
Evaluates the y derivative of the function composed of this spline plus a
linear term
alpha x at a specific x value. |
double |
evalDy2(double x)
Evaluates the second y derivative value at a specific x value.
|
double |
evalDy3(double x)
Evaluates the third y derivative value spline at a specific x
value.
|
double |
evalY(double x)
Evaluates the y value for this spline at a specific x value.
|
double |
evalY(double x,
double alpha)
Evaluates the y value of the function composed of this spline plus a linear
term
alpha x at a specific x value. |
CubicHermiteSpline1d.Knot |
getFirstKnot() |
CubicHermiteSpline1d.Knot |
getKnot(int idx) |
CubicHermiteSpline1d.Knot |
getLastKnot() |
CubicHermiteSpline1d.Knot |
getNextKnot(double x)
Find the knot immediately following x.
|
CubicHermiteSpline1d.Knot |
getPreviousKnot(double x)
Find the knot immediately preceeding x.
|
boolean |
isInvertible()
Queries whether this spline is invertible.
|
boolean |
isWritable()
Returns
true if this component should in fact be written to
secondary storage. |
java.util.Iterator<CubicHermiteSpline1d.Knot> |
iterator() |
int |
numKnots() |
boolean |
removeKnot(CubicHermiteSpline1d.Knot knot) |
void |
scaleX(double s)
Scales the x values of this spline.
|
void |
scaleY(double s)
Scales the y values of this spline.
|
void |
scan(ReaderTokenizer rtok,
java.lang.Object ref)
Scans this spline from a ReaderTokenizer.
|
void |
set(CubicHermiteSpline1d spline)
Sets this spline to be a copy of another spline.
|
void |
setNatural(double[] x,
double[] y)
Sets this spline to a natural cubic spline for a set of knot points whose
x and y positions are given.
|
void |
setNatural(double[] x,
double[] y,
double ddy0,
double ddyL)
Sets this spline to a natural cubic spline for a set of knot points whose
x and y positions are given.
|
double |
solveX(double y)
Solves for the x value given a specific y value.
|
double |
solveX(double y,
double alpha)
Solves for the x value given a specific y value of the function defined
by this spline plus a linear term
alpha x . |
void |
updateCoefficients() |
void |
updateCoefficients(CubicHermiteSpline1d.Knot knot) |
void |
write(java.io.PrintWriter pw,
NumberFormat fmt,
java.lang.Object ref)
Writes a text description of this spline to a PrintWriter.
|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
eval, evalDeriv
eval, inputSize
public CubicHermiteSpline1d()
public CubicHermiteSpline1d(double[] x, double[] y, double[] dy)
x
- x values. These should be in ascending order. If they are not,
they will be sorted into ascending order (internally) with the y and
derivative values reordered appropriately. All x values should also be
unique.y
- y valuesdy
- y derivative valuespublic CubicHermiteSpline1d(double[] values)
3
n
entries, where n
is the number of knots. The entries
should gave the form
x0 y0 dy0 x1 y1 dy1 x2 y2 dy2 ...where
xi
, yi
, and dyi
are the x, y
and derivative values for the i-th knot.
The x values should be in ascending order. If they are not, they will be sorted into ascending order (internally) with the y and derivative values reordered appropriately. All x values should also be unique.
values
- x, y, and derivative values for the knots.public CubicHermiteSpline1d(CubicHermiteSpline1d spline)
spline
- spline to copypublic void setNatural(double[] x, double[] y)
setNatural(double[],double[],double,double)
with ddy0
and
ddyL
both set to 0.x
- knot point x valuesy
- knot point y valuespublic void setNatural(double[] x, double[] y, double ddy0, double ddyL)
x
- knot point x valuesy
- knot point y valuesddy0
- desired second derivative at the first knotddyL
- desired second derivative at the last knotpublic CubicHermiteSpline1d.Knot addKnot(double x, double y, double dy)
public void addKnot(int idx, CubicHermiteSpline1d.Knot knot)
public boolean removeKnot(CubicHermiteSpline1d.Knot knot)
public void clearKnots()
public CubicHermiteSpline1d.Knot getPreviousKnot(double x)
knot.x0 <= x
. If no such knot exists, null
is returned.x
- value for which previous knot is soughtpublic CubicHermiteSpline1d.Knot getNextKnot(double x)
knot.x0 > x
. If no such knot exists, null
is returned.x
- value for which next knot is soughtpublic double evalY(double x)
x
- value at which y should be evaluatedpublic double evalY(double x, double alpha)
alpha x
at a specific x value. Values which are outside
the specified knot range are extrapolated based on y and dy values at the
end point knots. An empty spline evaluates to 0.x
- value at which y should be evaluatedalpha
- slope of the additional linear termpublic double evalDy(double x)
x
- value at which the y derivative should be evaluatedpublic double evalDy(double x, double alpha)
alpha x
at a specific x value. Values which are
outside the specified knot range are extrapolated based on y and dy
values at the end point knots. An empty spline evaluates to 0.x
- value at which the y derivative should be evaluatedalpha
- slope of the additional linear termpublic double evalDy2(double x)
x
- value at which the second y derivative should be evaluatedpublic double evalDy3(double x)
x
- value at which the second y derivative should be evaluatedpublic double eval(double x)
Diff1Function1x1Base
eval
in interface Function1x1
eval
in class Diff1Function1x1Base
x
- input valuepublic double eval(DoubleHolder deriv, double x)
Diff1Function1x1Base
eval
in interface Diff1Function1x1
eval
in class Diff1Function1x1Base
deriv
- if non-null, returns the derivative valuex
- input valuepublic double evalDeriv(double x)
Diff1Function1x1
evalDeriv
in interface Diff1Function1x1
x
- input valuepublic void scan(ReaderTokenizer rtok, java.lang.Object ref) throws java.io.IOException
3 n
numeric values giving
the x, y amd y derivative values for each of the n
knots, and
terminated with a closing square bracket. Whitespace characters are
ignored. For example,
[ 0.0 4.0 1.0 2.0 5.0 -1.0 ]describes a spline with two knots, with the first at
x = 0.0
and
having y and y derivative values of 4.0
and 1.0
, and the
second at x = 2.0
with y and y derivative values of 5.0
and -1.0
.scan
in interface Scannable
scan
in class Diff1Function1x1Base
rtok
- Tokenizer from which to scan the splineref
- optional reference object (not used)java.io.IOException
- if an I/O or formatting error occuredpublic void write(java.io.PrintWriter pw, NumberFormat fmt, java.lang.Object ref) throws java.io.IOException
scan
.write
in interface Scannable
write
in class Diff1Function1x1Base
pw
- writer to which the spline should be writtenfmt
- describes how the numbers should be formattedref
- optional reference object (not used)java.io.IOException
- if an I/O error occuredpublic boolean isWritable()
true
if this component should in fact be written to
secondary storage. This gives subclasses control over whether or
not they are actually written out.isWritable
in interface Scannable
isWritable
in class Diff1Function1x1Base
true
if this component should be written to
secondary storage.public int numKnots()
public CubicHermiteSpline1d.Knot getKnot(int idx)
public CubicHermiteSpline1d.Knot getFirstKnot()
public CubicHermiteSpline1d.Knot getLastKnot()
public void updateCoefficients(CubicHermiteSpline1d.Knot knot)
public void updateCoefficients()
public java.util.Iterator<CubicHermiteSpline1d.Knot> iterator()
iterator
in interface java.lang.Iterable<CubicHermiteSpline1d.Knot>
public void set(CubicHermiteSpline1d spline)
spline
- spline to copypublic void scaleX(double s)
s
- scale factorpublic void scaleY(double s)
s
- scale factorpublic boolean isInvertible()
true
if this spline is invertiblepublic double solveX(double y)
y
- value for which x should be solvedImproperStateException
- if the spline is not invertiblejava.lang.IllegalArgumentException
- if the spline is invertible
but y is out of rangepublic double solveX(double y, double alpha)
alpha x
. In order to do this,
the spline must be invertible, and the sign of alpha
must be
consistent with its monotonicity. Y values outside the nominal range are
extrapolated based on the x and 1/dy values at the end knots.y
- value for which x should be solvdealpha
- slope of the additional linear termImproperStateException
- if the spline is not invertiblejava.lang.IllegalArgumentException
- if the sign of alpha
is inconsistent with the spline's monotonicitypublic CubicHermiteSpline1d copy()
public boolean equals(CubicHermiteSpline1d curve)
public CubicHermiteSpline1d clone()
clone
in interface Clonable
clone
in class Diff1Function1x1Base