public final class MathUtils
extends java.lang.Object
Thanks to Riven on JavaGaming.org for the basis of sin/cos/floor/ceil.
限定符和类型 | 字段和说明 |
---|---|
static float |
degRad |
static float |
degreesToRadians
multiply by this to convert from degrees to radians
|
static float |
E |
static float |
FLOAT_ROUNDING_ERROR |
static float |
nanoToSec |
static float |
PI |
static float |
PI2 |
static float |
radDeg |
static float |
radiansToDegrees
multiply by this to convert from radians to degrees
|
static java.util.Random |
random |
构造器和说明 |
---|
MathUtils() |
限定符和类型 | 方法和说明 |
---|---|
static float |
atan2(float y,
float x)
Returns atan2 in radians, faster but less accurate than Math.atan2.
|
static int |
ceil(float value)
Returns the smallest integer greater than or equal to the specified float.
|
static int |
ceilPositive(float value)
Returns the smallest integer greater than or equal to the specified float.
|
static double |
clamp(double value,
double min,
double max) |
static float |
clamp(float value,
float min,
float max) |
static int |
clamp(int value,
int min,
int max) |
static long |
clamp(long value,
long min,
long max) |
static short |
clamp(short value,
short min,
short max) |
static float |
cos(float radians)
Returns the cosine in radians from a lookup table.
|
static float |
cosDeg(float degrees)
Returns the cosine in radians from a lookup table.
|
static int |
floor(float value)
Returns the largest integer less than or equal to the specified float.
|
static int |
floorPositive(float value)
Returns the largest integer less than or equal to the specified float.
|
static boolean |
isEqual(float a,
float b)
Returns true if a is nearly equal to b.
|
static boolean |
isEqual(float a,
float b,
float tolerance)
Returns true if a is nearly equal to b.
|
static boolean |
isPowerOfTwo(int value) |
static boolean |
isZero(float value)
Returns true if the value is zero (using the default tolerance as upper bound)
|
static boolean |
isZero(float value,
float tolerance)
Returns true if the value is zero.
|
static float |
lerp(float fromValue,
float toValue,
float progress)
Linearly interpolates between fromValue to toValue on progress position.
|
static float |
lerpAngle(float fromRadians,
float toRadians,
float progress)
Linearly interpolates between two angles in radians.
|
static float |
lerpAngleDeg(float fromDegrees,
float toDegrees,
float progress)
Linearly interpolates between two angles in degrees.
|
static float |
log(float a,
float value) |
static float |
log2(float value) |
static int |
nextPowerOfTwo(int value)
Returns the next power of two.
|
static float |
random()
Returns random number between 0.0 (inclusive) and 1.0 (exclusive).
|
static float |
random(float range)
Returns a random number between 0 (inclusive) and the specified value (exclusive).
|
static float |
random(float start,
float end)
Returns a random number between start (inclusive) and end (exclusive).
|
static int |
random(int range)
Returns a random number between 0 (inclusive) and the specified value (inclusive).
|
static int |
random(int start,
int end)
Returns a random number between start (inclusive) and end (inclusive).
|
static long |
random(long range)
Returns a random number between 0 (inclusive) and the specified value (inclusive).
|
static long |
random(long start,
long end)
Returns a random number between start (inclusive) and end (inclusive).
|
static boolean |
randomBoolean()
Returns a random boolean value.
|
static boolean |
randomBoolean(float chance)
Returns true if a random value between 0 and 1 is less than the specified value.
|
static int |
randomSign()
Returns -1 or 1, randomly.
|
static float |
randomTriangular()
Returns a triangularly distributed random number between -1.0 (exclusive) and 1.0 (exclusive), where values around zero are
more likely.
|
static float |
randomTriangular(float max)
Returns a triangularly distributed random number between
-max (exclusive) and max (exclusive), where values
around zero are more likely. |
static float |
randomTriangular(float min,
float max)
Returns a triangularly distributed random number between
min (inclusive) and max (exclusive), where the
mode argument defaults to the midpoint between the bounds, giving a symmetric distribution. |
static float |
randomTriangular(float min,
float max,
float mode)
Returns a triangularly distributed random number between
min (inclusive) and max (exclusive), where values
around mode are more likely. |
static int |
round(float value)
Returns the closest integer to the specified float.
|
static int |
roundPositive(float value)
Returns the closest integer to the specified float.
|
static float |
sin(float radians)
Returns the sine in radians from a lookup table.
|
static float |
sinDeg(float degrees)
Returns the sine in radians from a lookup table.
|
public static final float nanoToSec
public static final float FLOAT_ROUNDING_ERROR
public static final float PI
public static final float PI2
public static final float E
public static final float radiansToDegrees
public static final float radDeg
public static final float degreesToRadians
public static final float degRad
public static java.util.Random random
public static float sin(float radians)
public static float cos(float radians)
public static float sinDeg(float degrees)
public static float cosDeg(float degrees)
public static float atan2(float y, float x)
public static int random(int range)
public static int random(int start, int end)
public static long random(long range)
public static long random(long start, long end)
public static boolean randomBoolean()
public static boolean randomBoolean(float chance)
public static float random()
public static float random(float range)
public static float random(float start, float end)
public static int randomSign()
public static float randomTriangular()
This is an optimized version of randomTriangular(-1, 1, 0)
public static float randomTriangular(float max)
-max
(exclusive) and max
(exclusive), where values
around zero are more likely.
This is an optimized version of randomTriangular(-max, max, 0)
max
- the upper limitpublic static float randomTriangular(float min, float max)
min
(inclusive) and max
(exclusive), where the
mode
argument defaults to the midpoint between the bounds, giving a symmetric distribution.
This method is equivalent of randomTriangular(min, max, (min + max) * .5f)
min
- the lower limitmax
- the upper limitpublic static float randomTriangular(float min, float max, float mode)
min
(inclusive) and max
(exclusive), where values
around mode
are more likely.min
- the lower limitmax
- the upper limitmode
- the point around which the values are more likelypublic static int nextPowerOfTwo(int value)
public static boolean isPowerOfTwo(int value)
public static short clamp(short value, short min, short max)
public static int clamp(int value, int min, int max)
public static long clamp(long value, long min, long max)
public static float clamp(float value, float min, float max)
public static double clamp(double value, double min, double max)
public static float lerp(float fromValue, float toValue, float progress)
public static float lerpAngle(float fromRadians, float toRadians, float progress)
fromRadians
- start angle in radianstoRadians
- target angle in radiansprogress
- interpolation value in the range [0, 1]public static float lerpAngleDeg(float fromDegrees, float toDegrees, float progress)
fromDegrees
- start angle in degreestoDegrees
- target angle in degreesprogress
- interpolation value in the range [0, 1]public static int floor(float value)
public static int floorPositive(float value)
public static int ceil(float value)
public static int ceilPositive(float value)
public static int round(float value)
public static int roundPositive(float value)
public static boolean isZero(float value)
public static boolean isZero(float value, float tolerance)
tolerance
- represent an upper bound below which the value is considered zero.public static boolean isEqual(float a, float b)
a
- the first value.b
- the second value.public static boolean isEqual(float a, float b, float tolerance)
a
- the first value.b
- the second value.tolerance
- represent an upper bound below which the two values are considered equal.public static float log(float a, float value)
public static float log2(float value)