Class SN_Lerp

java.lang.Object
com.frcteam3255.utils.SN_Lerp

public class SN_Lerp extends Object
Linear Interpolation Table for finding the best value based on limited data points. "Borrowed" from 1706's 2022 code.

How to use:

1. Make list of SN_Point2D's that contain gathered information

2. Create new SN_Lerp with this list of points

3. On the created SN_Lerp, call getOutput() with the desired x value and it will return a linearly interpolated y value between the two closest datapoints

  • Field Details

    • size

      public final int size
  • Constructor Details

    • SN_Lerp

      public SN_Lerp(SN_Point2D... points)
      Create new SN_Lerp
      Parameters:
      points - List of SN_Point2D's
  • Method Details

    • getOutput

      public double getOutput(double input)
      Get a linearly interpolated output from the table

      Sequentially searches through all values of table. May not perform well with large datasets

      Parameters:
      input - X input
      Returns:
      Linearly interpolated Y value between the two closest datapoints
    • interpolate

      public static double interpolate(double input, SN_Point2D point1, SN_Point2D point2)
      Interpolate between two SN_Point2Ds
      Parameters:
      input - Desired X value
      point1 - Closest point below desired X value
      point2 - Closest point above desired X value
      Returns:
      interpolated Y value
    • getX

      public double[] getX()
      Get X values
      Returns:
      X values
    • getY

      public double[] getY()
      Get Y Values
      Returns:
      Y Values
    • getTable

      public SN_Point2D[] getTable()
      Get list of points
      Returns:
      list of points