Package com.ardor3d.math
Class MathUtils
java.lang.Object
com.ardor3d.math.MathUtils
-
Field Summary
Modifier and TypeFieldDescriptionstatic final double
A value to multiply a degree value by, to convert it to radians.static final double
A "close to zero" double epsilon value for usestatic final double
The value PI/2 as a double. (90 degrees)static final double
The value 1/PI as a double.static final double
The value 1/(2PI) as a double.static final double
static final double
The value PI as a double. (180 degrees)static final double
The value PI/4 as a double. (45 degrees)static final double
A value to multiply a radian value by, to convert it to degrees.static final Random
A precreated random object for random numbers.static final double
The value PI^2 as a double.static final double
The value 3/4 PI as a double. (135 degrees)static final double
The value 2PI as a double. (360 degrees)static final double
A "close to zero" double epsilon value for use -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic double
acos
(double dValue) static double
asin
(double dValue) static double
atan
(double dValue) static Vector3
cartesianToSpherical
(ReadOnlyVector3 cartCoords, Vector3 store) Converts a point from Cartesian coordinates (using positive Y as up) to Spherical and stores the results in the store var.static Vector3
cartesianZToSpherical
(ReadOnlyVector3 cartCoords, Vector3 store) Converts a point from Cartesian coordinates (using positive Z as up) to Spherical and stores the results in the store var.static double
clamp
(double val, double min, double max) static float
clamp
(float val, float min, float max) static int
clamp
(int val, int min, int max) static int
compare
(double d1, double d2) static double
cos
(double dValue) Returns cos of a value.static long
floor
(double val) Faster floor function.static int
floor
(float val) Faster floor function.static int
hashCode
(double value) static double
inverseSqrt
(double dValue) static boolean
isPowerOfTwo
(int number) Returns true if the number is a power of 2 (2,4,8,16...)static double
lerp
(double percent, double startValue, double endValue) static float
lerp
(float percent, float startValue, float endValue) static double
log
(double value, double base) static void
matrixFrustum
(double left, double right, double bottom, double top, double nearZ, double farZ, Matrix4 store) static void
matrixLookAt
(ReadOnlyVector3 position, ReadOnlyVector3 target, ReadOnlyVector3 worldUp, Matrix3 store) static void
matrixLookAt
(ReadOnlyVector3 position, ReadOnlyVector3 target, ReadOnlyVector3 worldUp, Matrix4 store) static void
matrixOrtho
(double left, double right, double bottom, double top, double nearZ, double farZ, Matrix4 store) static void
matrixPerspective
(double fovY, double aspect, double zNear, double zFar, Matrix4 store) static double
moduloPositive
(double value, double size) static float
moduloPositive
(float value, float size) static int
moduloPositive
(int value, int size) static int
nearestPowerOfTwo
(int number) static double
Returns a random double between 0 and 1.static float
Returns a random float between 0 and 1.static int
static int
nextRandomInt
(int min, int max) Returns a random int between min and max.static int
pow2
(int x) Simple 2^xstatic long
round
(double val) static int
round
(float val) static double
scurve3
(double t) plot a given value on the cubic S-curve: 3t^2 - 2t^3static float
scurve3
(float t) plot a given value on the cubic S-curve: 3t^2 - 2t^3static double
scurve5
(double t) plot a given value on the quintic S-curve: 6t^5 - 15t^4 + 10t^3static float
scurve5
(float t) plot a given value on the quintic S-curve: 6t^5 - 15t^4 + 10t^3static void
setRandomSeed
(long seed) Sets the seed to use for "random" operations.static double
sin
(double dValue) Returns sine of a value.static Vector3
sphericalToCartesian
(ReadOnlyVector3 sphereCoords, Vector3 store) Converts a point from Spherical coordinates to Cartesian (using positive Y as up) and stores the results in the store var.static Vector3
sphericalToCartesianZ
(ReadOnlyVector3 sphereCoords, Vector3 store) Converts a point from Spherical coordinates to Cartesian (using positive Z as up) and stores the results in the store var.static double
sqrt
(double dValue) static double
tan
(double dValue) static double
toUniqueZeroFloatingPointRepresentation
(double d)
-
Field Details
-
EPSILON
public static final double EPSILONA "close to zero" double epsilon value for use- See Also:
-
ZERO_TOLERANCE
public static final double ZERO_TOLERANCEA "close to zero" double epsilon value for use- See Also:
-
ONE_THIRD
public static final double ONE_THIRD- See Also:
-
PI
public static final double PIThe value PI as a double. (180 degrees)- See Also:
-
SQUARED_PI
public static final double SQUARED_PIThe value PI^2 as a double.- See Also:
-
TWO_PI
public static final double TWO_PIThe value 2PI as a double. (360 degrees)- See Also:
-
HALF_PI
public static final double HALF_PIThe value PI/2 as a double. (90 degrees)- See Also:
-
QUARTER_PI
public static final double QUARTER_PIThe value PI/4 as a double. (45 degrees)- See Also:
-
THREE_PI_HALVES
public static final double THREE_PI_HALVESThe value 3/4 PI as a double. (135 degrees)- See Also:
-
INV_PI
public static final double INV_PIThe value 1/PI as a double.- See Also:
-
INV_TWO_PI
public static final double INV_TWO_PIThe value 1/(2PI) as a double.- See Also:
-
DEG_TO_RAD
public static final double DEG_TO_RADA value to multiply a degree value by, to convert it to radians.- See Also:
-
RAD_TO_DEG
public static final double RAD_TO_DEGA value to multiply a radian value by, to convert it to degrees.- See Also:
-
rand
A precreated random object for random numbers.
-
-
Constructor Details
-
MathUtils
public MathUtils()
-
-
Method Details
-
sin
public static double sin(double dValue) Returns sine of a value. note: code from wiki posting on java.net by jeffpk- Parameters:
dValue
- The value to sine, in radians.- Returns:
- The sine of dValue.
- See Also:
-
cos
public static double cos(double dValue) Returns cos of a value.- Parameters:
dValue
- The value to cosine, in radians.- Returns:
- The cosine of dValue.
- See Also:
-
sqrt
public static double sqrt(double dValue) -
inverseSqrt
public static double inverseSqrt(double dValue) -
atan
public static double atan(double dValue) -
asin
public static double asin(double dValue) -
tan
public static double tan(double dValue) -
acos
public static double acos(double dValue) -
sphericalToCartesian
Converts a point from Spherical coordinates to Cartesian (using positive Y as up) and stores the results in the store var.- Parameters:
sphereCoords
- (Radius, Azimuth, Polar)store
- the vector to store the result in for return. If null, a new vector object is created and returned.- Returns:
- the Cartesian coordinates
-
cartesianToSpherical
Converts a point from Cartesian coordinates (using positive Y as up) to Spherical and stores the results in the store var. (Radius, Azimuth, Polar)- Parameters:
cartCoords
- the Cartesian coordinates (using positive Y as up)store
- the vector to store the result in for return. If null, a new vector object is created and returned.- Returns:
- the spherical coordinates
-
sphericalToCartesianZ
Converts a point from Spherical coordinates to Cartesian (using positive Z as up) and stores the results in the store var.- Parameters:
sphereCoords
- (Radius, Azimuth, Polar)store
- the vector to store the result in for return. If null, a new vector object is created and returned.- Returns:
- the Cartesian coordinates
-
cartesianZToSpherical
Converts a point from Cartesian coordinates (using positive Z as up) to Spherical and stores the results in the store var. (Radius, Azimuth, Polar)- Parameters:
cartCoords
- the Cartesian coordinates (using positive Z as up)store
- the vector to store the result in for return. If null, a new vector object is created and returned.- Returns:
- the spherical coordinates
-
isPowerOfTwo
public static boolean isPowerOfTwo(int number) Returns true if the number is a power of 2 (2,4,8,16...) A good implementation found on the Java boards. note: a number is a power of two if and only if it is the smallest number with that number of significant bits. Therefore, if you subtract 1, you know that the new number will have fewer bits, so ANDing the original number with anything less than it will give 0.- Parameters:
number
- The number to test.- Returns:
- True if it is a power of two.
-
nearestPowerOfTwo
public static int nearestPowerOfTwo(int number) - Parameters:
number
- The number to test- Returns:
- the closest power of two to the given number.
-
log
public static double log(double value, double base) - Parameters:
value
- the valuebase
- the base- Returns:
- the logarithm of value with given base, calculated as log(value)/log(base) such that pow(base, return)==value
-
setRandomSeed
public static void setRandomSeed(long seed) Sets the seed to use for "random" operations. The default is the current system milliseconds.- Parameters:
seed
- the seed
-
nextRandomDouble
public static double nextRandomDouble()Returns a random double between 0 and 1.- Returns:
- A random double between 0.0 (inclusive) to 1.0 (exclusive).
-
nextRandomFloat
public static float nextRandomFloat()Returns a random float between 0 and 1.- Returns:
- A random float between 0.0f (inclusive) to 1.0f (exclusive).
-
nextRandomInt
public static int nextRandomInt()- Returns:
- A random int between Integer.MIN_VALUE and Integer.MAX_VALUE.
-
nextRandomInt
public static int nextRandomInt(int min, int max) Returns a random int between min and max.- Parameters:
min
- the minimum valuemax
- the maximum value- Returns:
- A random int between min (inclusive) to max (inclusive).
-
lerp
public static float lerp(float percent, float startValue, float endValue) - Parameters:
percent
- the percent valuestartValue
- the start valueendValue
- the end value- Returns:
- the lerp
-
lerp
public static double lerp(double percent, double startValue, double endValue) - Parameters:
percent
- the percent valuestartValue
- the start valueendValue
- the end value- Returns:
- the lerp
-
scurve3
public static float scurve3(float t) plot a given value on the cubic S-curve: 3t^2 - 2t^3- Parameters:
t
- our input value- Returns:
- the plotted value
-
scurve3
public static double scurve3(double t) plot a given value on the cubic S-curve: 3t^2 - 2t^3- Parameters:
t
- our input value- Returns:
- the plotted value
-
scurve5
public static float scurve5(float t) plot a given value on the quintic S-curve: 6t^5 - 15t^4 + 10t^3- Parameters:
t
- our input value- Returns:
- the plotted value
-
scurve5
public static double scurve5(double t) plot a given value on the quintic S-curve: 6t^5 - 15t^4 + 10t^3- Parameters:
t
- our input value- Returns:
- the plotted value
-
matrixFrustum
public static void matrixFrustum(double left, double right, double bottom, double top, double nearZ, double farZ, Matrix4 store) - Parameters:
left
- the left abscissaright
- the right abscissabottom
- the bottom ordinatetop
- the top ordinatenearZ
- the near applicatefarZ
- the far applicatestore
- the object to store the matrix of the frustum (similar to glFrustum)
-
matrixOrtho
public static void matrixOrtho(double left, double right, double bottom, double top, double nearZ, double farZ, Matrix4 store) - Parameters:
left
- the left abscissaright
- the right abscissabottom
- the bottom ordinatetop
- the top ordinatenearZ
- the near applicatefarZ
- the far applicatestore
- the object to store the matrix in orthogonal projection
-
matrixPerspective
public static void matrixPerspective(double fovY, double aspect, double zNear, double zFar, Matrix4 store) - Parameters:
fovY
- the fov Yaspect
- the aspectzNear
- the near applicatezFar
- the far applicatestore
- the object to store the matrix in perspective projection (similar to gluPerspective)
-
matrixLookAt
public static void matrixLookAt(ReadOnlyVector3 position, ReadOnlyVector3 target, ReadOnlyVector3 worldUp, Matrix4 store) - Parameters:
position
- the positiontarget
- the targetworldUp
- the up vectorstore
- the object to store the result, the model view matrix (similar to gluLookAt)
-
matrixLookAt
public static void matrixLookAt(ReadOnlyVector3 position, ReadOnlyVector3 target, ReadOnlyVector3 worldUp, Matrix3 store) - Parameters:
position
- the positiontarget
- the targetworldUp
- the up vectorstore
- the object to store the result, the model view matrix (similar to gluLookAt)
-
floor
public static int floor(float val) Faster floor function. Does not handle NaN and Infinity. (Not handled when doing Math.floor and just casting anyways, so question is if we want to handle it or not)- Parameters:
val
- Value to floor- Returns:
- Floored int value
-
floor
public static long floor(double val) Faster floor function. Does not handle NaN and Infinity. (Not handled when doing Math.floor and just casting anyways, so question is if we want to handle it or not)- Parameters:
val
- Value to floor- Returns:
- Floored long value
-
round
public static int round(float val) -
round
public static long round(double val) -
clamp
public static double clamp(double val, double min, double max) -
clamp
public static float clamp(float val, float min, float max) -
clamp
public static int clamp(int val, int min, int max) -
moduloPositive
public static int moduloPositive(int value, int size) -
moduloPositive
public static float moduloPositive(float value, float size) -
moduloPositive
public static double moduloPositive(double value, double size) -
pow2
public static int pow2(int x) Simple 2^x- Parameters:
x
- power- Returns:
- 2^x
-
toUniqueZeroFloatingPointRepresentation
public static double toUniqueZeroFloatingPointRepresentation(double d) -
compare
public static int compare(double d1, double d2) -
hashCode
public static int hashCode(double value)
-