|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objecttoxi.math.MathUtils
public final class MathUtils
Miscellaneous math utilities.
Field Summary | |
---|---|
static float |
DEG2RAD
Degrees to radians conversion factor |
static float |
EPS
Epsilon value |
static float |
HALF_PI
PI/2 |
static float |
INV_PI
The reciprocal of PI: (1/PI) |
static float |
LOG2
Log(2) |
static float |
PI
PI |
static float |
PI_SQUARED
PI*PI |
static float |
QUARTER_PI
PI/4 |
static float |
RAD2DEG
Radians to degrees conversion factor |
static java.util.Random |
RND
Default random number generator used by random methods of this class which don't use a passed in Random instance. |
static float |
SQRT2
Square root of 2 |
static float |
SQRT3
Square root of 3 |
static float |
THIRD_PI
PI/3 |
static float |
THREE_HALVES_PI
PI*1.5 |
static float |
TWO_PI
PI*2 |
Constructor Summary | |
---|---|
MathUtils()
|
Method Summary | |
---|---|
static double |
abs(double x)
|
static float |
abs(float x)
|
static int |
abs(int x)
|
static int |
ceilPowerOf2(int x)
Rounds up the value to the nearest higher power^2 value. |
static double |
clip(double a,
double min,
double max)
|
static float |
clip(float a,
float min,
float max)
|
static int |
clip(int a,
int min,
int max)
|
static float |
clipNormalized(float a)
Clips the value to the 0.0 .. |
static double |
cos(double theta)
|
static float |
cos(float theta)
Returns fast cosine approximation of a value. |
static float |
degrees(float radians)
|
static double |
fastCos(double x)
Fast cosine approximation. |
static int |
fastFloor(float x)
Deprecated. renamed into floor(float) |
static float |
fastInverseSqrt(float x)
Deprecated. |
static float |
fastPow(float a,
float b)
Computes a fast approximation to Math.pow(a, b) . |
static double |
fastSin(double x)
Fast sine approximation. |
static boolean |
flipCoin()
|
static boolean |
flipCoin(java.util.Random rnd)
|
static int |
floor(double x)
|
static int |
floor(float x)
This method is a *lot* faster than using (int)Math.floor(x). |
static int |
floorPowerOf2(int x)
Rounds down the value to the nearest lower power^2 value. |
static double |
max(double a,
double b)
|
static double |
max(double a,
double b,
double c)
|
static float |
max(float a,
float b)
|
static float |
max(float a,
float b,
float c)
Returns the maximum value of three floats. |
static int |
max(int a,
int b)
|
static int |
max(int a,
int b,
int c)
Returns the maximum value of three ints. |
static double |
min(double a,
double b)
|
static double |
min(double a,
double b,
double c)
|
static float |
min(float a,
float b)
|
static float |
min(float a,
float b,
float c)
Returns the minimum value of three floats. |
static int |
min(int a,
int b)
|
static int |
min(int a,
int b,
int c)
Returns the minimum value of three ints. |
static float |
normalizedRandom()
Returns a random number in the interval -1 .. |
static float |
normalizedRandom(java.util.Random rnd)
Returns a random number in the interval -1 .. |
static float |
radians(float degrees)
|
static float |
random(float max)
|
static float |
random(float min,
float max)
|
static int |
random(int max)
|
static int |
random(int min,
int max)
|
static double |
random(java.util.Random rnd,
double max)
|
static double |
random(java.util.Random rnd,
double min,
double max)
|
static float |
random(java.util.Random rnd,
float max)
|
static float |
random(java.util.Random rnd,
float min,
float max)
|
static int |
random(java.util.Random rnd,
int max)
|
static int |
random(java.util.Random rnd,
int min,
int max)
|
static double |
reduceAngle(double theta)
|
static float |
reduceAngle(float theta)
Reduces the given angle into the -PI/4 ... |
static void |
setDefaultRandomGenerator(java.util.Random rnd)
Sets the default Random number generator for this class. |
static int |
sign(double x)
|
static int |
sign(float x)
|
static int |
sign(int x)
|
static double |
sin(double theta)
|
static float |
sin(float theta)
Returns a fast sine approximation of a value. |
static float |
sqrt(float x)
Deprecated. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final float SQRT2
public static final float SQRT3
public static final float LOG2
public static final float PI
public static final float INV_PI
public static final float HALF_PI
public static final float THIRD_PI
public static final float QUARTER_PI
public static final float TWO_PI
public static final float THREE_HALVES_PI
public static final float PI_SQUARED
public static final float EPS
public static final float DEG2RAD
public static final float RAD2DEG
public static java.util.Random RND
Random
instance.
Constructor Detail |
---|
public MathUtils()
Method Detail |
---|
public static final double abs(double x)
x
-
public static final float abs(float x)
x
-
public static final int abs(int x)
x
-
public static final int ceilPowerOf2(int x)
x
-
public static final double clip(double a, double min, double max)
public static final float clip(float a, float min, float max)
public static final int clip(int a, int min, int max)
public static final float clipNormalized(float a)
a
-
public static final double cos(double theta)
public static final float cos(float theta)
theta
- angle in radians.
public static final float degrees(float radians)
public static final double fastCos(double x)
x
- angle in -PI/2 .. +PI/2 interval
@Deprecated public static final int fastFloor(float x)
floor(float)
@Deprecated public static final float fastInverseSqrt(float x)
public static final float fastPow(float a, float b)
Math.pow(a, b)
. Adapted
from http://www.dctsystems.co.uk/Software/power.html.
a
- a positive numberb
- a number
public static final double fastSin(double x)
x
- angle in -PI/2 .. +PI/2 interval
public static final boolean flipCoin()
public static final boolean flipCoin(java.util.Random rnd)
public static final int floor(double x)
public static final int floor(float x)
x
- value to be floored
public static final int floorPowerOf2(int x)
x
-
public static final double max(double a, double b)
public static final double max(double a, double b, double c)
public static final float max(float a, float b)
public static final float max(float a, float b, float c)
a
- b
- c
-
public static final int max(int a, int b)
public static final int max(int a, int b, int c)
a
- b
- c
-
public static final double min(double a, double b)
public static final double min(double a, double b, double c)
public static final float min(float a, float b)
public static final float min(float a, float b, float c)
a
- b
- c
-
public static final int min(int a, int b)
public static final int min(int a, int b, int c)
a
- b
- c
-
public static final float normalizedRandom()
public static final float normalizedRandom(java.util.Random rnd)
Random
instance provided.
public static final float radians(float degrees)
public static final float random(float max)
public static final float random(float min, float max)
public static final int random(int max)
public static final int random(int min, int max)
public static final double random(java.util.Random rnd, double max)
public static final double random(java.util.Random rnd, double min, double max)
public static final float random(java.util.Random rnd, float max)
public static final float random(java.util.Random rnd, float min, float max)
public static final int random(java.util.Random rnd, int max)
public static final int random(java.util.Random rnd, int min, int max)
public static final double reduceAngle(double theta)
public static final float reduceAngle(float theta)
sin(float)
&
cos(float)
.
theta
- angle in radians
sin(float)
,
cos(float)
public static void setDefaultRandomGenerator(java.util.Random rnd)
Random
instance to be used.
rnd
- public static int sign(double x)
public static int sign(float x)
public static int sign(int x)
public static final double sin(double theta)
public static final float sin(float theta)
theta
- angle in radians.
@Deprecated public static final float sqrt(float x)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |