Class MyMath
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic double
Return the (one-sided) area of the specified triangle.static double
circle
(double abscissa) Return the circle functionsqrt(1 - x^2)
for a double-precision value.static float
circle
(float abscissa) Return the circle functionsqrt(1 - x^2)
for a single-precision value.static double
clamp
(double dValue, double min, double max) Clamp a double-precision value between 2 limits.static int
clamp
(int iValue, int min, int max) Clamp an integer value between 2 limits.static Transform
Combine the specified transforms.static float
cube
(float fValue) Cube the specified single-precision value.static Matrix3f
fromAngles
(float xAngle, float yAngle, float zAngle, Matrix3f storeResult) Sets a rotation matrix from the specified Tait-Bryan angles, applying the rotations in x-z-y extrinsic order or y-z'-x" intrinsic order.static float
hypotenuse
(float... fValues) Return the root sum of squares of some single-precision values.static double
hypotenuseDouble
(double... dValues) Return the root sum of squares of some double-precision values.static boolean
isBetween
(float a, float b, float c) Test whether b is between a and c.static boolean
isFinite
(float value) Test whether the specified floating-point value is finite.static boolean
isFiniteDouble
(double value) Test whether the specified floating-point value is finite.static boolean
isIdentity
(Transform transform) Test the specified transform for exact identity.static boolean
isOdd
(int iValue) Test whether an integer value is odd.static float
lerp
(float t, float y0, float y1) Interpolate linearly between (or extrapolate linearly from) 2 single-precision values.static int
log2
(int iValue) Calculate the floor of the base-2 logarithm of the input value.static float
max
(float... fValues) Find the maximum of some single-precision values.static int
maxInt
(int... iValues) Find the maximum of some int values.static float
mid
(float a, float b, float c) Find the median of 3 single-precision values.static float
min
(float... fValues) Find the minimum of some single-precision values.static float
modulo
(float fValue, float modulus) Return the least non-negative value congruent with the input value with respect to the specified modulus.static int
modulo
(int iValue, int modulus) Return the least non-negative value congruent with the input value with respect to the specified modulus.static float
standardize
(float fValue) Standardize a single-precision value in preparation for hashing.static float
standardizeAngle
(float angle) Standardize a rotation angle to the range [-Pi, Pi).static double
sumOfSquares
(float... fValues) Return the sum of squares of some single-precision values.static float
toDegrees
(float radians) Convert an angle from radians to degrees.static float
toRadians
(float degrees) Convert an angle from degrees to radians.static Vector3f
Apply the specified transform to a Vector3f.static Triangle
transformInverse
(Transform transform, Triangle input, Triangle storeResult) Apply the inverse of the specified transform to each vertex of a Triangle.static Vector3f
transformInverse
(Transform transform, Vector3f input, Vector3f storeResult) Apply the inverse of the specified transform to a Vector3f.
-
Field Details
-
phi
public static final float phigolden ratio = 1.618... -
root2
public static final float root2square root of 2 -
rootHalf
public static final float rootHalfsquare root of 1/2 -
logger
message logger for this class
-
-
Method Details
-
area
Return the (one-sided) area of the specified triangle.- Parameters:
triangle
- (not null, unaffected)- Returns:
- the area (≥0)
-
circle
public static double circle(double abscissa) Return the circle functionsqrt(1 - x^2)
for a double-precision value.- Parameters:
abscissa
- input (≤1, ≥-1)- Returns:
- positive ordinate of the unit circle at the abscissa (≤1, ≥0)
-
circle
public static float circle(float abscissa) Return the circle functionsqrt(1 - x^2)
for a single-precision value. Double-precision arithmetic is used to reduce the risk of overflow.- Parameters:
abscissa
- input (≤1, ≥-1)- Returns:
- positive ordinate of the unit circle at the abscissa (≤1, ≥0)
-
clamp
public static double clamp(double dValue, double min, double max) Clamp a double-precision value between 2 limits.- Parameters:
dValue
- input value to be clampedmin
- lower limit of the clampmax
- upper limit of the clamp- Returns:
- the value between min and max inclusive that is closest to fValue
- See Also:
-
clamp
public static int clamp(int iValue, int min, int max) Clamp an integer value between 2 limits.- Parameters:
iValue
- input value to be clampedmin
- the lower limitmax
- the upper limit- Returns:
- the value between min and max inclusive that is closest to iValue
-
combine
Combine the specified transforms.It is safe for any or all of
child
,parent
, andstoreResult
to be the same object.This method works on transforms containing non-normalized quaternions.
- Parameters:
child
- the transform applied first (not null, unaffected unless it'sstoreResult
)parent
- the transform applied last (not null, unaffected unless it'sstoreResult
)storeResult
- (modified if not null)- Returns:
- a Transform equivalent to
child
followed byparent
(eitherstoreResult
or a new instance)
-
cube
public static float cube(float fValue) Cube the specified single-precision value. Logs a warning in case of overflow.- Parameters:
fValue
- input value to be cubed- Returns:
- fValue raised to the third power
-
fromAngles
Sets a rotation matrix from the specified Tait-Bryan angles, applying the rotations in x-z-y extrinsic order or y-z'-x" intrinsic order.- Parameters:
xAngle
- the X angle (in radians)yAngle
- the Y angle (in radians)zAngle
- the Z angle (in radians)storeResult
- storage for the result (modified if not null)- Returns:
- a rotation matrix (either
storeResult
or a new instance)
-
hypotenuse
public static float hypotenuse(float... fValues) Return the root sum of squares of some single-precision values. Double-precision arithmetic is used to reduce the risk of overflow.- Parameters:
fValues
- the input values- Returns:
- the positive square root of the sum of squares (≥0)
-
hypotenuseDouble
public static double hypotenuseDouble(double... dValues) Return the root sum of squares of some double-precision values.- Parameters:
dValues
- the input values- Returns:
- the positive square root of the sum of squares (≥0)
-
isBetween
public static boolean isBetween(float a, float b, float c) Test whether b is between a and c.- Parameters:
a
- the first input valueb
- the 2nd input valuec
- the 3rd input value- Returns:
- true if b is between a and c (inclusive), otherwise false
-
isFinite
public static boolean isFinite(float value) Test whether the specified floating-point value is finite. Note that Java 8 providesFloat.isFinite(float)
.- Parameters:
value
- the value to test- Returns:
- true if finite, false if NaN or infinity
-
isFiniteDouble
public static boolean isFiniteDouble(double value) Test whether the specified floating-point value is finite. Note that Java 8 providesDouble.isFinite(double)
.- Parameters:
value
- the value to test- Returns:
- true if finite, false if NaN or infinity
-
isIdentity
Test the specified transform for exact identity.- Parameters:
transform
- which transform to test (not null, unaffected)- Returns:
- true if exact identity, otherwise false
-
isOdd
public static boolean isOdd(int iValue) Test whether an integer value is odd.- Parameters:
iValue
- the value to be tested- Returns:
- true if x is odd, false if it's even
-
lerp
public static float lerp(float t, float y0, float y1) Interpolate linearly between (or extrapolate linearly from) 2 single-precision values.No rounding error is introduced when y0==y1.
- Parameters:
t
- the weight given toy1
y0
- the function value at t=0y1
- the function value at t=1- Returns:
- the interpolated function value
-
log2
public static int log2(int iValue) Calculate the floor of the base-2 logarithm of the input value.- Parameters:
iValue
- the input value (≥1)- Returns:
- the largest integer N≤30 for which
(1 << N) <= iValue
(≥0, ≤30)
-
max
public static float max(float... fValues) Find the maximum of some single-precision values.- Parameters:
fValues
- the input values- Returns:
- the most positive value
- See Also:
-
maxInt
public static int maxInt(int... iValues) Find the maximum of some int values.- Parameters:
iValues
- the input values- Returns:
- the most positive value
- See Also:
-
mid
public static float mid(float a, float b, float c) Find the median of 3 single-precision values.- Parameters:
a
- the first input valueb
- the 2nd input valuec
- the 3rd input value- Returns:
- the median of the 3 values
-
min
public static float min(float... fValues) Find the minimum of some single-precision values.- Parameters:
fValues
- the input values- Returns:
- the most negative value
- See Also:
-
modulo
public static int modulo(int iValue, int modulus) Return the least non-negative value congruent with the input value with respect to the specified modulus.This differs from remainder for negative input values. For instance, modulo(-1, 4) == 3, while -1 % 4 == -1.
- Parameters:
iValue
- the input valuemodulus
- (>0)- Returns:
- iValue MOD modulus (<modulus, ≥0)
-
modulo
public static float modulo(float fValue, float modulus) Return the least non-negative value congruent with the input value with respect to the specified modulus.This differs from remainder for negative input values. For instance, modulo(-1f, 4f) == 3f, while -1f % 4f == -1f.
- Parameters:
fValue
- the input valuemodulus
- (>0)- Returns:
- fValue MOD modulus (<modulus, ≥0)
-
standardize
public static float standardize(float fValue) Standardize a single-precision value in preparation for hashing.- Parameters:
fValue
- input value- Returns:
- an equivalent value that's not -0
-
standardizeAngle
public static float standardizeAngle(float angle) Standardize a rotation angle to the range [-Pi, Pi).- Parameters:
angle
- the input angle (in radians)- Returns:
- the standardized angle (in radians, <Pi, ≥-Pi)
-
sumOfSquares
public static double sumOfSquares(float... fValues) Return the sum of squares of some single-precision values. Double-precision arithmetic is used to reduce the risk of overflow.- Parameters:
fValues
- the input values- Returns:
- the sum of squares (≥0)
-
toDegrees
public static float toDegrees(float radians) Convert an angle from radians to degrees.- Parameters:
radians
- input angle- Returns:
- equivalent in degrees
- See Also:
-
toRadians
public static float toRadians(float degrees) Convert an angle from degrees to radians.- Parameters:
degrees
- input angle- Returns:
- equivalent in radians
- See Also:
-
transform
Apply the specified transform to a Vector3f.It is safe for
input
andstoreResult
to be the same object.This method works on transforms containing non-normalized quaternions.
- Parameters:
transform
- the transform to apply (not null, unaffected unlessstoreResult
is its translation or scaling component)input
- the input vector (not null, unaffected unless it'sstoreResult
)storeResult
- storage for the result (modified if not null)- Returns:
- the transformed vector (either
storeResult
or a new instance)
-
transformInverse
Apply the inverse of the specified transform to each vertex of a Triangle.It is safe for
input
andstoreResult
to be the same object.- Parameters:
transform
- the transform to apply (not null, unaffected)input
- the input triangle (not null, unaffected unless it'sstoreResult
)storeResult
- storage for the result (modified if not null)- Returns:
- the transformed triangle (either
storeResult
or a new instance)
-
transformInverse
Apply the inverse of the specified transform to a Vector3f.It is safe for
input
andstoreResult
to be the same object.This method works on transforms containing non-normalized quaternions.
- Parameters:
transform
- the transform to un-apply (not null, unaffected unlessstoreResult
is its translation or scaling component)input
- the input vector (not null, unaffected unless it'sstoreResult
)storeResult
- storage for the result (modified if not null)- Returns:
- the transformed vector (either
storeResult
or a new instance)
-