ptolemy.math
Class Interpolation

java.lang.Object
  extended by ptolemy.math.Interpolation

public class Interpolation
extends java.lang.Object

This class provides algorithms to do interpolation. Currently, zero, first, and third order interpolations are supported. These are the interpolation orders most often used in practice. zero order interpolation holds the last reference value; first order does linear interpolation; and third order interpolation is based on the Hermite curves in chapter 11 of "Computer Graphic, Principles and Practice", by Foley, van Dam, Feiner and Hughes, 2nd ed. in C, 1996.

The setValues() method specifies the reference values as a double array. setIndexes() specifies the indexes of those values as an int array. These two arrays must have the same length, and the indexes must be increasing and non-negative; otherwise an exception will be thrown. The values are periodic if a positive period is set by setPeriod(). In this case, the period must be greater than the largest index, and values within the index range 0 to (period-1) are repeated indefinitely. If the period is zero, the values are not periodic, and the values outside the range of the indexes are considered to be 0.0. The interpolation order is set by setOrder().

The default reference values are {1.0, 0.0} and the indexes are {0, 1}. The default period is 2 and the order is 0.

Since:
Ptolemy II 0.4
Version:
$Id: Interpolation.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Sarah Packman, Yuhong Xiong
Accepted Rating:
red (cxh)
Proposed Rating:
Yellow (yuhong)

Field Summary
private  int[] _indexes
           
private  int _order
           
private  int _period
           
private  double[] _values
           
 
Constructor Summary
Interpolation()
          Construct an instance of Interpolation using the default parameters.
 
Method Summary
private  double _hermite(int index, int iStart, double vStart, double tanStart, int iEnd, double vEnd, double tanEnd)
           
 int[] getIndexes()
          Return the reference indexes.
 int getOrder()
          Return the interpolation order.
 int getPeriod()
          Return the value repetition period.
 double[] getValues()
          Return the reference values.
 double interpolate(int index)
          Return the interpolation result for the specified index.
 void setIndexes(int[] indexes)
          Set the reference indexes.
 void setOrder(int order)
          Set the interpolation order.
 void setPeriod(int period)
          Set the value repetition period.
 void setValues(double[] values)
          Set the reference values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_indexes

private int[] _indexes

_values

private double[] _values

_period

private int _period

_order

private int _order
Constructor Detail

Interpolation

public Interpolation()
Construct an instance of Interpolation using the default parameters.

Method Detail

getIndexes

public int[] getIndexes()
Return the reference indexes.

Returns:
An int array.
See Also:
setIndexes(int[])

getOrder

public int getOrder()
Return the interpolation order.

Returns:
An int.
See Also:
setOrder(int)

getPeriod

public int getPeriod()
Return the value repetition period.

Returns:
An int.
See Also:
setPeriod(int)

getValues

public double[] getValues()
Return the reference values.

Returns:
An double array.
See Also:
setValues(double[])

interpolate

public double interpolate(int index)
Return the interpolation result for the specified index.

Parameters:
index - The point of interpolation. Can be negative
Returns:
A double.
Throws:
java.lang.IllegalStateException - If the index and value arrays do not have the same length, or the period is not 0 and not greater than the largest index.

setIndexes

public void setIndexes(int[] indexes)
Set the reference indexes.

Parameters:
indexes - An int array.
Throws:
java.lang.IllegalArgumentException - If the argument array is not increasing and non-negative.
See Also:
getIndexes()

setOrder

public void setOrder(int order)
Set the interpolation order.

Parameters:
order - An int.
Throws:
java.lang.IllegalArgumentException - If the order is not 0, 1, or 3.
See Also:
getOrder()

setPeriod

public void setPeriod(int period)
Set the value repetition period.

Parameters:
period - An int.
Throws:
java.lang.IllegalArgumentException - If the period is negative.
See Also:
getPeriod()

setValues

public void setValues(double[] values)
Set the reference values.

Parameters:
values - A double array.
See Also:
getValues()

_hermite

private double _hermite(int index,
                        int iStart,
                        double vStart,
                        double tanStart,
                        int iEnd,
                        double vEnd,
                        double tanEnd)