java.lang.Object
com.github.stephengold.joltjni.JoltPhysicsObject
com.github.stephengold.joltjni.LinearCurve
All Implemented Interfaces:
ConstJoltPhysicsObject, ConstLinearCurve, AutoCloseable, Comparable<JoltPhysicsObject>

public class LinearCurve extends JoltPhysicsObject implements ConstLinearCurve
Linearly interpolate some value Y versus another value X, such as torque versus RPMs or wheel friction versus slip ratio.
  • Constructor Details

    • LinearCurve

      public LinearCurve()
      Instantiate a default curve.
    • LinearCurve

      public LinearCurve(ConstLinearCurve original)
      Instantiate a copy of the specified curve.
      Parameters:
      original - the curve to copy (not null, unaffected)
  • Method Details

    • addPoint

      public void addPoint(float x, float y)
      Add the specified point to the curve.
      Parameters:
      x - the input (X) coordinate
      y - the output (Y) coordinate
    • clear

      public void clear()
      Remove all points from the curve.
    • restoreBinaryState

      public void restoreBinaryState(StreamIn stream)
      Read the state of this curve from the specified stream.
      Parameters:
      stream - where to read from (not null)
    • sort

      public void sort()
      Sort the points by their X values, in ascending order.
    • countPoints

      public int countPoints()
      Count the points in the curve. The curve is unaffected.
      Specified by:
      countPoints in interface ConstLinearCurve
      Returns:
      the count (≥0)
    • getMaxX

      public float getMaxX()
      Return the highest X value. The curve is unaffected.
      Specified by:
      getMaxX in interface ConstLinearCurve
      Returns:
      the highest X value
    • getMinX

      public float getMinX()
      Return the lowest X value. The curve is unaffected.
      Specified by:
      getMinX in interface ConstLinearCurve
      Returns:
      the lowest X value
    • getPointX

      public float getPointX(int pointIndex)
      Return the X value of the specified point. The curve is unaffected.
      Specified by:
      getPointX in interface ConstLinearCurve
      Parameters:
      pointIndex - the index of the point (≥0)
      Returns:
      the point's X value
    • getPointY

      public float getPointY(int pointIndex)
      Return the Y value of the specified point. The curve is unaffected.
      Specified by:
      getPointY in interface ConstLinearCurve
      Parameters:
      pointIndex - the index of the point (≥0)
      Returns:
      the point's Y value
    • getValue

      public float getValue(float x)
      Return the Y value for the specified X. The curve is unaffected.
      Specified by:
      getValue in interface ConstLinearCurve
      Parameters:
      x - the input X value
      Returns:
      the interpolated Y value
    • saveBinaryState

      public void saveBinaryState(StreamOut stream)
      Write the curve to the specified stream. The curve is unaffected.
      Specified by:
      saveBinaryState in interface ConstLinearCurve
      Parameters:
      stream - where to write objects (not null)