multigraph
Class LinearInterpolator

java.lang.Object
  extended bymultigraph.LinearInterpolator

public class LinearInterpolator
extends java.lang.Object

Handle linear interpolation of a single floating point (double) variable.

In computer graphics and other mathematical software there is often a need to interpolate one range of values to another. This class encapsulates the mathematics for that simple but very common process, providing several convenient methods for performing the interpolation and related operations.

The general idea is that you create a LinearInterpolator instance by specifying domain endpoints [a,b] and range endpoints [A,B]. That creates an interpolator which takes a to A and b to B. You then call its interp method to perform the interpolation as many times as you want.

There are also several other methods for performing computations related to the interpolation.

Version:
$Id: LinearInterpolator.java,v 1.1.1.1 2004/11/30 22:30:41 mphillips Exp $
Author:
Mark Phillips

Constructor Summary
LinearInterpolator(double A, double B, double a, double b)
          Create a linear interpolator which maps [a,b] to [A,B]
LinearInterpolator(double A, double B, long a, long b)
          Create a linear interpolator which maps [a,b] to [A,B]
LinearInterpolator(long A, long B, double a, double b)
          Create a linear interpolator which maps [a,b] to [A,B]
LinearInterpolator(long A, long B, long a, long b)
          Create a linear interpolator which maps [a,b] to [A,B]
 
Method Summary
 double geta()
          Return the left endpoint of the domain interval for this interpolator.
 double getA()
          Return the left endpoint of the range interval for this interpolator.
 double getb()
          Return the right endpoint of the domain interval for this interpolator.
 double getB()
          Return the right endpoint of the range interval for this interpolator.
 long iInterp(double x)
          Return an interpolated value rounded off to the nearest integer.
 long iInterp(long x)
          Return an interpolated value rounded off to the nearest integer.
 double interp(double x)
          Return the interpolated value corresponding to x.
 double interp(long x)
          Return the interpolated value corresponding to x.
 LinearInterpolator inverse()
          Return a the inverse linear interpolator.
 long iScale(long x)
          Return the scaling part of this interpolation, rounded off to the nearest integer.
 double scale(double x)
          Perform the scaling part of this interpolation.
 double scale(long x)
          Perform the scaling part of this interpolation.
 java.lang.String toString()
          Return a string representation of this interpolator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LinearInterpolator

public LinearInterpolator(double A,
                          double B,
                          double a,
                          double b)
Create a linear interpolator which maps [a,b] to [A,B]


LinearInterpolator

public LinearInterpolator(long A,
                          long B,
                          double a,
                          double b)
Create a linear interpolator which maps [a,b] to [A,B]


LinearInterpolator

public LinearInterpolator(double A,
                          double B,
                          long a,
                          long b)
Create a linear interpolator which maps [a,b] to [A,B]


LinearInterpolator

public LinearInterpolator(long A,
                          long B,
                          long a,
                          long b)
Create a linear interpolator which maps [a,b] to [A,B]

Method Detail

inverse

public LinearInterpolator inverse()
Return a the inverse linear interpolator. I.e. an interpolator that maps [A,B] to [a,b], where A,B,a,b are the value used to create this interpolator.


interp

public double interp(double x)
Return the interpolated value corresponding to x.


interp

public double interp(long x)
Return the interpolated value corresponding to x.


scale

public double scale(double x)
Perform the scaling part of this interpolation. Omit the offset part.


scale

public double scale(long x)
Perform the scaling part of this interpolation. Omit the offset part.


iInterp

public long iInterp(double x)
Return an interpolated value rounded off to the nearest integer.


iInterp

public long iInterp(long x)
Return an interpolated value rounded off to the nearest integer.


iScale

public long iScale(long x)
Return the scaling part of this interpolation, rounded off to the nearest integer.


geta

public double geta()
Return the left endpoint of the domain interval for this interpolator. This is the value of 'a' that was passed to its constructor.


getb

public double getb()
Return the right endpoint of the domain interval for this interpolator. This is the value of 'b' that was passed to its constructor.


getA

public double getA()
Return the left endpoint of the range interval for this interpolator. This is the value of 'A' that was passed to its constructor.


getB

public double getB()
Return the right endpoint of the range interval for this interpolator. This is the value of 'B' that was passed to its constructor.


toString

public java.lang.String toString()
Return a string representation of this interpolator.