Class MathUtil

java.lang.Object
edu.wpi.first.math.MathUtil

public final class MathUtil
extends Object
  • Method Summary

    Modifier and Type Method Description
    static double angleModulus​(double angleRadians)
    Wraps an angle to the range -pi to pi radians.
    static double applyDeadband​(double value, double deadband)
    Returns 0.0 if the given value is within the specified range around zero.
    static double applyDeadband​(double value, double deadband, double maxMagnitude)
    Returns 0.0 if the given value is within the specified range around zero.
    static double clamp​(double value, double low, double high)
    Returns value clamped between low and high boundaries.
    static int clamp​(int value, int low, int high)
    Returns value clamped between low and high boundaries.
    static double inputModulus​(double input, double minimumInput, double maximumInput)
    Returns modulus of input.
    static double interpolate​(double startValue, double endValue, double t)
    Perform linear interpolation between two values.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • clamp

      public static int clamp​(int value, int low, int high)
      Returns value clamped between low and high boundaries.
      Parameters:
      value - Value to clamp.
      low - The lower boundary to which to clamp value.
      high - The higher boundary to which to clamp value.
      Returns:
      The clamped value.
    • clamp

      public static double clamp​(double value, double low, double high)
      Returns value clamped between low and high boundaries.
      Parameters:
      value - Value to clamp.
      low - The lower boundary to which to clamp value.
      high - The higher boundary to which to clamp value.
      Returns:
      The clamped value.
    • applyDeadband

      public static double applyDeadband​(double value, double deadband, double maxMagnitude)
      Returns 0.0 if the given value is within the specified range around zero. The remaining range between the deadband and the maximum magnitude is scaled from 0.0 to the maximum magnitude.
      Parameters:
      value - Value to clip.
      deadband - Range around zero.
      maxMagnitude - The maximum magnitude of the input. Can be infinite.
      Returns:
      The value after the deadband is applied.
    • applyDeadband

      public static double applyDeadband​(double value, double deadband)
      Returns 0.0 if the given value is within the specified range around zero. The remaining range between the deadband and 1.0 is scaled from 0.0 to 1.0.
      Parameters:
      value - Value to clip.
      deadband - Range around zero.
      Returns:
      The value after the deadband is applied.
    • inputModulus

      public static double inputModulus​(double input, double minimumInput, double maximumInput)
      Returns modulus of input.
      Parameters:
      input - Input value to wrap.
      minimumInput - The minimum value expected from the input.
      maximumInput - The maximum value expected from the input.
      Returns:
      The wrapped value.
    • angleModulus

      public static double angleModulus​(double angleRadians)
      Wraps an angle to the range -pi to pi radians.
      Parameters:
      angleRadians - Angle to wrap in radians.
      Returns:
      The wrapped angle.
    • interpolate

      public static double interpolate​(double startValue, double endValue, double t)
      Perform linear interpolation between two values.
      Parameters:
      startValue - The value to start at.
      endValue - The value to end at.
      t - How far between the two values to interpolate. This is clamped to [0, 1].
      Returns:
      The interpolated value.