Class Curve

java.lang.Object
ca.spatial.patchworks.Curve

public class Curve extends Object
This class implements linear interpolated curves that are represented by a series of points. The class is instantiated with arrays of x and y floating point values. The getY(float) method will retrieve an estimate of the Y value for any given X value.

Linear interpolation is used for calculating values of Y where the X value lies between two points. When the X value is lower than the lowest X value in the curve, then the lowest Y value is returned. When the X value is higher than the highest X value in the curve, then the highest Y value is returned.

A curve containing a single point will return a constant value for any value of X.

  • Constructor Summary

    Constructors
    Constructor
    Description
    Curve​(float[] xp, float[] yp)
    Construct a curve from a series of points.
    Curve​(float[] xp, float[] yp, int n)
    Construct a curve from a series of points.
  • Method Summary

    Modifier and Type
    Method
    Description
    float
    getY​(float xn)
    Estimate the Y value in a curve for any given X value.
     

    Methods inherited from class java.lang.Object

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

    • Curve

      public Curve(float[] xp, float[] yp)
      Construct a curve from a series of points. All points in the input arrays will be used. This constructor is equivalent to
       
         new Curve(xp, yp, xp.length);
       
      Parameters:
      xp - An array of x-values that represent the series of points in the curve
      yp - An array of y-values that represent the series of points in the curve
    • Curve

      public Curve(float[] xp, float[] yp, int n)
      Construct a curve from a series of points. The constructor will automatically discard unnecessary points.

      The X values must be in monotonically increasing order.

      Parameters:
      xp - An array of x-values that represent the series of points in the curve
      yp - An array of y-values that represent the series of points in the curve
      n - The number of points that are in the arrays. Points in the array beyond 'n' will be ignored.
  • Method Details

    • getY

      public final float getY(float xn)
      Estimate the Y value in a curve for any given X value. Read the class description for the interpolation method that is used.
    • toString

      public String toString()
      Overrides:
      toString in class Object