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 SummaryFieldsModifier and TypeFieldDescriptionstatic final doubleA "close to zero" double epsilon value for usestatic final floatA value to multiply a degree value by, to convert it to radians.static final floatA "close to zero" float epsilon value for usestatic final floatThe value PI/2 as a float.static final floatThe value 1/PI as a float.static final floatThe value 1/(2PI) as a float.static final floatThe value 1/3, as a float.static final floatThe value PI as a float.static final floatThe value PI/4 as a float.static final floatA value to multiply a radian value by, to convert it to degrees.static final RandomA precreated random object for random numbers.static final floatThe value 2PI as a float.static final floatA "close to zero" float epsilon value for use
- 
Method SummaryModifier and TypeMethodDescriptionstatic floatabs(float fValue) Returns Absolute value of a float.static floatacos(float fValue) Returns the arc cosine of a value.
 Special cases: If fValue is smaller than -1, then the result is PI.static booleanapproximateEquals(float a, float b) Determine if two floats are approximately equal.static floatasin(float fValue) Returns the arc sine of a value.
 Special cases: If fValue is smaller than -1, then the result is -HALF_PI.static floatatan(float fValue) Returns the arc tangent of an angle given in radians.static floatatan2(float fY, float fX) A direct call to Math.atan2.static Vector3fcartesianToSpherical(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 Vector3fcartesianZToSpherical(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 floatceil(float fValue) Rounds a fValue up.static floatclamp(float input, float min, float max) Take a float input and clamp it between min and max.static Vector3fcomputeNormal(Vector3f v1, Vector3f v2, Vector3f v3) A method that computes normal for a triangle defined by three vertices.static shortconvertFloatToHalf(float flt) Convert a single-precision (32-bit) floating-point value to half precision.static floatconvertHalfToFloat(short half) Converts a single precision (32 bit) floating point value into half precision (16 bit).static floatcopysign(float x, float y) static floatcos(float v) Returns cosine of an angle.static intcounterClockwise(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 floatdeterminant(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 floatexp(float fValue) Returns E^fValuestatic floatextrapolateLinear(float scale, float startValue, float endValue) Linear extrapolation from startValue to endValue by the given scale.static Vector3fextrapolateLinear(float scale, Vector3f startValue, Vector3f endValue) Linear extrapolation from startValue to endValue by the given scale.static Vector3fextrapolateLinear(float scale, Vector3f startValue, Vector3f endValue, Vector3f store) Linear extrapolation from startValue to endValue by the given scale.static floatfastInvSqrt(float x) Quickly estimate 1/sqrt(fValue).static floatfloor(float fValue) Returns a number rounded down.static floatgetBezierP1toP2Length(Vector3f p0, Vector3f p1, Vector3f p2, Vector3f p3) Compute the length on a Bezier spline between control points 1 and 2.static floatgetCatmullRomP1toP2Length(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 Vector2fReturns a random point inside or on a circle with radius 1.0.static Vector3fReturns a random point inside or on a sphere with radius 1.0 This method uses spherical coordinates combined with a cubed-root radius.static floatinterpolateBezier(float u, float p0, float p1, float p2, float p3) Interpolate a spline between at least 4 control points following the Bezier equation.static Vector3finterpolateBezier(float u, Vector3f p0, Vector3f p1, Vector3f p2, Vector3f p3) Interpolate a spline between at least 4 control points following the Bezier equation.static Vector3fInterpolate a spline between at least 4 control points following the Bezier equation.static floatinterpolateCatmullRom(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 Vector3finterpolateCatmullRom(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 Vector3finterpolateCatmullRom(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 floatinterpolateLinear(float scale, float startValue, float endValue) Linear interpolation from startValue to endValue by the given percent.static Vector3finterpolateLinear(float scale, Vector3f startValue, Vector3f endValue) Linear interpolation from startValue to endValue by the given percent.static Vector3finterpolateLinear(float scale, Vector3f startValue, Vector3f endValue, Vector3f store) Linear interpolation from startValue to endValue by the given percent.static floatinvSqrt(float fValue) Returns 1/sqrt(fValue)static booleanisPowerOfTwo(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 floatlog(float fValue) Returns the log base E of a value.static floatlog(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 intnearestPowerOfTwo(int number) Get the next power of two of the given number.static floatGenerates a pseudorandomfloatin the range [0.0, 1.0).static floatnextRandomFloat(float min, float max) Generates a pseudorandomfloatin the range [min, max)static intGenerates a pseudorandom, uniformly-distributedintvalue.static intnextRandomInt(int min, int max) Generates a pseudorandomintin the range [min, max] (inclusive).static floatnormalize(float val, float min, float max) Takes a value and expresses it in terms of min to max.static Vector3fReturns a random point on the surface of a sphere with radius 1.0static intpointInsideTriangle(Vector2f t0, Vector2f t1, Vector2f t2, Vector2f p) Test if a point is inside a triangle.static floatpow(float fBase, float fExponent) Returns a number raised to an exponent power.static floatsaturate(float input) Clamps the given float to be between 0 and 1.static floatsign(float fValue) Returns 1 if the number is positive, -1 if the number is negative, and 0 otherwisestatic intsign(int iValue) Returns 1 if the number is positive, -1 if the number is negative, and 0 otherwisestatic floatsin(float v) Returns the sine of an angle.static Vector3fsphericalToCartesian(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 Vector3fsphericalToCartesianZ(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 floatsqr(float fValue) Returns the value squared.static floatsqrt(float fValue) Returns the square root of a given value.static floattan(float fValue) Returns the tangent of the specified angle.static inttoMultipleOf(int n, int p) Round n to a multiple of pstatic floatunInterpolateLinear(float value, float min, float max) Converts a range of min/max to a 0-1 range.
- 
Field Details- 
DBL_EPSILONpublic static final double DBL_EPSILONA "close to zero" double epsilon value for use- See Also:
 
- 
FLT_EPSILONpublic static final float FLT_EPSILONA "close to zero" float epsilon value for use- See Also:
 
- 
ZERO_TOLERANCEpublic static final float ZERO_TOLERANCEA "close to zero" float epsilon value for use- See Also:
 
- 
ONE_THIRDpublic static final float ONE_THIRDThe value 1/3, as a float.- See Also:
 
- 
PIpublic static final float PIThe value PI as a float. (180 degrees)- See Also:
 
- 
TWO_PIpublic static final float TWO_PIThe value 2PI as a float. (360 degrees)- See Also:
 
- 
HALF_PIpublic static final float HALF_PIThe value PI/2 as a float. (90 degrees)- See Also:
 
- 
QUARTER_PIpublic static final float QUARTER_PIThe value PI/4 as a float. (45 degrees)- See Also:
 
- 
INV_PIpublic static final float INV_PIThe value 1/PI as a float.- See Also:
 
- 
INV_TWO_PIpublic static final float INV_TWO_PIThe value 1/(2PI) as a float.- See Also:
 
- 
DEG_TO_RADpublic static final float DEG_TO_RADA value to multiply a degree value by, to convert it to radians.- See Also:
 
- 
RAD_TO_DEGpublic static final float RAD_TO_DEGA value to multiply a radian value by, to convert it to degrees.- See Also:
 
- 
randA precreated random object for random numbers.
 
- 
- 
Method Details- 
isPowerOfTwopublic 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.
 
- 
nearestPowerOfTwopublic 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.
 
- 
interpolateLinearpublic 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 f
- endValue- ending value. 100% of f
- Returns:
- The interpolated value between startValue and endValue.
 
- 
interpolateLinearpublic 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 f
- endValue- ending value. 100% of f
- store- a vector3f to store the result
- Returns:
- The interpolated value between startValue and endValue.
 
- 
interpolateLinearLinear 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 f
- endValue- ending value. 100% of f
- Returns:
- The interpolated value between startValue and endValue.
 
- 
extrapolateLinearpublic 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 extrapolation
- startValue- the starting value (scale = 0)
- endValue- the end value (scale = 1)
- Returns:
- an extrapolation for the given parameters
 
- 
extrapolateLinearpublic 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 extrapolation
- startValue- 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
 
- 
extrapolateLinearLinear 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 extrapolation
- startValue- the starting value (scale = 0)
- endValue- the end value (scale = 1)
- Returns:
- an extrapolation for the given parameters
 
- 
interpolateCatmullRompublic 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 1
- T- The tension of the curve
- p0- control point 0
- p1- control point 1
- p2- control point 2
- p3- control point 3
- Returns:
- Catmull–Rom interpolation
 
- 
interpolateCatmullRompublic 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 1
- T- The tension of the curve
- p0- control point 0
- p1- control point 1
- p2- control point 2
- p3- control point 3
- store- a Vector3f to store the result
- Returns:
- Catmull–Rom interpolation
 
- 
interpolateCatmullRompublic 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 1
- T- The tension of the curve
- p0- control point 0
- p1- control point 1
- p2- control point 2
- p3- control point 3
- Returns:
- Catmull–Rom interpolation
 
- 
interpolateBezierpublic 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 1
- p0- control point 0
- p1- control point 1
- p2- control point 2
- p3- control point 3
- Returns:
- Bezier interpolation
 
- 
interpolateBezierpublic 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 1
- p0- control point 0
- p1- control point 1
- p2- control point 2
- p3- control point 3
- store- a Vector3f to store the result
- Returns:
- Bezier interpolation
 
- 
interpolateBezierpublic 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 1
- p0- control point 0
- p1- control point 1
- p2- control point 2
- p3- control point 3
- Returns:
- Bezier interpolation
 
- 
getCatmullRomP1toP2Lengthpublic 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 0
- p1- control point 1
- p2- control point 2
- p3- control point 3
- startRange- 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
 
- 
getBezierP1toP2LengthCompute the length on a Bezier spline between control points 1 and 2.- Parameters:
- p0- control point 0
- p1- control point 1
- p2- control point 2
- p3- control point 3
- Returns:
- the length of the segment
 
- 
acospublic 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:
 
- 
asinpublic 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:
 
- 
atanpublic 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:
 
- 
atan2public static float atan2(float fY, float fX) A direct call to Math.atan2.- Parameters:
- fY- ordinate
- fX- abscissa
- Returns:
- Math.atan2(fY,fX)
- See Also:
 
- 
ceilpublic 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:
 
- 
cospublic 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:
 
- 
sinpublic 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:
 
- 
exppublic static float exp(float fValue) Returns E^fValue- Parameters:
- fValue- Value to raise to a power.
- Returns:
- The value E^fValue
- See Also:
 
- 
abspublic 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:
 
- 
floorpublic static float floor(float fValue) Returns a number rounded down.- Parameters:
- fValue- The value to round
- Returns:
- The given number rounded down
- See Also:
 
- 
invSqrtpublic static float invSqrt(float fValue) Returns 1/sqrt(fValue)- Parameters:
- fValue- The value to process.
- Returns:
- 1/sqrt(fValue)
- See Also:
 
- 
fastInvSqrtpublic static float fastInvSqrt(float x) Quickly estimate 1/sqrt(fValue).- Parameters:
- x- the input value (≥0)
- Returns:
- an approximate value for 1/sqrt(x)
 
- 
logpublic 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:
 
- 
logpublic 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
 
- 
powpublic 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:
 
- 
sqrpublic static float sqr(float fValue) Returns the value squared. fValue ^ 2- Parameters:
- fValue- The value to square.
- Returns:
- The square of the given value.
 
- 
sqrtpublic 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:
 
- 
tanpublic 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:
 
- 
signpublic 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.
 
- 
signpublic 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.
 
- 
counterClockwiseGiven 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.
 
- 
pointInsideTriangleTest 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.
 
- 
computeNormalA method that computes normal for a triangle defined by three vertices.- Parameters:
- v1- first vertex
- v2- second vertex
- v3- third vertex
- Returns:
- a normal for the face
 
- 
determinantpublic 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 matrix
- m01- the element in row 0, column 1 of the matrix
- m02- the element in row 0, column 2 of the matrix
- m03- the element in row 0, column 3 of the matrix
- m10- the element in row 1, column 0 of the matrix
- m11- the element in row 1, column 1 of the matrix
- m12- the element in row 1, column 2 of the matrix
- m13- the element in row 1, column 3 of the matrix
- m20- the element in row 2, column 0 of the matrix
- m21- the element in row 2, column 1 of the matrix
- m22- the element in row 2, column 2 of the matrix
- m23- the element in row 2, column 3 of the matrix
- m30- the element in row 3, column 0 of the matrix
- m31- the element in row 3, column 1 of the matrix
- m32- the element in row 3, column 2 of the matrix
- m33- the element in row 3, column 3 of the matrix
- Returns:
- the determinant
 
- 
nextRandomFloatpublic static float nextRandomFloat()Generates a pseudorandomfloatin the range [0.0, 1.0).- Returns:
- A random floatvalue.
 
- 
nextRandomFloatpublic static float nextRandomFloat(float min, float max) Generates a pseudorandomfloatin the range [min, max)- Parameters:
- min- The lower bound (inclusive).
- max- The upper bound (exclusive).
- Returns:
- A random floatvalue within the specified range.
 
- 
nextRandomIntpublic static int nextRandomInt()Generates a pseudorandom, uniformly-distributedintvalue.- Returns:
- The next pseudorandom intvalue.
 
- 
nextRandomIntpublic static int nextRandomInt(int min, int max) Generates a pseudorandomintin the range [min, max] (inclusive).- Parameters:
- min- The lower bound (inclusive).
- max- The upper bound (inclusive).
- Returns:
- A random intvalue within the specified range.
 
- 
onUnitSphereReturns a random point on the surface of a sphere with radius 1.0- Returns:
- A new Vector3frepresenting a random point on the surface of the unit sphere.
 
- 
insideUnitSphereReturns a random point inside or on a sphere with radius 1.0 This method uses spherical coordinates combined with a cubed-root radius.- Returns:
- A new Vector3frepresenting a random point within the unit sphere.
 
- 
insideUnitCircleReturns a random point inside or on a circle with radius 1.0. This method uses polar coordinates combined with a square-root radius.- Returns:
- A new Vector2frepresenting a random point within the unit circle.
 
- 
sphericalToCartesianConverts 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)
 
- 
cartesianToSphericalConverts 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)
 
- 
sphericalToCartesianZConverts 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)
 
- 
cartesianZToSphericalConverts 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)
 
- 
normalizepublic 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 range
- max- the upper limit of the range
- Returns:
- the normalized angle (also in radians)
 
- 
copysignpublic 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.
 
- 
clamppublic 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 clamped
- min- the minimum output value
- max- the maximum output value
- Returns:
- clamped input
 
- 
saturatepublic 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.
 
- 
approximateEqualspublic 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 compare
- b- The second float to compare
- Returns:
- True if a and b are approximately equal, false otherwise.
 
- 
convertHalfToFloatpublic 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.
 
- 
convertFloatToHalfpublic 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
 
- 
unInterpolateLinearpublic 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.
 
- 
toMultipleOfpublic static int toMultipleOf(int n, int p) Round n to a multiple of p
 
-