Thanks to Riven on JavaGaming.org for the basis of sin/cos/floor/ceil.
| Modifier and Type | Class and Description |
|---|---|
| private static class |
| Modifier and Type | Field and Description |
|---|---|
| private static final double | |
| private static final double | |
| private static final int | |
| private static final double | |
| private static final double | |
| private static final float | |
| public static final float | |
| public static final float | degreesToRadians
multiply by this to convert from degrees to radians |
| private static final float | |
| public static final float | |
| public static final float | |
| public static final float | |
| public static final float | |
| public static final float | |
| public static final float | |
| public static final float | |
| private static final float | |
| public static final float | radiansToDegrees
multiply by this to convert from radians to degrees |
| private static final float | |
| public static Random | |
| private static final int | |
| private static final int | |
| private static final int |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static float | Returns: between0 and PI when a is in the defined rangeacos is defined only when a is between -1f and 1f, inclusive a)Returns acos in radians; less accurate than Math.acos but may be faster. |
| public static float | Returns: between0 and 180 when a is in the defined rangeacos is defined only when a is between -1f and 1f, inclusive a)Returns arccosine in degrees. |
| public static float | Returns: between-HALF_PI and HALF_PI when a is in the defined rangeasin is defined only when a is between -1f and 1f, inclusive a)Returns asin in radians; less accurate than Math.asin but may be faster. |
| public static float | Returns: between-90 and 90 when a is in the defined rangeasin is defined only when a is between -1f and 1f, inclusive a)Returns arcsine in degrees. |
| public static float | Returns: an output from the inverse tangent function, from-HALF_PI to HALF_PI inclusivean input to the inverse tangent function; any float is accepted i)Arc tangent approximation with very low error, using an algorithm from the 1955 research study "Approximations for Digital Computers," by RAND Corporation (this is sheet 11's algorithm, which is the fourth-fastest and fourth-least precise). |
| public static float | Returns: the angle to the given point, in radians as a float; ranges from-PI to PIy-component of the point to find the angle towards; note the parameter order is unusual by convention y, float x-component of the point to find the angle towards; note the parameter order is unusual by convention x)Close approximation of the frequently-used trigonometric method atan2. |
| public static float | Returns: the angle to the given point, in degrees as a float; ranges from-180 to 180y-component of the point to find the angle towards; note the parameter order is unusual by convention y, float x-component of the point to find the angle towards; note the parameter order is unusual by convention x)Close approximation of the frequently-used trigonometric method atan2, using positive or negative degrees. |
| public static float | Returns: the angle to the given point, in degrees as a float; ranges from0 to 360y-component of the point to find the angle towards; note the parameter order is unusual by convention y, float x-component of the point to find the angle towards; note the parameter order is unusual by convention x)Close approximation of the frequently-used trigonometric method atan2, using non-negative degrees only. |
| public static float | Returns: an output from the inverse tangent function in degrees, from-90 to 90 inclusivean input to the inverse tangent function; any float is accepted i)Arc tangent approximation returning a value measured in positive or negative degrees, using an algorithm from the 1955 research study "Approximations for Digital Computers," by RAND Corporation (this is sheet 11's algorithm, which is the fourth-fastest and fourth-least precise). |
| public static float | Returns: an output from the inverse tangent function, from-HALF_PI to HALF_PI inclusiveany finite double or float, but more commonly a float i)A variant on |
| public static double | Returns: an output from the inverse tangent function in degrees, from-90 to 90 inclusiveany finite double or float, but more commonly a float i)A variant on |
| public static int | |
| public static int | |
| public static short | |
| public static int | |
| public static long | |
| public static float | |
| public static double | |
| public static float | |
| public static float | |
| public static int | |
| public static int | |
| public static boolean | |
| public static boolean | isEqual(float
the first value. a, float the second value. b, float represent an upper bound below which the two values are considered equal. tolerance)Returns true if a is nearly equal to b. |
| public static boolean | |
| public static boolean | |
| public static boolean | isZero(float value, float
represent an upper bound below which the value is considered zero. tolerance)Returns true if the value is zero. |
| public static float | lerp(float fromValue, float toValue, float progress)
Linearly interpolates between fromValue to toValue on progress position. |
| public static float | Returns: the interpolated angle in the range [0, PI2[start angle in radians fromRadians, float target angle in radians toRadians, float interpolation value in the range [0, 1] progress)Linearly interpolates between two angles in radians. |
| public static float | Returns: the interpolated angle in the range [0, 360[start angle in degrees fromDegrees, float target angle in degrees toDegrees, float interpolation value in the range [0, 1] progress)Linearly interpolates between two angles in degrees. |
| public static float | |
| public static float | |
| public static float | Returns: Mapped value. Values outside of the input range are not clamped to output rangeInput range start inRangeStart, float Input range end inRangeEnd, float Output range start outRangeStart, float Output range end outRangeEnd, float Value to map value)Linearly map a value from one range to another. |
| public static int | |
| public static float | Returns: Normalized value. Values outside of the range are not clamped to 0 and 1Range start normalized to 0 rangeStart, float Range end normalized to 1 rangeEnd, float Value to normalize value)Linearly normalizes value from a range. |
| public static int | |
| public static int | |
| public static long | random(long range)
Returns a random number between 0 (inclusive) and the specified value (inclusive). |
| public static long | |
| public static float | |
| public static float | random(float range)
Returns a random number between 0 (inclusive) and the specified value (exclusive). |
| public static float | random(float start, float end)
Returns a random number between start (inclusive) and end (exclusive). |
| public static boolean | |
| public static boolean | randomBoolean(float chance)
Returns true if a random value between 0 and 1 is less than the specified value. |
| public static int | |
| public static float | randomTriangular()
Returns a triangularly distributed random number between -1.0 (exclusive) and 1.0 (exclusive), where values around zero are more likely. |
| public static float | randomTriangular(float
the upper limit max)Returns a triangularly distributed random number between |
| public static float | randomTriangular(float
the lower limit min, float the upper limit max)Returns a triangularly distributed random number between |
| public static float | randomTriangular(float
the lower limit min, float the upper limit max, float the point around which the values are more likely mode)Returns a triangularly distributed random number between |
| public static int | |
| public static int | |
| public static float | |
| public static float | |
| public static float | |
| public static float | Returns: a float approximation of tan()an angle in degrees, where 0 to 360 is one rotation degrees)Returns the tangent given an input in degrees, using a Padé approximant. |
| BIG_ENOUGH_CEIL | back to summary |
|---|---|
| private static final double BIG_ENOUGH_CEIL | |
| BIG_ENOUGH_FLOOR | back to summary |
|---|---|
| private static final double BIG_ENOUGH_FLOOR | |
| BIG_ENOUGH_INT | back to summary |
|---|---|
| private static final int BIG_ENOUGH_INT | |
| BIG_ENOUGH_ROUND | back to summary |
|---|---|
| private static final double BIG_ENOUGH_ROUND | |
| CEIL | back to summary |
|---|---|
| private static final double CEIL | |
| degFull | back to summary |
|---|---|
| private static final float degFull | |
| degRad | back to summary |
|---|---|
| public static final float degRad | |
| degreesToRadians | back to summary |
|---|---|
| public static final float degreesToRadians multiply by this to convert from degrees to radians | |
| degToIndex | back to summary |
|---|---|
| private static final float degToIndex | |
| E | back to summary |
|---|---|
| public static final float E | |
| FLOAT_ROUNDING_ERROR | back to summary |
|---|---|
| public static final float FLOAT_ROUNDING_ERROR | |
| HALF_PI | back to summary |
|---|---|
| public static final float HALF_PI | |
| nanoToSec | back to summary |
|---|---|
| public static final float nanoToSec | |
| PI | back to summary |
|---|---|
| public static final float PI | |
| PI2 | back to summary |
|---|---|
| public static final float PI2 | |
| radDeg | back to summary |
|---|---|
| public static final float radDeg | |
| radFull | back to summary |
|---|---|
| private static final float radFull | |
| radiansToDegrees | back to summary |
|---|---|
| public static final float radiansToDegrees multiply by this to convert from radians to degrees | |
| radToIndex | back to summary |
|---|---|
| private static final float radToIndex | |
| random | back to summary |
|---|---|
| public static Random random | |
| SIN_BITS | back to summary |
|---|---|
| private static final int SIN_BITS | |
| SIN_COUNT | back to summary |
|---|---|
| private static final int SIN_COUNT | |
| SIN_MASK | back to summary |
|---|---|
| private static final int SIN_MASK | |
| MathUtils | back to summary |
|---|---|
| private MathUtils() | |
| acos | back to summary |
|---|---|
| public static float acos(float a) Returns acos in radians; less accurate than Math.acos but may be faster. Average error of 0.00002845 radians (0.0016300649 degrees), largest error of 0.000067548 radians (0.0038702153 degrees). This implementation does not return NaN if given an out-of-range input (Math.acos does return NaN), unless the input is NaN.
| |
| acosDeg | back to summary |
|---|---|
| public static float acosDeg(float a) Returns arccosine in degrees. This implementation does not return NaN if given an out-of-range input (Math.acos does return NaN), unless the input is NaN.
| |
| asin | back to summary |
|---|---|
| public static float asin(float a) Returns asin in radians; less accurate than Math.asin but may be faster. Average error of 0.000028447 radians (0.0016298931 degrees), largest error of 0.000067592 radians (0.0038727364 degrees). This implementation does not return NaN if given an out-of-range input (Math.asin does return NaN), unless the input is NaN.
| |
| asinDeg | back to summary |
|---|---|
| public static float asinDeg(float a) Returns arcsine in degrees. This implementation does not return NaN if given an out-of-range input (Math.asin does return NaN), unless the input is NaN.
| |
| atan | back to summary |
|---|---|
| public static float atan(float i) Arc tangent approximation with very low error, using an algorithm from the 1955 research study "Approximations for Digital
Computers," by RAND Corporation (this is sheet 11's algorithm, which is the fourth-fastest and fourth-least precise). This
method is usually about 4x faster than
| |
| atan2 | back to summary |
|---|---|
| public static float atan2(final float y, float x) Close approximation of the frequently-used trigonometric method atan2. Average error is 1.057E-6 radians; maximum error is
1.922E-6. Takes y and x (in that unusual order) as floats, and returns the angle from the origin to that point in radians.
It is about 4 times faster than
| |
| atan2Deg | back to summary |
|---|---|
| public static float atan2Deg(final float y, float x) Close approximation of the frequently-used trigonometric method atan2, using positive or negative degrees. Average absolute
error is 0.00006037 degrees; relative error is 0 degrees, maximum error is 0.00010396 degrees. Takes y and x (in that
unusual order) as floats, and returns the angle from the origin to that point in degrees.
| |
| atan2Deg360 | back to summary |
|---|---|
| public static float atan2Deg360(final float y, float x) Close approximation of the frequently-used trigonometric method atan2, using non-negative degrees only. Average absolute
error is 0.00006045 degrees; relative error is 0 degrees; maximum error is 0.00011178 degrees. Takes y and x (in that
unusual order) as floats, and returns the angle from the origin to that point in degrees.
| |
| atanDeg | back to summary |
|---|---|
| public static float atanDeg(float i) Arc tangent approximation returning a value measured in positive or negative degrees, using an algorithm from the 1955
research study "Approximations for Digital Computers," by RAND Corporation (this is sheet 11's algorithm, which is the
fourth-fastest and fourth-least precise). For finite inputs only, you may get a tiny speedup by using
| |
| atanUnchecked | back to summary |
|---|---|
| public static float atanUnchecked(double i) A variant on
| |
| atanUncheckedDeg | back to summary |
|---|---|
| public static double atanUncheckedDeg(double i) A variant on
| |
| ceil | back to summary |
|---|---|
| public static int ceil(float value) Returns the smallest integer greater than or equal to the specified float. This method will only properly ceil floats from -(2^14) to (Float.MAX_VALUE - 2^14). | |
| ceilPositive | back to summary |
|---|---|
| public static int ceilPositive(float value) Returns the smallest integer greater than or equal to the specified float. This method will only properly ceil floats that are positive. | |
| clamp | back to summary |
|---|---|
| public static short clamp(short value, short min, short max) | |
| clamp | back to summary |
|---|---|
| public static int clamp(int value, int min, int max) | |
| clamp | back to summary |
|---|---|
| public static long clamp(long value, long min, long max) | |
| clamp | back to summary |
|---|---|
| public static float clamp(float value, float min, float max) | |
| clamp | back to summary |
|---|---|
| public static double clamp(double value, double min, double max) | |
| cos | back to summary |
|---|---|
| public static float cos(float radians) Returns the cosine in radians from a lookup table. For optimal precision, use radians between -PI2 and PI2 (both inclusive). | |
| cosDeg | back to summary |
|---|---|
| public static float cosDeg(float degrees) Returns the cosine in degrees from a lookup table. For optimal precision, use degrees between -360 and 360 (both inclusive). | |
| floor | back to summary |
|---|---|
| public static int floor(float value) Returns the largest integer less than or equal to the specified float. This method will only properly floor floats from -(2^14) to (Float.MAX_VALUE - 2^14). | |
| floorPositive | back to summary |
|---|---|
| public static int floorPositive(float value) Returns the largest integer less than or equal to the specified float. This method will only properly floor floats that are positive. Note this method simply casts the float to int. | |
| isEqual | back to summary |
|---|---|
| public static boolean isEqual(float a, float b) Returns true if a is nearly equal to b. The function uses the default floating error tolerance.
| |
| isEqual | back to summary |
|---|---|
| public static boolean isEqual(float a, float b, float tolerance) Returns true if a is nearly equal to b.
| |
| isPowerOfTwo | back to summary |
|---|---|
| public static boolean isPowerOfTwo(int value) | |
| isZero | back to summary |
|---|---|
| public static boolean isZero(float value) Returns true if the value is zero (using the default tolerance as upper bound) | |
| isZero | back to summary |
|---|---|
| public static boolean isZero(float value, float tolerance) Returns true if the value is zero.
| |
| lerp | back to summary |
|---|---|
| public static float lerp(float fromValue, float toValue, float progress) Linearly interpolates between fromValue to toValue on progress position. | |
| lerpAngle | back to summary |
|---|---|
| public static float lerpAngle(float fromRadians, float toRadians, float progress) Linearly interpolates between two angles in radians. Takes into account that angles wrap at two pi and always takes the direction with the smallest delta angle.
| |
| lerpAngleDeg | back to summary |
|---|---|
| public static float lerpAngleDeg(float fromDegrees, float toDegrees, float progress) Linearly interpolates between two angles in degrees. Takes into account that angles wrap at 360 degrees and always takes the direction with the smallest delta angle.
| |
| log | back to summary |
|---|---|
public static float log(float a, float value)
| |
| log2 | back to summary |
|---|---|
public static float log2(float value)
| |
| map | back to summary |
|---|---|
| public static float map(float inRangeStart, float inRangeEnd, float outRangeStart, float outRangeEnd, float value) Linearly map a value from one range to another. Input range must not be empty. This is the same as chaining
| |
| nextPowerOfTwo | back to summary |
|---|---|
| public static int nextPowerOfTwo(int value) Returns the next power of two. Returns the specified value if the value is already a power of two. | |
| norm | back to summary |
|---|---|
| public static float norm(float rangeStart, float rangeEnd, float value) Linearly normalizes value from a range. Range must not be empty. This is the inverse of
| |
| random | back to summary |
|---|---|
| public static int random(int range) Returns a random number between 0 (inclusive) and the specified value (inclusive). | |
| random | back to summary |
|---|---|
| public static int random(int start, int end) Returns a random number between start (inclusive) and end (inclusive). | |
| random | back to summary |
|---|---|
| public static long random(long range) Returns a random number between 0 (inclusive) and the specified value (inclusive). | |
| random | back to summary |
|---|---|
| public static long random(long start, long end) Returns a random number between start (inclusive) and end (inclusive). | |
| random | back to summary |
|---|---|
| public static float random() Returns random number between 0.0 (inclusive) and 1.0 (exclusive). | |
| random | back to summary |
|---|---|
| public static float random(float range) Returns a random number between 0 (inclusive) and the specified value (exclusive). | |
| random | back to summary |
|---|---|
| public static float random(float start, float end) Returns a random number between start (inclusive) and end (exclusive). | |
| randomBoolean | back to summary |
|---|---|
| public static boolean randomBoolean() Returns a random boolean value. | |
| randomBoolean | back to summary |
|---|---|
| public static boolean randomBoolean(float chance) Returns true if a random value between 0 and 1 is less than the specified value. | |
| randomSign | back to summary |
|---|---|
| public static int randomSign() Returns -1 or 1, randomly. | |
| randomTriangular | back to summary |
|---|---|
| public static float randomTriangular() Returns a triangularly distributed random number between -1.0 (exclusive) and 1.0 (exclusive), where values around zero are more likely.
This is an optimized version of | |
| randomTriangular | back to summary |
|---|---|
| public static float randomTriangular(float max) Returns a triangularly distributed random number between
This is an optimized version of
| |
| randomTriangular | back to summary |
|---|---|
| public static float randomTriangular(float min, float max) Returns a triangularly distributed random number between
This method is equivalent of
| |
| randomTriangular | back to summary |
|---|---|
| public static float randomTriangular(float min, float max, float mode) Returns a triangularly distributed random number between
| |
| round | back to summary |
|---|---|
| public static int round(float value) Returns the closest integer to the specified float. This method will only properly round floats from -(2^14) to (Float.MAX_VALUE - 2^14). | |
| roundPositive | back to summary |
|---|---|
| public static int roundPositive(float value) Returns the closest integer to the specified float. This method will only properly round floats that are positive. | |
| sin | back to summary |
|---|---|
| public static float sin(float radians) Returns the sine in radians from a lookup table. For optimal precision, use radians between -PI2 and PI2 (both inclusive). | |
| sinDeg | back to summary |
|---|---|
| public static float sinDeg(float degrees) Returns the sine in degrees from a lookup table. For optimal precision, use degrees between -360 and 360 (both inclusive). | |
| tan | back to summary |
|---|---|
| public static float tan(float radians) Returns the tangent given an input in radians, using a Padé approximant.
| |
| tanDeg | back to summary |
|---|---|
| public static float tanDeg(float degrees) Returns the tangent given an input in degrees, using a Padé approximant. Based on this Stack Exchange answer.
| |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv static final float[] |
| Access | Constructor and Description |
|---|---|
| private |
| table | back to summary |
|---|---|
| pack-priv static final float[] table | |
| Sin | back to summary |
|---|---|
| private Sin() | |