Package com.jme3.math

Class FastMath

java.lang.Object
com.jme3.math.FastMath

public final class FastMath extends Object
FastMath provides 'fast' math approximations and float equivalents of Math functions. These are all used as static values and functions.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final float
    A value to multiply a degree value by, to convert it to radians.
    static final float
    A "close to zero" double epsilon value for use
    static final float
    The value PI/2 as a float.
    static final float
    The value PI as a float.
    static final float
    The value PI/4 as a float.
    static final float
    A value to multiply a radian value by, to convert it to degrees.
    static final float
    The value 2PI as a float.
  • Method Summary

    Modifier and Type
    Method
    Description
    static float
    abs(float fValue)
    Returns Absolute value of a float.
    static boolean
    approximateEquals(float a, float b)
    Determine if two floats are approximately equal.
    static float
    atan(float fValue)
    Returns the arc tangent of an angle given in radians.
    static float
    atan2(float fY, float fX)
    A direct call to Math.atan2.
    static float
    clamp(float input, float min, float max)
    Take a float input and clamp it between min and max.
    static float
    cos(float v)
    Returns cosine of an angle.
    static float
    pow(float fBase, float fExponent)
    Returns a number raised to an exponent power.
    static float
    sin(float v)
    Returns the sine of an angle.
    static float
    sqrt(float fValue)
    Returns the square root of a given value.
    static float
    tan(float fValue)
    Returns the tangent of the specified angle.

    Methods inherited from class java.lang.Object

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

    • FLT_EPSILON

      public static final float FLT_EPSILON
      A "close to zero" double epsilon value for use
      See Also:
    • PI

      public static final float PI
      The value PI as a float. (180 degrees)
      See Also:
    • TWO_PI

      public static final float TWO_PI
      The value 2PI as a float. (360 degrees)
      See Also:
    • HALF_PI

      public static final float HALF_PI
      The value PI/2 as a float. (90 degrees)
      See Also:
    • QUARTER_PI

      public static final float QUARTER_PI
      The value PI/4 as a float. (45 degrees)
      See Also:
    • DEG_TO_RAD

      public static final float DEG_TO_RAD
      A value to multiply a degree value by, to convert it to radians.
      See Also:
    • RAD_TO_DEG

      public static final float RAD_TO_DEG
      A value to multiply a radian value by, to convert it to degrees.
      See Also:
  • Method Details

    • atan

      public static float atan(float fValue)
      Returns the arc tangent of an angle given in radians.
      Parameters:
      fValue - The angle, in radians.
      Returns:
      fValue's atan
      See Also:
    • atan2

      public static float atan2(float fY, float fX)
      A direct call to Math.atan2.
      Parameters:
      fY - ordinate
      fX - abscissa
      Returns:
      Math.atan2(fY,fX)
      See Also:
    • cos

      public static float cos(float v)
      Returns cosine of an angle. Direct call to java.lang.Math
      Parameters:
      v - The angle to cosine.
      Returns:
      the cosine of the angle.
      See Also:
    • sin

      public static float sin(float v)
      Returns the sine of an angle. Direct call to java.lang.Math
      Parameters:
      v - The angle to sine.
      Returns:
      the sine of the angle.
      See Also:
    • abs

      public static float abs(float fValue)
      Returns Absolute value of a float.
      Parameters:
      fValue - The value to abs.
      Returns:
      The abs of the value.
      See Also:
    • pow

      public static float pow(float fBase, float fExponent)
      Returns a number raised to an exponent power. fBase^fExponent
      Parameters:
      fBase - The base value (IE 2)
      fExponent - The exponent value (IE 3)
      Returns:
      base raised to exponent (IE 8)
      See Also:
    • sqrt

      public static float sqrt(float fValue)
      Returns the square root of a given value.
      Parameters:
      fValue - The value to sqrt.
      Returns:
      The square root of the given value.
      See Also:
    • tan

      public static float tan(float fValue)
      Returns the tangent of the specified angle.
      Parameters:
      fValue - The value to tangent, in radians.
      Returns:
      The tangent of fValue.
      See Also:
    • clamp

      public static float clamp(float input, float min, float max)
      Take a float input and clamp it between min and max.
      Parameters:
      input - the value to be clamped
      min - the minimum output value
      max - the maximum output value
      Returns:
      clamped input
    • approximateEquals

      public static boolean approximateEquals(float a, float b)
      Determine if two floats are approximately equal. This takes into account the magnitude of the floats, since large numbers will have larger differences be close to each other. Should return true for a=100000, b=100001, but false for a=10000, b=10001.
      Parameters:
      a - The first float to compare
      b - The second float to compare
      Returns:
      True if a and b are approximately equal, false otherwise.