public class GenericMath extends Object
| Modifier and Type | Field and Description |
|---|---|
static double |
DBL_EPSILON
A "close to zero" double epsilon value for use
|
static float |
FLT_EPSILON
A "close to zero" float epsilon value for use
|
| Modifier and Type | Method and Description |
|---|---|
static double |
biLerp(double x,
double y,
double q00,
double q01,
double q10,
double q11,
double x1,
double x2,
double y1,
double y2)
Calculates the value at x,y using bilinear interpolation
|
static Color |
blend(Color a,
Color b)
Blends two colors into one.
|
static Boolean |
castBoolean(Object o)
Casts a value to a boolean.
|
static Byte |
castByte(Object o)
Casts a value to a byte.
|
static Double |
castDouble(Object o)
Casts a value to a double.
|
static Float |
castFloat(Object o)
Casts a value to a float.
|
static Integer |
castInt(Object o)
Casts a value to an integer.
|
static Long |
castLong(Object o)
Casts a value to a long.
|
static Short |
castShort(Object o)
Casts a value to a short.
|
static double |
clamp(double value,
double low,
double high)
Clamps the value between the low and high boundaries
|
static int |
clamp(int value,
int low,
int high)
Clamps the value between the low and high boundaries
|
static String |
decToHex(int dec,
int minDigits)
Converts an integer to hexadecimal form with at least the minimum of digits specified (by adding leading zeros).
|
static int |
floor(double a)
Rounds 'a' down to the closest integer
|
static int |
floor(float a)
Rounds 'a' down to the closest integer
|
static long |
floorl(double a)
Rounds 'a' down to the closest long
|
static long |
floorl(float a)
Rounds 'a' down to the closest long
|
static float |
getDegreeDifference(float angle1,
float angle2)
Gets the difference between two angles This value is always positive (0 - 180)
|
static double |
getRadianDifference(double radian1,
double radian2)
Gets the difference between two radians This value is always positive (0 - PI)
|
static Random |
getRandom()
Gets a thread local Random object that is seeded using SecureRandom.
|
static double |
inverseSqrt(double a)
Returns a fast estimate of the inverse square root of the value
|
static boolean |
isPowerOfTwo(int num)
Determines if the given number is a power of two.
|
static Color |
lerp(Color a,
Color b,
float percent)
Calculates the linear interpolation between a and b with the given percent
|
static double |
lerp(double a,
double b,
double percent)
Calculates the linear interpolation between a and b with the given percent
|
static double |
lerp(double x,
double x1,
double x2,
double q0,
double q1)
Calculates the value at x using linear interpolation
|
static float |
lerp(float a,
float b,
float percent)
Calculates the linear interpolation between a and b with the given percent
|
static int |
lerp(int a,
int b,
int percent)
Calculates the linear interpolation between a and b with the given percent
|
static Quaterniond |
lerp(Quaterniond a,
Quaterniond b,
double percent)
Interpolates a quaternion between two others using linear interpolation.
|
static Quaternionf |
lerp(Quaternionf a,
Quaternionf b,
float percent)
Interpolates a quaternion between two others using linear interpolation.
|
static Vector2d |
lerp(Vector2d a,
Vector2d b,
double percent)
Calculates the linear interpolation between a and b with the given percent
|
static Vector2f |
lerp(Vector2f a,
Vector2f b,
float percent)
Calculates the linear interpolation between a and b with the given percent
|
static Vector3d |
lerp(Vector3d a,
Vector3d b,
double percent)
Calculates the linear interpolation between a and b with the given percent
|
static Vector3f |
lerp(Vector3f a,
Vector3f b,
float percent)
Calculates the linear interpolation between a and b with the given percent
|
static byte |
max(byte value1,
byte value2)
Gets the maximum byte value from two values
|
static double |
mean(double... values)
Calculates the mean of a set of values.
|
static int |
mean(int... values)
Calculates the mean of a set of values
|
static double |
mod(double a,
double div)
Returns the modulo of 'a' by 'div' with corrections for negative numbers.
|
static float |
mod(float a,
float div)
Returns the modulo of 'a' by 'div' with corrections for negative numbers.
|
static int |
mod(int a,
int div)
Returns the modulo of 'a' by 'div' with corrections for negative numbers.
|
static int |
multiplyToShift(int a)
Converts a multiplication into a shift.
|
static Vector2d |
normalizeSafe(Vector2d v)
Attempts to normalize a vector.
|
static Vector2f |
normalizeSafe(Vector2f v)
Attempts to normalize a vector.
|
static Vector3d |
normalizeSafe(Vector3d v)
Attempts to normalize a vector.
|
static Vector3f |
normalizeSafe(Vector3f v)
Attempts to normalize a vector.
|
static Vector4d |
normalizeSafe(Vector4d v)
Attempts to normalize a vector.
|
static Vector4f |
normalizeSafe(Vector4f v)
Attempts to normalize a vector.
|
static VectorNd |
normalizeSafe(VectorNd v)
Attempts to normalize a vector.
|
static VectorNf |
normalizeSafe(VectorNf v)
Attempts to normalize a vector.
|
static double |
round(double input,
int decimals)
Rounds a number to the amount of decimals specified
|
static int |
roundUpPow2(int a)
Rounds an integer up to the next power of 2.
|
static long |
roundUpPow2(long a)
Rounds an integer up to the next power of 2.
|
static Quaterniond |
slerp(Quaterniond a,
Quaterniond b,
double percent)
Interpolates a quaternion between two others using spherical linear interpolation.
|
static Quaternionf |
slerp(Quaternionf a,
Quaternionf b,
float percent)
Interpolates a quaternion between two others using spherical linear interpolation.
|
static double |
sqrt(double a)
Returns a fast estimate of the square root of the value
|
static double |
triLerp(double x,
double y,
double z,
double q000,
double q001,
double q010,
double q011,
double q100,
double q101,
double q110,
double q111,
double x1,
double x2,
double y1,
double y2,
double z1,
double z2)
Calculates the value at x,y,z using trilinear interpolation
|
static float |
wrapAngleDeg(float angle)
Wraps the angle between -180 and 180 degrees
|
static float |
wrapAnglePitchDeg(float angle)
Wraps the pitch angle between -90 and 90 degrees
|
static double |
wrapAngleRad(double angle)
Wraps the radian between -PI and PI
|
static byte |
wrapByte(int value)
Wraps a byte between 0 and 256
|
public static final double DBL_EPSILON
public static final float FLT_EPSILON
public static float getDegreeDifference(float angle1,
float angle2)
angle1 - The first angleangle2 - The second anglepublic static double getRadianDifference(double radian1,
double radian2)
radian1 - The first angleradian2 - The second anglepublic static float wrapAngleDeg(float angle)
angle - to wrappublic static double wrapAngleRad(double angle)
angle - to wrappublic static float wrapAnglePitchDeg(float angle)
angle - to wrappublic static byte wrapByte(int value)
value - to wrappublic static double round(double input,
int decimals)
input - to rounddecimals - to round topublic static double lerp(double a,
double b,
double percent)
a - The first know valueb - The second know valuepercent - The percentpublic static float lerp(float a,
float b,
float percent)
a - The first know valueb - The second know valuepercent - The percentpublic static int lerp(int a,
int b,
int percent)
a - The first know valueb - The second know valuepercent - The percentpublic static Vector3f lerp(Vector3f a, Vector3f b, float percent)
a - The first know valueb - The second know valuepercent - The percentpublic static Vector3d lerp(Vector3d a, Vector3d b, double percent)
a - The first know valueb - The second know valuepercent - The percentpublic static Vector2f lerp(Vector2f a, Vector2f b, float percent)
a - The first know valueb - The second know valuepercent - The percentpublic static Vector2d lerp(Vector2d a, Vector2d b, double percent)
a - The first know valueb - The second know valuepercent - The percentpublic static double lerp(double x,
double x1,
double x2,
double q0,
double q1)
x - the X coord of the value to interpolatex1 - the X coord of q0x2 - the X coord of q1q0 - the first known value (x1)q1 - the second known value (x2)public static Color lerp(Color a, Color b, float percent)
a - The first know valueb - The second know valuepercent - The percentpublic static Quaternionf slerp(Quaternionf a, Quaternionf b, float percent)
a - The first quaternionb - The second quaternionpercent - The percent for the interpolation, between 0 and 1 inclusivelypublic static Quaterniond slerp(Quaterniond a, Quaterniond b, double percent)
a - The first quaternionb - The second quaternionpercent - The percent for the interpolation, between 0 and 1 inclusivelypublic static Quaternionf lerp(Quaternionf a, Quaternionf b, float percent)
a - The first quaternionb - The second quaternionpercent - The percent for the interpolation, between 0 and 1 inclusivelypublic static Quaterniond lerp(Quaterniond a, Quaterniond b, double percent)
a - The first quaternionb - The second quaternionpercent - The percent for the interpolation, between 0 and 1 inclusivelypublic static double biLerp(double x,
double y,
double q00,
double q01,
double q10,
double q11,
double x1,
double x2,
double y1,
double y2)
x - the X coord of the value to interpolatey - the Y coord of the value to interpolateq00 - the first known value (x1, y1)q01 - the second known value (x1, y2)q10 - the third known value (x2, y1)q11 - the fourth known value (x2, y2)x1 - the X coord of q00 and q01x2 - the X coord of q10 and q11y1 - the Y coord of q00 and q10y2 - the Y coord of q01 and q11public static double triLerp(double x,
double y,
double z,
double q000,
double q001,
double q010,
double q011,
double q100,
double q101,
double q110,
double q111,
double x1,
double x2,
double y1,
double y2,
double z1,
double z2)
x - the X coord of the value to interpolatey - the Y coord of the value to interpolatez - the Z coord of the value to interpolateq000 - the first known value (x1, y1, z1)q001 - the second known value (x1, y2, z1)q010 - the third known value (x1, y1, z2)q011 - the fourth known value (x1, y2, z2)q100 - the fifth known value (x2, y1, z1)q101 - the sixth known value (x2, y2, z1)q110 - the seventh known value (x2, y1, z2)q111 - the eighth known value (x2, y2, z2)x1 - the X coord of q000, q001, q010 and q011x2 - the X coord of q100, q101, q110 and q111y1 - the Y coord of q000, q010, q100 and q110y2 - the Y coord of q001, q011, q101 and q111z1 - the Z coord of q000, q001, q100 and q101z2 - the Z coord of q010, q011, q110 and q111public static Color blend(Color a, Color b)
a - The first colorb - The second colorpublic static double clamp(double value,
double low,
double high)
value - The value to clamplow - The low bound of the clamphigh - The high bound of the clamppublic static int clamp(int value,
int low,
int high)
value - The value to clamplow - The low bound of the clamphigh - The high bound of the clamppublic static double inverseSqrt(double a)
a - The valuepublic static double sqrt(double a)
a - The valuepublic static int floor(double a)
a - The value to floorpublic static int floor(float a)
a - The value to floorpublic static long floorl(double a)
a - The value to floorpublic static long floorl(float a)
a - The value to floorpublic static byte max(byte value1,
byte value2)
value1 - The first valuevalue2 - The second valuepublic static int roundUpPow2(int a)
a - The integer to roundpublic static long roundUpPow2(long a)
a - The long to roundpublic static Float castFloat(Object o)
o - The object to attempt to castpublic static Byte castByte(Object o)
o - The object to attempt to castpublic static Short castShort(Object o)
o - The object to attempt to castpublic static Integer castInt(Object o)
o - The object to attempt to castpublic static Double castDouble(Object o)
o - The object to attempt to castpublic static Long castLong(Object o)
o - The object to attempt to castpublic static Boolean castBoolean(Object o)
o - The object to attempt to castpublic static int mean(int... values)
values - to calculate the mean ofpublic static double mean(double... values)
values - to calculate the mean ofpublic static String decToHex(int dec, int minDigits)
dec - The integer to convertminDigits - The minimum of digits in the hexadecimal formpublic static int mod(int a,
int div)
a - The number as an intdiv - The div as an intpublic static float mod(float a,
float div)
a - The dividenddiv - The dividerpublic static double mod(double a,
double div)
a - The dividenddiv - The dividerpublic static Random getRandom()
public static boolean isPowerOfTwo(int num)
public static int multiplyToShift(int a)
a - the multiplicandpublic static Vector2f normalizeSafe(Vector2f v)
v - The vector to attempt to normalizepublic static Vector2d normalizeSafe(Vector2d v)
v - The vector to attempt to normalizepublic static Vector3f normalizeSafe(Vector3f v)
v - The vector to attempt to normalizepublic static Vector3d normalizeSafe(Vector3d v)
v - The vector to attempt to normalizepublic static Vector4f normalizeSafe(Vector4f v)
v - The vector to attempt to normalizepublic static Vector4d normalizeSafe(Vector4d v)
v - The vector to attempt to normalizepublic static VectorNf normalizeSafe(VectorNf v)
v - The vector to attempt to normalizepublic static VectorNd normalizeSafe(VectorNd v)
v - The vector to attempt to normalizeCopyright © 2013–2016 Flow Powered. All rights reserved.