com.jme.math
Class FastMath

java.lang.Object
  extended bycom.jme.math.FastMath

public final class FastMath
extends java.lang.Object

FastMath provides 'fast' math approximations and float equivalents of Math functions. These are all used as static values and functions.

Version:
$Id: FastMath.java,v 1.16 2005/02/25 03:09:44 renanse Exp $
Author:
Various

Nested Class Summary
static class FastMath.FastTrig
          FastTrig is used to calculate quick trig functions using a lookup table.
 
Field Summary
static double DBL_EPSILON
          A "close to zero" double epsilon value for use
static float DEG_TO_RAD
          A value to multiply a degree value by, to convert it to radians.
static float FLT_EPSILON
          A "close to zero" float epsilon value for use
static float HALF_PI
          The value PI/2 as a float.
static float INV_PI
          The value 1/PI as a float.
static float INV_TWO_PI
          The value 1/(2PI) as a float.
static float PI
          The value PI as a float.
static float RAD_TO_DEG
          A value to multiply a radian value by, to convert it to degrees.
static java.util.Random rand
          A precreated random object for random numbers.
static float TWO_PI
          The value 2PI as a float.
static boolean USE_FAST_TRIG
          If true, fast trig approximations are used for values such as sin/cos/tan.
 
Method Summary
static float abs(float fValue)
          Returns Absolute value of a float.
static float acos(float fValue)
          Returns the arc cosine of an angle given in radians.
Special cases: If fValue is smaller than -1, then the result is PI.
static float asin(float fValue)
          Returns the arc sine of an angle given in radians.
Special cases: If fValue is smaller than -1, then the result is -HALF_PI.
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 int ccw(Vector2f p0, Vector2f p1, Vector2f p2)
          Given 3 points in a 2d plane, this function computes if the points going from A-B-C are moving counter clock wise.
static float ceil(float fValue)
          Rounds a fValue up.
static float cos(float fValue)
          Returns cos of a value.
static float determinant(double m00, double m01, double m02, double m03, double m10, double m11, double m12, double m13, double m20, double m21, double m22, double m23, double m30, double m31, double m32, double m33)
          Returns the determinant of a 4x4 matrix.
static float erf(float fX)
           
static float erfc(float fX)
           
static float exp(float fValue)
          Returns E^fValue
static float floor(float fValue)
          Returns a number rounded down.
static float gamma(float fX)
           
static float incompleteGamma(float fA, float fX)
           
static float incompleteGammaCF(float fA, float fX)
           
static float incompleteGammaS(float fA, float fX)
           
static float invSqrt(float fValue)
          Returns 1/sqrt(fValue)
static boolean isPowerOfTwo(int number)
          Returns true if the number is a power of 2 (2,4,8,16...)
static float LERP(float f, float v0, float v1)
          Linear interpolation from v0 to v1 by f percent.
static float log(float fValue)
          Returns the log base E of a value.
static float logGamma(float fX)
           
static float modBessel0(float fX)
           
static float modBessel1(float fX)
           
static float nextRandomFloat()
          Returns a random float between 0 and 1.
static int pointInsideTriangle(Vector2f t0, Vector2f t1, Vector2f t2, Vector2f p)
          Test if a point is inside a triangle.
static float pow(float fBase, float fExponent)
          Returns a number raised to an exponent power.
static float sign(float fValue)
          Returns 1 if the number is positive, -1 if the number is negative, and 0 otherwise
static int sign(int iValue)
          Returns 1 if the number is positive, -1 if the number is negative, and 0 otherwise
static float sin(float fValue)
          Returns sine of a value.
static float sqr(float fValue)
          Returns the value squared.
static float sqrt(float fValue)
          Returns the square root of a given value.
static float tan(float fValue)
          Returns the tangent of a value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DBL_EPSILON

public static final double DBL_EPSILON
A "close to zero" double epsilon value for use

See Also:
Constant Field Values

FLT_EPSILON

public static final float FLT_EPSILON
A "close to zero" float epsilon value for use

See Also:
Constant Field Values

PI

public static final float PI
The value PI as a float.


TWO_PI

public static final float TWO_PI
The value 2PI as a float.


HALF_PI

public static final float HALF_PI
The value PI/2 as a float.


INV_PI

public static final float INV_PI
The value 1/PI as a float.


INV_TWO_PI

public static final float INV_TWO_PI
The value 1/(2PI) as a float.


DEG_TO_RAD

public static final float DEG_TO_RAD
A value to multiply a degree value by, to convert it to radians.


RAD_TO_DEG

public static final float RAD_TO_DEG
A value to multiply a radian value by, to convert it to degrees.


rand

public static final java.util.Random rand
A precreated random object for random numbers.


USE_FAST_TRIG

public static boolean USE_FAST_TRIG
If true, fast trig approximations are used for values such as sin/cos/tan.

Method Detail

isPowerOfTwo

public static boolean isPowerOfTwo(int number)
Returns true if the number is a power of 2 (2,4,8,16...)

Parameters:
number - The number to test.
Returns:
True if it is a power of two.

LERP

public static float LERP(float f,
                         float v0,
                         float v1)
Linear interpolation from v0 to v1 by f percent. IE (1-f) * V0 + f * V1

Parameters:
f - Percent value to use.
v0 - Begining value. 0% of f
v1 - ending value. 100% of f
Returns:
An interpolation between v0 and v1.

acos

public static float acos(float fValue)
Returns the arc cosine of an angle given in radians.
Special cases:

Parameters:
fValue - The angle, in radians.
Returns:
fValue's acos
See Also:
Math.acos(double)

asin

public static float asin(float fValue)
Returns the arc sine of an angle given in radians.
Special cases:

Parameters:
fValue - The angle, in radians.
Returns:
fValue's asin
See Also:
Math.asin(double)

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 asin
See Also:
Math.atan(double)

atan2

public static float atan2(float fY,
                          float fX)
A direct call to Math.atan2.

Parameters:
fY -
fX -
Returns:
Math.atan2(fY,fX)
See Also:
Math.atan2(double, double)

ceil

public static float ceil(float fValue)
Rounds a fValue up. A call to Math.ceil

Parameters:
fValue - The value.
Returns:
The fValue rounded up
See Also:
Math.ceil(double)

cos

public static float cos(float fValue)
Returns cos of a value. If USE_FAST_TRIG is enabled, an approximate value is returned. Otherwise, a direct value is used.

Parameters:
fValue - The value to cosine, in raidans.
Returns:
The cosine of fValue.
See Also:
Math.cos(double)

exp

public static float exp(float fValue)
Returns E^fValue

Parameters:
fValue - Value to raise to a power.
Returns:
The value E^fValue
See Also:
Math.exp(double)

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:
Math.abs(float)

floor

public static float floor(float fValue)
Returns a number rounded down.

Parameters:
fValue - The value to round
Returns:
The given number rounded down
See Also:
Math.floor(double)

invSqrt

public static float invSqrt(float fValue)
Returns 1/sqrt(fValue)

Parameters:
fValue - The value to process.
Returns:
1/sqrt(fValue)
See Also:
Math.sqrt(double)

log

public static float log(float fValue)
Returns the log base E of a value.

Parameters:
fValue - The value to log.
Returns:
The log of fValue base E
See Also:
Math.log(double)

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:
Math.pow(double, double)

sin

public static float sin(float fValue)
Returns sine of a value. If USE_FAST_TRIG is enabled, an approximate value is returned. Otherwise, a direct value is used.

Parameters:
fValue - The value to sine, in raidans.
Returns:
The sine of fValue.
See Also:
Math.sin(double)

sqr

public static float sqr(float fValue)
Returns the value squared. fValue ^ 2

Parameters:
fValue - The vaule to square.
Returns:
The square of the given value.

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:
Math.sqrt(double)

tan

public static float tan(float fValue)
Returns the tangent of a value. If USE_FAST_TRIG is enabled, an approximate value is returned. Otherwise, a direct value is used.

Parameters:
fValue - The value to tangent, in raidans.
Returns:
The tangent of fValue.
See Also:
Math.tan(double)

sign

public static int sign(int iValue)
Returns 1 if the number is positive, -1 if the number is negative, and 0 otherwise

Parameters:
iValue - The integer to examine.
Returns:
The integer's sign.

sign

public static float sign(float fValue)
Returns 1 if the number is positive, -1 if the number is negative, and 0 otherwise

Parameters:
fValue - The float to examine.
Returns:
The float's sign.

logGamma

public static float logGamma(float fX)

gamma

public static float gamma(float fX)

incompleteGammaS

public static float incompleteGammaS(float fA,
                                     float fX)

incompleteGammaCF

public static float incompleteGammaCF(float fA,
                                      float fX)

incompleteGamma

public static float incompleteGamma(float fA,
                                    float fX)

erf

public static float erf(float fX)

erfc

public static float erfc(float fX)

modBessel0

public static float modBessel0(float fX)

modBessel1

public static float modBessel1(float fX)

ccw

public static int ccw(Vector2f p0,
                      Vector2f p1,
                      Vector2f p2)
Given 3 points in a 2d plane, this function computes if the points going from A-B-C are moving counter clock wise.

Parameters:
p0 - Point 0.
p1 - Point 1.
p2 - Point 2.
Returns:
1 If they are CCW, -1 if they are not CCW, 0 if p2 is between p0 and p1.

pointInsideTriangle

public static int pointInsideTriangle(Vector2f t0,
                                      Vector2f t1,
                                      Vector2f t2,
                                      Vector2f p)
Test if a point is inside a triangle. 1 if the point is on the ccw side, -1 if the point is on the cw side, and 0 if it is on neither.

Parameters:
t0 - First point of the triangle.
t1 - Second point of the triangle.
t2 - Third point of the triangle.
p - The point to test.
Returns:
Value 1 or -1 if inside triangle, 0 otherwise.

determinant

public static float determinant(double m00,
                                double m01,
                                double m02,
                                double m03,
                                double m10,
                                double m11,
                                double m12,
                                double m13,
                                double m20,
                                double m21,
                                double m22,
                                double m23,
                                double m30,
                                double m31,
                                double m32,
                                double m33)
Returns the determinant of a 4x4 matrix.


nextRandomFloat

public static float nextRandomFloat()
Returns a random float between 0 and 1.

Returns:
A random float between 0 and 1.