uk.ac.starlink.diva.interp
Class AbstractInterpolator

java.lang.Object
  extended by uk.ac.starlink.diva.interp.AbstractInterpolator
All Implemented Interfaces:
Interpolator
Direct Known Subclasses:
LinearInterp

public abstract class AbstractInterpolator
extends Object
implements Interpolator

Abstract base class for all Interpolators. Interpolation assumes a monotonic set of X coordinates (the ordinates) and an arbitrary set of Y coordinates (the data values). Interpolation of the Y coordinates is provided by the specification of any possible X coordinate or array of X coordinates.

Extenders of this class need to at implement the interpolate(double), and probably a few others.

Version:
$Id$
Author:
Peter W. Draper

Field Summary
protected  double[] c
          Some coefficients, if any associated with the fit.
protected  boolean decr
          Whether the X coordinates are monotonically decreasing.
protected  double[] x
          The X coordinates.
protected  double[] y
          The Y coordinates.
 
Constructor Summary
AbstractInterpolator()
          Create an instance with no coordinates.
AbstractInterpolator(double[] x, double[] y)
          Create an instance with the given coordinates.
 
Method Summary
 void appendValue(double newx, double newy)
          Append a new position to the existing coordinates.
protected  int[] binarySearch(double[] array, double value)
          Return two indices of the values in an array that lie above and below a given value.
 double evalYData(double xp)
          Return the interpolated value corresponding to some arbitrary X coordinate.
 double[] evalYDataArray(double[] xps)
          Return an array of interpolated value corresponding to some array of arbitrary X coordinates.
 int getCount()
          Get the number of coordinate positions that are being used by this interpolator.
 double getXCoord(int index)
          Get an X coordinate by index.
 double[] getXCoords()
          Get the X coordinates.
 double getYCoord(int index)
          Get a Y coordinate by index.
 double[] getYCoords()
          Get the Y coordinates.
abstract  double interpolate(double xp)
          Return the interpolated value corresponding to some arbitrary X coordinate.
 boolean isFull()
          Return if the Interpolator is full.
 boolean isIncreasing()
          Return the direction being used by this interpolator.
 void setCoords(double[] x, double[] y, boolean check)
          Set or reset the coordinates used by this interpolator.
 int stepGuess()
          A guess at the number of steps needed between the actual X coordinates that may be used to draw a reasonable representation of the curve being interpolated.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

x

protected double[] x
The X coordinates. Must be monotonic. These form the basis for interpolation of the Y coordinates.


y

protected double[] y
The Y coordinates. There should be at least as many of these values as X coordinates.


c

protected double[] c
Some coefficients, if any associated with the fit.


decr

protected boolean decr
Whether the X coordinates are monotonically decreasing.

Constructor Detail

AbstractInterpolator

public AbstractInterpolator()
Create an instance with no coordinates. A call to setCoords must be made before any other methods.


AbstractInterpolator

public AbstractInterpolator(double[] x,
                            double[] y)
Create an instance with the given coordinates. Interpolation is by X coordinate see the interpolate method. The X coordinates should be monotonic, either increasing or decreasing. Same value X coordinates are not allowed.

Parameters:
x - the X coordinates.
y - the Y coordinates.
Method Detail

stepGuess

public int stepGuess()
Description copied from interface: Interpolator
A guess at the number of steps needed between the actual X coordinates that may be used to draw a reasonable representation of the curve being interpolated.

Specified by:
stepGuess in interface Interpolator

setCoords

public void setCoords(double[] x,
                      double[] y,
                      boolean check)
Description copied from interface: Interpolator
Set or reset the coordinates used by this interpolator.

Specified by:
setCoords in interface Interpolator
Parameters:
x - the X coordinates.
y - the Y coordinates.
check - whether to check the monotonic direction (compares 0 and 1 values of x). Use this when you need to preserve the direction temporarily even though the order may currently be switched, but take care to reorder before interpolating.

isIncreasing

public boolean isIncreasing()
Description copied from interface: Interpolator
Return the direction being used by this interpolator.

Specified by:
isIncreasing in interface Interpolator

appendValue

public void appendValue(double newx,
                        double newy)
Description copied from interface: Interpolator
Append a new position to the existing coordinates.

Specified by:
appendValue in interface Interpolator

getCount

public int getCount()
Description copied from interface: Interpolator
Get the number of coordinate positions that are being used by this interpolator.

Specified by:
getCount in interface Interpolator
Returns:
the number of positions that will be used.

isFull

public boolean isFull()
Description copied from interface: Interpolator
Return if the Interpolator is full. This may mean that the instance will ignore or refuse any further vectices.

Specified by:
isFull in interface Interpolator

getXCoords

public double[] getXCoords()
Description copied from interface: Interpolator
Get the X coordinates.

Specified by:
getXCoords in interface Interpolator
Returns:
the X coordinate array. Note this is not a copy, if you modify it you need to re-apply setCoords.

getXCoord

public double getXCoord(int index)
Description copied from interface: Interpolator
Get an X coordinate by index. If the index is invalid an out of bound exception will be thrown.

Specified by:
getXCoord in interface Interpolator
Returns:
the X coordinate.

getYCoords

public double[] getYCoords()
Description copied from interface: Interpolator
Get the Y coordinates.

Specified by:
getYCoords in interface Interpolator
Returns:
the Y coordinate array. Note this is not a copy, if you modify it you need to re-apply setCoords.

getYCoord

public double getYCoord(int index)
Description copied from interface: Interpolator
Get a Y coordinate by index. If the index is invalid an out of bound exception will be thrown.

Specified by:
getYCoord in interface Interpolator
Returns:
the Y coordinate.

interpolate

public abstract double interpolate(double xp)
Description copied from interface: Interpolator
Return the interpolated value corresponding to some arbitrary X coordinate.

Specified by:
interpolate in interface Interpolator
Parameters:
xp - the X coordinate at which an interpolated Y coordinate is required.
Returns:
the interpolated value.

evalYData

public double evalYData(double xp)
Description copied from interface: Interpolator
Return the interpolated value corresponding to some arbitrary X coordinate.

Specified by:
evalYData in interface Interpolator
Parameters:
xp - the X coordinate at which an interpolated Y coordinate is required.
Returns:
the interpolated value.

evalYDataArray

public double[] evalYDataArray(double[] xps)
Description copied from interface: Interpolator
Return an array of interpolated value corresponding to some array of arbitrary X coordinates.

Specified by:
evalYDataArray in interface Interpolator
Parameters:
xps - the X coordinates at which interpolated Y coordinates are required.
Returns:
the interpolated values.

binarySearch

protected int[] binarySearch(double[] array,
                             double value)
Return two indices of the values in an array that lie above and below a given value. If the value doesn't lie within the range the two indices are returned as the nearest end point. The array of values must be increasing or decreasing monotonically.

Parameters:
array - the array of values to be searched
value - the value to be located


Copyright © 2015 Central Laboratory of the Research Councils. All Rights Reserved.