Package com.jme3.math
Class FastMath
java.lang.Object
com.jme3.math.FastMath
FastMath
provides 'fast' math approximations and float equivalents of Math
functions. These are all used as static values and functions.-
Field Summary
Modifier and TypeFieldDescriptionstatic final double
A "close to zero" double epsilon value for usestatic final float
A value to multiply a degree value by, to convert it to radians.static final float
A "close to zero" float epsilon value for usestatic final float
The value PI/2 as a float.static final float
The value 1/PI as a float.static final float
The value 1/(2PI) as a float.static final float
The value 1/3, as a float.static final float
The value PI as a float.static final float
The value PI/4 as a float.static final float
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 float
The value 2PI as a float.static final float
A "close to zero" float epsilon value for use -
Method Summary
Modifier and TypeMethodDescriptionstatic float
abs
(float fValue) Returns Absolute value of a float.static float
acos
(float fValue) Returns the arc cosine of a value.
Special cases: If fValue is smaller than -1, then the result is PI.static boolean
approximateEquals
(float a, float b) Determine if two floats are approximately equal.static float
asin
(float fValue) Returns the arc sine of a value.
Special cases: If fValue is smaller than -1, then the result is -HALF_PI.static float
atan
(float fValue) Returns the arc tangent of an angle given in radians.static float
atan2
(float fY, float fX) A direct call to Math.atan2.static Vector3f
cartesianToSpherical
(Vector3f cartCoords, Vector3f store) Converts a point from Cartesian coordinates (using positive Y as up) to Spherical and stores the results in the store var.static Vector3f
cartesianZToSpherical
(Vector3f cartCoords, Vector3f store) Converts a point from Cartesian coordinates (using positive Z as up) to Spherical and stores the results in the store var.static float
ceil
(float fValue) Rounds a fValue up.static float
clamp
(float input, float min, float max) Take a float input and clamp it between min and max.static Vector3f
computeNormal
(Vector3f v1, Vector3f v2, Vector3f v3) A method that computes normal for a triangle defined by three vertices.static short
convertFloatToHalf
(float flt) Convert a single-precision (32-bit) floating-point value to half precision.static float
convertHalfToFloat
(short half) Converts a single precision (32 bit) floating point value into half precision (16 bit).static float
copysign
(float x, float y) static float
cos
(float v) Returns cosine of an angle.static int
counterClockwise
(Vector2f p0, Vector2f p1, Vector2f p2) Given 3 points in a 2d plane, this function computes if the points going from A-B-C are moving counter clock wise.static float
determinant
(double m00, double m01, double m02, double m03, double m10, double m11, double m12, double m13, double m20, double m21, double m22, double m23, double m30, double m31, double m32, double m33) Returns the determinant of a 4x4 matrix.static float
exp
(float fValue) Returns E^fValuestatic float
extrapolateLinear
(float scale, float startValue, float endValue) Linear extrapolation from startValue to endValue by the given scale.static Vector3f
extrapolateLinear
(float scale, Vector3f startValue, Vector3f endValue) Linear extrapolation from startValue to endValue by the given scale.static Vector3f
extrapolateLinear
(float scale, Vector3f startValue, Vector3f endValue, Vector3f store) Linear extrapolation from startValue to endValue by the given scale.static float
fastInvSqrt
(float x) Quickly estimate 1/sqrt(fValue).static float
floor
(float fValue) Returns a number rounded down.static float
getBezierP1toP2Length
(Vector3f p0, Vector3f p1, Vector3f p2, Vector3f p3) Compute the length on a Bezier spline between control points 1 and 2.static float
getCatmullRomP1toP2Length
(Vector3f p0, Vector3f p1, Vector3f p2, Vector3f p3, float startRange, float endRange, float curveTension) Compute the length of a Catmull–Rom spline between control points 1 and 2static float
interpolateBezier
(float u, float p0, float p1, float p2, float p3) Interpolate a spline between at least 4 control points following the Bezier equation.static Vector3f
interpolateBezier
(float u, Vector3f p0, Vector3f p1, Vector3f p2, Vector3f p3) Interpolate a spline between at least 4 control points following the Bezier equation.static Vector3f
Interpolate a spline between at least 4 control points following the Bezier equation.static float
interpolateCatmullRom
(float u, float T, float p0, float p1, float p2, float p3) Interpolate a spline between at least 4 control points following the Catmull-Rom equation.static Vector3f
interpolateCatmullRom
(float u, float T, Vector3f p0, Vector3f p1, Vector3f p2, Vector3f p3) Interpolate a spline between at least 4 control points using the Catmull-Rom equation.static Vector3f
interpolateCatmullRom
(float u, float T, Vector3f p0, Vector3f p1, Vector3f p2, Vector3f p3, Vector3f store) Interpolate a spline between at least 4 control points following the Catmull-Rom equation.static float
interpolateLinear
(float scale, float startValue, float endValue) Linear interpolation from startValue to endValue by the given percent.static Vector3f
interpolateLinear
(float scale, Vector3f startValue, Vector3f endValue) Linear interpolation from startValue to endValue by the given percent.static Vector3f
interpolateLinear
(float scale, Vector3f startValue, Vector3f endValue, Vector3f store) Linear interpolation from startValue to endValue by the given percent.static float
invSqrt
(float fValue) Returns 1/sqrt(fValue)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.static float
log
(float fValue) Returns the log base E of a value.static float
log
(float value, float base) Returns the logarithm of value with given base, calculated as log(value)/log(base), so that pow(base, return)==value (contributed by vear)static int
nearestPowerOfTwo
(int number) Get the next power of two of the given number.static float
Returns a random float between 0 and 1.static int
Choose a pseudo-random, uniformly-distributed integer value from the shared generator.static int
nextRandomInt
(int min, int max) Returns a random integer between min and max.static float
normalize
(float val, float min, float max) Takes a value and expresses it in terms of min to max.static int
pointInsideTriangle
(Vector2f t0, Vector2f t1, Vector2f t2, Vector2f p) Test if a point is inside a triangle.static float
pow
(float fBase, float fExponent) Returns a number raised to an exponent power.static float
saturate
(float input) Clamps the given float to be between 0 and 1.static float
sign
(float fValue) Returns 1 if the number is positive, -1 if the number is negative, and 0 otherwisestatic int
sign
(int iValue) Returns 1 if the number is positive, -1 if the number is negative, and 0 otherwisestatic float
sin
(float v) Returns the sine of an angle.static Vector3f
sphericalToCartesian
(Vector3f sphereCoords, Vector3f store) Converts a point from Spherical coordinates to Cartesian (using positive Y as up) and stores the results in the store var.static Vector3f
sphericalToCartesianZ
(Vector3f sphereCoords, Vector3f store) Converts a point from Spherical coordinates to Cartesian (using positive Z as up) and stores the results in the store var.static float
sqr
(float fValue) Returns the value squared.static float
sqrt
(float fValue) Returns the square root of a given value.static float
tan
(float fValue) Returns the tangent of the specified angle.static float
unInterpolateLinear
(float value, float min, float max) Converts a range of min/max to a 0-1 range.
-
Field Details
-
DBL_EPSILON
public static final double DBL_EPSILONA "close to zero" double epsilon value for use- See Also:
-
FLT_EPSILON
public static final float FLT_EPSILONA "close to zero" float epsilon value for use- See Also:
-
ZERO_TOLERANCE
public static final float ZERO_TOLERANCEA "close to zero" float epsilon value for use- See Also:
-
ONE_THIRD
public static final float ONE_THIRDThe value 1/3, as a float.- See Also:
-
PI
public static final float PIThe value PI as a float. (180 degrees)- See Also:
-
TWO_PI
public static final float TWO_PIThe value 2PI as a float. (360 degrees)- See Also:
-
HALF_PI
public static final float HALF_PIThe value PI/2 as a float. (90 degrees)- See Also:
-
QUARTER_PI
public static final float QUARTER_PIThe value PI/4 as a float. (45 degrees)- See Also:
-
INV_PI
public static final float INV_PIThe value 1/PI as a float.- See Also:
-
INV_TWO_PI
public static final float INV_TWO_PIThe value 1/(2PI) as a float.- See Also:
-
DEG_TO_RAD
public static final float DEG_TO_RADA value to multiply a degree value by, to convert it to radians.- See Also:
-
RAD_TO_DEG
public static final float 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.
-
-
Method Details
-
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) Get the next power of two of the given number. E.g. for an input 100, this returns 128. Returns 1 for all numbers less than or equal to 1.- Parameters:
number
- The number to obtain the POT for.- Returns:
- The next power of two.
-
interpolateLinear
public static float interpolateLinear(float scale, float startValue, float endValue) Linear interpolation from startValue to endValue by the given percent. Basically: ((1 - percent) * startValue) + (percent * endValue)- Parameters:
scale
- scale value to use. if 1, use endValue, if 0, use startValue.startValue
- Beginning value. 0% of fendValue
- ending value. 100% of f- Returns:
- The interpolated value between startValue and endValue.
-
interpolateLinear
public static Vector3f interpolateLinear(float scale, Vector3f startValue, Vector3f endValue, Vector3f store) Linear interpolation from startValue to endValue by the given percent. Basically: ((1 - percent) * startValue) + (percent * endValue)- Parameters:
scale
- scale value to use. if 1, use endValue, if 0, use startValue.startValue
- Beginning value. 0% of fendValue
- ending value. 100% of fstore
- a vector3f to store the result- Returns:
- The interpolated value between startValue and endValue.
-
interpolateLinear
Linear interpolation from startValue to endValue by the given percent. Basically: ((1 - percent) * startValue) + (percent * endValue)- Parameters:
scale
- scale value to use. if 1, use endValue, if 0, use startValue.startValue
- Beginning value. 0% of fendValue
- ending value. 100% of f- Returns:
- The interpolated value between startValue and endValue.
-
extrapolateLinear
public static float extrapolateLinear(float scale, float startValue, float endValue) Linear extrapolation from startValue to endValue by the given scale. if scale is between 0 and 1 this method returns the same result as interpolateLinear if the scale is over 1 the value is linearly extrapolated. Note that the end value is the value for a scale of 1.- Parameters:
scale
- the scale for extrapolationstartValue
- the starting value (scale = 0)endValue
- the end value (scale = 1)- Returns:
- an extrapolation for the given parameters
-
extrapolateLinear
public static Vector3f extrapolateLinear(float scale, Vector3f startValue, Vector3f endValue, Vector3f store) Linear extrapolation from startValue to endValue by the given scale. if scale is between 0 and 1 this method returns the same result as interpolateLinear if the scale is over 1 the value is linearly extrapolated. Note that the end value is the value for a scale of 1.- Parameters:
scale
- the scale for extrapolationstartValue
- the starting value (scale = 0)endValue
- the end value (scale = 1)store
- an initialized vector to store the return value- Returns:
- an extrapolation for the given parameters
-
extrapolateLinear
Linear extrapolation from startValue to endValue by the given scale. if scale is between 0 and 1 this method returns the same result as interpolateLinear if the scale is over 1 the value is linearly extrapolated. Note that the end value is the value for a scale of 1.- Parameters:
scale
- the scale for extrapolationstartValue
- the starting value (scale = 0)endValue
- the end value (scale = 1)- Returns:
- an extrapolation for the given parameters
-
interpolateCatmullRom
public static float interpolateCatmullRom(float u, float T, float p0, float p1, float p2, float p3) Interpolate a spline between at least 4 control points following the Catmull-Rom equation. here is the interpolation matrix m = [ 0.0 1.0 0.0 0.0 ] [-T 0.0 T 0.0 ] [ 2T T-3 3-2T -T ] [-T 2-T T-2 T ] where T is the curve tension the result is a value between p1 and p2, t=0 for p1, t=1 for p2- Parameters:
u
- value from 0 to 1T
- The tension of the curvep0
- control point 0p1
- control point 1p2
- control point 2p3
- control point 3- Returns:
- Catmull–Rom interpolation
-
interpolateCatmullRom
public static Vector3f interpolateCatmullRom(float u, float T, Vector3f p0, Vector3f p1, Vector3f p2, Vector3f p3, Vector3f store) Interpolate a spline between at least 4 control points following the Catmull-Rom equation. here is the interpolation matrix m = [ 0.0 1.0 0.0 0.0 ] [-T 0.0 T 0.0 ] [ 2T T-3 3-2T -T ] [-T 2-T T-2 T ] where T is the tension of the curve the result is a value between p1 and p2, t=0 for p1, t=1 for p2- Parameters:
u
- value from 0 to 1T
- The tension of the curvep0
- control point 0p1
- control point 1p2
- control point 2p3
- control point 3store
- a Vector3f to store the result- Returns:
- Catmull–Rom interpolation
-
interpolateCatmullRom
public static Vector3f interpolateCatmullRom(float u, float T, Vector3f p0, Vector3f p1, Vector3f p2, Vector3f p3) Interpolate a spline between at least 4 control points using the Catmull-Rom equation. Here is the interpolation matrix: m = [ 0.0 1.0 0.0 0.0 ] [-T 0.0 T 0.0 ] [ 2T T-3 3-2T -T ] [-T 2-T T-2 T ] where T is the tension of the curve the result is a value between p1 and p2, t=0 for p1, t=1 for p2- Parameters:
u
- value from 0 to 1T
- The tension of the curvep0
- control point 0p1
- control point 1p2
- control point 2p3
- control point 3- Returns:
- Catmull–Rom interpolation
-
interpolateBezier
public static float interpolateBezier(float u, float p0, float p1, float p2, float p3) Interpolate a spline between at least 4 control points following the Bezier equation. here is the interpolation matrix m = [ -1.0 3.0 -3.0 1.0 ] [ 3.0 -6.0 3.0 0.0 ] [ -3.0 3.0 0.0 0.0 ] [ 1.0 0.0 0.0 0.0 ] where T is the curve tension the result is a value between p1 and p3, t=0 for p1, t=1 for p3- Parameters:
u
- value from 0 to 1p0
- control point 0p1
- control point 1p2
- control point 2p3
- control point 3- Returns:
- Bezier interpolation
-
interpolateBezier
public static Vector3f interpolateBezier(float u, Vector3f p0, Vector3f p1, Vector3f p2, Vector3f p3, Vector3f store) Interpolate a spline between at least 4 control points following the Bezier equation. here is the interpolation matrix m = [ -1.0 3.0 -3.0 1.0 ] [ 3.0 -6.0 3.0 0.0 ] [ -3.0 3.0 0.0 0.0 ] [ 1.0 0.0 0.0 0.0 ] where T is the tension of the curve the result is a value between p1 and p3, t=0 for p1, t=1 for p3- Parameters:
u
- value from 0 to 1p0
- control point 0p1
- control point 1p2
- control point 2p3
- control point 3store
- a Vector3f to store the result- Returns:
- Bezier interpolation
-
interpolateBezier
public static Vector3f interpolateBezier(float u, Vector3f p0, Vector3f p1, Vector3f p2, Vector3f p3) Interpolate a spline between at least 4 control points following the Bezier equation. here is the interpolation matrix m = [ -1.0 3.0 -3.0 1.0 ] [ 3.0 -6.0 3.0 0.0 ] [ -3.0 3.0 0.0 0.0 ] [ 1.0 0.0 0.0 0.0 ] where T is the tension of the curve the result is a value between p1 and p3, t=0 for p1, t=1 for p3- Parameters:
u
- value from 0 to 1p0
- control point 0p1
- control point 1p2
- control point 2p3
- control point 3- Returns:
- Bezier interpolation
-
getCatmullRomP1toP2Length
public static float getCatmullRomP1toP2Length(Vector3f p0, Vector3f p1, Vector3f p2, Vector3f p3, float startRange, float endRange, float curveTension) Compute the length of a Catmull–Rom spline between control points 1 and 2- Parameters:
p0
- control point 0p1
- control point 1p2
- control point 2p3
- control point 3startRange
- the starting range on the segment (use 0)endRange
- the end range on the segment (use 1)curveTension
- the curve tension- Returns:
- the length of the segment
-
getBezierP1toP2Length
Compute the length on a Bezier spline between control points 1 and 2.- Parameters:
p0
- control point 0p1
- control point 1p2
- control point 2p3
- control point 3- Returns:
- the length of the segment
-
acos
public static float acos(float fValue) Returns the arc cosine of a value.
Special cases:- If fValue is smaller than -1, then the result is PI.
- If the argument is greater than 1, then the result is 0.
- Parameters:
fValue
- The value to arc cosine.- Returns:
- The angle, in radians.
- See Also:
-
asin
public static float asin(float fValue) Returns the arc sine of a value.
Special cases:- If fValue is smaller than -1, then the result is -HALF_PI.
- If the argument is greater than 1, then the result is HALF_PI.
- Parameters:
fValue
- The value to arc sine.- Returns:
- the angle in radians.
- See Also:
-
atan
public static float atan(float fValue) Returns the arc tangent of an angle given in radians.- Parameters:
fValue
- The angle, in radians.- Returns:
- fValue's atan
- See Also:
-
atan2
public static float atan2(float fY, float fX) A direct call to Math.atan2.- Parameters:
fY
- ordinatefX
- abscissa- Returns:
- Math.atan2(fY,fX)
- See Also:
-
ceil
public static float ceil(float fValue) Rounds a fValue up. A call to Math.ceil- Parameters:
fValue
- The value.- Returns:
- The fValue rounded up
- See Also:
-
cos
public static float cos(float v) Returns cosine of an angle. Direct call to java.lang.Math- Parameters:
v
- The angle to cosine.- Returns:
- the cosine of the angle.
- See Also:
-
sin
public static float sin(float v) Returns the sine of an angle. Direct call to java.lang.Math- Parameters:
v
- The angle to sine.- Returns:
- the sine of the angle.
- See Also:
-
exp
public static float exp(float fValue) Returns E^fValue- Parameters:
fValue
- Value to raise to a power.- Returns:
- The value E^fValue
- See Also:
-
abs
public static float abs(float fValue) Returns Absolute value of a float.- Parameters:
fValue
- The value to abs.- Returns:
- The abs of the value.
- See Also:
-
floor
public static float floor(float fValue) Returns a number rounded down.- Parameters:
fValue
- The value to round- Returns:
- The given number rounded down
- See Also:
-
invSqrt
public static float invSqrt(float fValue) Returns 1/sqrt(fValue)- Parameters:
fValue
- The value to process.- Returns:
- 1/sqrt(fValue)
- See Also:
-
fastInvSqrt
public static float fastInvSqrt(float x) Quickly estimate 1/sqrt(fValue).- Parameters:
x
- the input value (≥0)- Returns:
- an approximate value for 1/sqrt(x)
-
log
public static float log(float fValue) Returns the log base E of a value.- Parameters:
fValue
- The value to log.- Returns:
- The log of fValue base E
- See Also:
-
log
public static float log(float value, float base) Returns the logarithm of value with given base, calculated as log(value)/log(base), so that pow(base, return)==value (contributed by vear)- Parameters:
value
- The value to log.base
- Base of logarithm.- Returns:
- The logarithm of value with given base
-
pow
public static float pow(float fBase, float fExponent) Returns a number raised to an exponent power. fBase^fExponent- Parameters:
fBase
- The base value (IE 2)fExponent
- The exponent value (IE 3)- Returns:
- base raised to exponent (IE 8)
- See Also:
-
sqr
public static float sqr(float fValue) Returns the value squared. fValue ^ 2- Parameters:
fValue
- The value to square.- Returns:
- The square of the given value.
-
sqrt
public static float sqrt(float fValue) Returns the square root of a given value.- Parameters:
fValue
- The value to sqrt.- Returns:
- The square root of the given value.
- See Also:
-
tan
public static float tan(float fValue) Returns the tangent of the specified angle.- Parameters:
fValue
- The value to tangent, in radians.- Returns:
- The tangent of fValue.
- See Also:
-
sign
public static int sign(int iValue) Returns 1 if the number is positive, -1 if the number is negative, and 0 otherwise- Parameters:
iValue
- The integer to examine.- Returns:
- The integer's sign.
-
sign
public static float sign(float fValue) Returns 1 if the number is positive, -1 if the number is negative, and 0 otherwise- Parameters:
fValue
- The float to examine.- Returns:
- The float's sign.
-
counterClockwise
Given 3 points in a 2d plane, this function computes if the points going from A-B-C are moving counter clock wise.- Parameters:
p0
- Point 0.p1
- Point 1.p2
- Point 2.- Returns:
- 1 If they are CCW, -1 if they are not CCW, 0 if p2 is between p0 and p1.
-
pointInsideTriangle
Test if a point is inside a triangle. 1 if the point is on the ccw side, -1 if the point is on the cw side, and 0 if it is on neither.- Parameters:
t0
- First point of the triangle.t1
- Second point of the triangle.t2
- Third point of the triangle.p
- The point to test.- Returns:
- Value 1 or -1 if inside triangle, 0 otherwise.
-
computeNormal
A method that computes normal for a triangle defined by three vertices.- Parameters:
v1
- first vertexv2
- second vertexv3
- third vertex- Returns:
- a normal for the face
-
determinant
public static float determinant(double m00, double m01, double m02, double m03, double m10, double m11, double m12, double m13, double m20, double m21, double m22, double m23, double m30, double m31, double m32, double m33) Returns the determinant of a 4x4 matrix.- Parameters:
m00
- the element in row 0, column 0 of the matrixm01
- the element in row 0, column 1 of the matrixm02
- the element in row 0, column 2 of the matrixm03
- the element in row 0, column 3 of the matrixm10
- the element in row 1, column 0 of the matrixm11
- the element in row 1, column 1 of the matrixm12
- the element in row 1, column 2 of the matrixm13
- the element in row 1, column 3 of the matrixm20
- the element in row 2, column 0 of the matrixm21
- the element in row 2, column 1 of the matrixm22
- the element in row 2, column 2 of the matrixm23
- the element in row 2, column 3 of the matrixm30
- the element in row 3, column 0 of the matrixm31
- the element in row 3, column 1 of the matrixm32
- the element in row 3, column 2 of the matrixm33
- the element in row 3, column 3 of the matrix- Returns:
- the determinant
-
nextRandomFloat
public static float nextRandomFloat()Returns a random float between 0 and 1.- Returns:
- a random float between 0 (inclusive) and 1 (exclusive)
-
nextRandomInt
public static int nextRandomInt(int min, int max) Returns a random integer between min and max.- Parameters:
min
- the desired minimum valuemax
- the desired maximum value- Returns:
- a random int between min (inclusive) and max (inclusive)
-
nextRandomInt
public static int nextRandomInt()Choose a pseudo-random, uniformly-distributed integer value from the shared generator.- Returns:
- the next integer value
-
sphericalToCartesian
Converts a point from Spherical coordinates to Cartesian (using positive Y as up) and stores the results in the store var.- Parameters:
sphereCoords
- the input spherical coordinates: x=distance from origin, y=longitude in radians, z=latitude in radians (not null, unaffected)store
- storage for the result (modified if not null)- Returns:
- the Cartesian coordinates (either store or a new vector)
-
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 input Cartesian coordinates (not null, unaffected)store
- storage for the result (modified if not null)- Returns:
- the Cartesian coordinates: x=distance from origin, y=longitude in radians, z=latitude in radians (either store or a new vector)
-
sphericalToCartesianZ
Converts a point from Spherical coordinates to Cartesian (using positive Z as up) and stores the results in the store var.- Parameters:
sphereCoords
- the input spherical coordinates: x=distance from origin, y=latitude in radians, z=longitude in radians (not null, unaffected)store
- storage for the result (modified if not null)- Returns:
- the Cartesian coordinates (either store or a new vector)
-
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 input Cartesian coordinates (not null, unaffected)store
- storage for the result (modified if not null)- Returns:
- the Cartesian coordinates: x=distance from origin, y=latitude in radians, z=longitude in radians (either store or a new vector)
-
normalize
public static float normalize(float val, float min, float max) Takes a value and expresses it in terms of min to max.- Parameters:
val
- - the angle to normalize (in radians)min
- the lower limit of the rangemax
- the upper limit of the range- Returns:
- the normalized angle (also in radians)
-
copysign
public static float copysign(float x, float y) - Parameters:
x
- the value whose sign is to be adjusted.y
- the value whose sign is to be used.- Returns:
- x with its sign changed to match the sign of y.
-
clamp
public static float clamp(float input, float min, float max) Take a float input and clamp it between min and max.- Parameters:
input
- the value to be clampedmin
- the minimum output valuemax
- the maximum output value- Returns:
- clamped input
-
saturate
public static float saturate(float input) Clamps the given float to be between 0 and 1.- Parameters:
input
- the value to be clamped- Returns:
- input clamped between 0 and 1.
-
approximateEquals
public static boolean approximateEquals(float a, float b) Determine if two floats are approximately equal. This takes into account the magnitude of the floats, since large numbers will have larger differences be close to each other. Should return true for a=100000, b=100001, but false for a=10000, b=10001.- Parameters:
a
- The first float to compareb
- The second float to compare- Returns:
- True if a and b are approximately equal, false otherwise.
-
convertHalfToFloat
public static float convertHalfToFloat(short half) Converts a single precision (32 bit) floating point value into half precision (16 bit).Source: ftp://www.fox-toolkit.org/pub/fasthalffloatconversion.pdf
- Parameters:
half
- The half floating point value as a short.- Returns:
- floating point value of the half.
-
convertFloatToHalf
public static short convertFloatToHalf(float flt) Convert a single-precision (32-bit) floating-point value to half precision.- Parameters:
flt
- the input value (not a NaN)- Returns:
- a near-equivalent value in half precision
- Throws:
UnsupportedOperationException
- if flt is a NaN
-
unInterpolateLinear
public static float unInterpolateLinear(float value, float min, float max) Converts a range of min/max to a 0-1 range.- Parameters:
value
- the value between min-max (inclusive).min
- the minimum of the range.max
- the maximum of the range.- Returns:
- A value between 0-1 if the given value is between min/max.
-