Class MultiInterpolator

java.lang.Object
com.softsynth.jmsl.util.MultiInterpolator
All Implemented Interfaces:
Interpolator

public class MultiInterpolator
extends java.lang.Object
implements Interpolator
A sequence of Interpolators each of which is active for a particular range of x. For those ranges of x not covered by interpolators added with addInterpolator() a default LinearInterpolator is used if setInterp() is called, in which case the default's slope is set with setInterp() If the ranges of all interpolators are contiguous (with no "holes"), this linear interpolator will never be used. If a nonlinear default Interpolator is desired, use setDefaultInterpolator() Assumes interpolators added with addInterpolator() are added in increasing sorted x-range order.
Author:
Nick Didkovsky 1/4/02, added to jmsl with MODS 2/14/2003
  • Constructor Summary

    Constructors
    Constructor Description
    MultiInterpolator()  
  • Method Summary

    Modifier and Type Method Description
    void addInterpolator​(Interpolator interp, double startX, double endX)
    Add an interpolator and associate it with specified range of x values [startx, endX)
    Interpolator getDefaultInterpolator()  
    Interpolator getLastUsedInterpolator()  
    double interp​(double x)
    Locates the interpolator associated with range including x, and returns f(x) Values of x that are not in range of any interpolators added with addInterpolator() are passed to the default interpolator's interp() method.
    static void main​(java.lang.String[] args)
    Open a frame with a canvas a draw into it using MultiInterpolator
    void setDefaultInterpolator​(Interpolator interpolator)
    Set the Interpolator to be used if x sent to interp() does not fall in the range of any added Interpolators Only practical reason to use this is if the default interpolator should be something other than a LinearInterpolator (in which case just use setInterp() )
    void setInterp​(double x1, double y1, double x2, double y2)
    Sets slope of a default LinearInterpolator which is used to calculate f(x) where x is not in range of any interpolators added by addInterpolator()

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • MultiInterpolator

      public MultiInterpolator()
  • Method Details

    • addInterpolator

      public void addInterpolator​(Interpolator interp, double startX, double endX)
      Add an interpolator and associate it with specified range of x values [startx, endX)
    • setInterp

      public void setInterp​(double x1, double y1, double x2, double y2)
      Sets slope of a default LinearInterpolator which is used to calculate f(x) where x is not in range of any interpolators added by addInterpolator()
      Specified by:
      setInterp in interface Interpolator
    • getDefaultInterpolator

      public Interpolator getDefaultInterpolator()
      Returns:
      default interpolator, which is used to calculate f(x) where x is not in range of any interpolators added by addInterpolator()
    • setDefaultInterpolator

      public void setDefaultInterpolator​(Interpolator interpolator)
      Set the Interpolator to be used if x sent to interp() does not fall in the range of any added Interpolators Only practical reason to use this is if the default interpolator should be something other than a LinearInterpolator (in which case just use setInterp() )
    • interp

      public double interp​(double x)
      Locates the interpolator associated with range including x, and returns f(x) Values of x that are not in range of any interpolators added with addInterpolator() are passed to the default interpolator's interp() method. This default is a LinearInterpolator if setInterp() was called.
      Specified by:
      interp in interface Interpolator
    • getLastUsedInterpolator

      public Interpolator getLastUsedInterpolator()
      Returns:
      Interpolator most recently used during a call to interp() This interpolator will be the one in whose range x fell
    • main

      public static void main​(java.lang.String[] args)
      Open a frame with a canvas a draw into it using MultiInterpolator
       ...
                  LinearInterpolator interp1 = new LinearInterpolator(0, 0, 100, 100);
                  LinearInterpolator interp2 = new LinearInterpolator(100, 100, 200, 0);
                  ExponentialInterpolator interp3 = new ExponentialInterpolator(200, 0, 300, 400);
                  interp3.setSteepness(9);
                  ExponentialDecayInterpolator interp4 = new ExponentialDecayInterpolator(300, 400, 500, 0);
                  interp4.setSteepness(2);
      
                  MultiInterpolator multi = new MultiInterpolator();
                  multi.setInterp(0, 0, 200, 20);
                  multi.addInterpolator(interp1, 0, 50);
                  multi.addInterpolator(interp2, 100, 200);
                  multi.addInterpolator(interp3, 200, 300);
                  multi.addInterpolator(interp4, 300, 400);