- java.lang.Object
-
- org.arakhne.afc.math.MathUtil
-
public final class MathUtil extends Object
Mathematic and geometric utilities.- Version:
- 17.0 2020-01-04 14:41:41
- Author:
- Stéphane GALLAND, Hamza JAFFALI
- Maven Group Id:
- org.arakhne.afc.core
- Maven Artifact Id:
- mathgen
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static doubleclamp(double v, double min, double max)Clamp the given value to the given range.static intclamp(int v, int min, int max)Clamp the given value to the given range.static doubleclampCyclic(double value, double min, double max)Clamp the given value to fit between the min and max values according to a cyclic heuristic.static doubleclampToNearestBounds(double value, double minBounds, double maxBounds)Replies thevalueclamped to the nearest bounds.static intcompareEpsilon(double v1, double v2)Compares its two arguments for order.static intcompareEpsilon(double v1, double v2, double epsilon)Compares its two arguments for order.static doublecot(double angle)Replies the cotangent of the specified angle.static doublecrd(double angle)Replies the chord of the specified angle.static doublecsc(double angle)Replies the cosecant of the specified angle.static doubleexsec(double angle)Replies the exsecant of the specified angle.static intgetCohenSutherlandCode(double px, double py, double rxmin, double rymin, double rxmax, double rymax)Compute the zone where the point is against the given rectangle according to the Cohen-Sutherland algorithm.static intgetCohenSutherlandCode(int px, int py, int rxmin, int rymin, int rxmax, int rymax)Compute the zone where the point is against the given rectangle according to the Cohen-Sutherland algorithm.static intgetCohenSutherlandCode3D(double px, double py, double pz, double rxmin, double rymin, double rzmin, double rxmax, double rymax, double rzmax)Compute the zone where the point is against the given rectangular prism according to the Cohen-Sutherland algorithm.static intgetCohenSutherlandCode3D(int px, int py, int pz, int rxmin, int rymin, int rzmin, int rxmax, int rymax, int rzmax)Compute the zone where the point is against the given rectangular prism according to the Cohen-Sutherland algorithm.static DoubleRangegetMinMax(double value1, double value2, double value3)Determine the min and max values from a set of three values.static doublehaversine(double angle)Replies the half of the versine (aka, haversine) of the specified angle.static booleanisEpsilonEqual(double v1, double v2)Replies if the given values are near.static booleanisEpsilonEqual(double v1, double v2, double epsilon)Replies if the given values are near.static booleanisEpsilonZero(double value)Replies if the given value is near zero.static booleanisEpsilonZero(double value, double epsilon)Replies if the given value is near zero.static doublemax(double... values)Replies the max value.static floatmax(float... values)Replies the max value.static intmax(int... values)Replies the max value.static longmax(long... values)Replies the max value.static shortmax(short... values)Replies the max value.static doublemin(double... values)Replies the min value.static floatmin(float... values)Replies the min value.static intmin(int... values)Replies the min value.static longmin(long... values)Replies the min value.static shortmin(short... values)Replies the min value.static doublesec(double angle)Replies the secant of the specified angle.static intsign(double value)Returns the sign of the argument; zero if the argument is zero, 1 if the argument is greater than zero, -1 if the argument is less than zero.static intsignNoZero(double value)Returns the sign of the argument; 1 if the argument is greater than or equal to zero, -1 if the argument is less than zero.static doubleversin(double angle)Replies the versine of the specified angle.
-
-
-
Method Detail
-
sign
@Pure public static int sign(double value)
Returns the sign of the argument; zero if the argument is zero, 1 if the argument is greater than zero, -1 if the argument is less than zero.This function differs from
Math.signum(double)because it is returning a integer value.If you would like to treat the zero value as a positive number, see
signNoZero(double).- Parameters:
value- the floating-point value whose sign is to be returned- Returns:
- the sign of the argument,
-1,0or1. - See Also:
signNoZero(double),Math.signum(double)
-
signNoZero
@Pure public static int signNoZero(double value)
Returns the sign of the argument; 1 if the argument is greater than or equal to zero, -1 if the argument is less than zero.This function differs from
sign(double)because it assumes the zero value has a positive sign.- Parameters:
value- the floating-point value whose sign is to be returned- Returns:
- the sign of the argument,
-1or1. - Since:
- 16.0
- See Also:
sign(double),Math.signum(double)
-
clamp
@Pure public static double clamp(double v, double min, double max)Clamp the given value to the given range.If the value is outside the
[min;max]range, it is clamp to the nearest bounding valueminormax.- Parameters:
v- is the value to clamp.min- is the min value of the range.max- is the max value of the range.- Returns:
- the value in
[min;max]range.
-
clamp
@Pure public static int clamp(int v, int min, int max)Clamp the given value to the given range.If the value is outside the
[min;max]range, it is clamp to the nearest bounding valueminormax.- Parameters:
v- is the value to clamp.min- is the min value of the range.max- is the max value of the range.- Returns:
- the value in
[min;max]range.
-
isEpsilonZero
@Pure public static boolean isEpsilonZero(double value)
Replies if the given value is near zero.- Parameters:
value- is the value to test.- Returns:
trueif the givenvalueis near zero, otherwisefalse.- See Also:
Math.ulp(double)
-
isEpsilonZero
@Pure public static boolean isEpsilonZero(double value, double epsilon)Replies if the given value is near zero.- Parameters:
value- is the value to test.epsilon- the approximation epsilon. IfDouble.NaN, the functionMath.ulp(double)is used for evaluating the epsilon.- Returns:
trueif the givenvalueis near zero, otherwisefalse.
-
isEpsilonEqual
@Pure public static boolean isEpsilonEqual(double v1, double v2)Replies if the given values are near.- Parameters:
v1- first value.v2- second value.- Returns:
trueif the givenv1is nearv2, otherwisefalse.- See Also:
Math.ulp(double)
-
isEpsilonEqual
@Pure public static boolean isEpsilonEqual(double v1, double v2, double epsilon)Replies if the given values are near.- Parameters:
v1- first value.v2- second value.epsilon- the approximation epsilon. IfDouble.NaN, the functionMath.ulp(double)is used for evaluating the epsilon.- Returns:
trueif the givenv1is nearv2, otherwisefalse.
-
compareEpsilon
@Pure public static int compareEpsilon(double v1, double v2)Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.- Parameters:
v1- first value.v2- second value.- Returns:
- a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
-
compareEpsilon
@Pure public static int compareEpsilon(double v1, double v2, double epsilon)Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.- Parameters:
v1- first value.v2- second value.epsilon- approximation epsilon. IfDouble.NaN, the functionMath.ulp(double)is used for evaluating the epsilon.- Returns:
- a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
-
max
@Pure public static double max(double... values)
Replies the max value.- Parameters:
values- are the values to scan.- Returns:
- the max value.
-
max
@Pure public static float max(float... values)
Replies the max value.- Parameters:
values- are the values to scan.- Returns:
- the max value.
-
max
@Pure public static int max(int... values)
Replies the max value.- Parameters:
values- are the values to scan.- Returns:
- the max value.
-
max
@Pure public static long max(long... values)
Replies the max value.- Parameters:
values- are the values to scan.- Returns:
- the max value.
-
max
@Pure public static short max(short... values)
Replies the max value.- Parameters:
values- are the values to scan.- Returns:
- the max value.
-
min
@Pure public static double min(double... values)
Replies the min value.- Parameters:
values- are the values to scan.- Returns:
- the min value.
-
min
@Pure public static float min(float... values)
Replies the min value.- Parameters:
values- are the values to scan.- Returns:
- the min value.
-
min
@Pure public static int min(int... values)
Replies the min value.- Parameters:
values- are the values to scan.- Returns:
- the min value.
-
min
@Pure public static long min(long... values)
Replies the min value.- Parameters:
values- are the values to scan.- Returns:
- the min value.
-
min
@Pure public static short min(short... values)
Replies the min value.- Parameters:
values- are the values to scan.- Returns:
- the min value.
-
clampCyclic
@Pure public static double clampCyclic(double value, double min, double max)Clamp the given value to fit between the min and max values according to a cyclic heuristic. If the given value is not between the minimum and maximum values, the replied value is modulo the min-max range.- Parameters:
value- the value to clamp.min- the minimum value inclusive.max- the maximum value exclusive.- Returns:
- the clamped value
-
clampToNearestBounds
@Pure public static double clampToNearestBounds(double value, double minBounds, double maxBounds)Replies thevalueclamped to the nearest bounds. If |value-minBounds| > |value-maxBounds| then the returned value ismaxBounds; otherwise it isminBounds.- Parameters:
value- is the value to clamp.minBounds- is the minimal allowed value.maxBounds- is the maximal allowed value.- Returns:
minBoundsormaxBounds.
-
getCohenSutherlandCode
@Pure public static int getCohenSutherlandCode(int px, int py, int rxmin, int rymin, int rxmax, int rymax)Compute the zone where the point is against the given rectangle according to the Cohen-Sutherland algorithm.- Parameters:
px- is the coordinates of the points.py- is the coordinates of the points.rxmin- is the min of the coordinates of the rectangle.rymin- is the min of the coordinates of the rectangle.rxmax- is the max of the coordinates of the rectangle.rymax- is the max of the coordinates of the rectangle.- Returns:
- the zone
- See Also:
MathConstants.COHEN_SUTHERLAND_BOTTOM,MathConstants.COHEN_SUTHERLAND_TOP,MathConstants.COHEN_SUTHERLAND_LEFT,MathConstants.COHEN_SUTHERLAND_RIGHT,MathConstants.COHEN_SUTHERLAND_INSIDE
-
getCohenSutherlandCode
@Pure public static int getCohenSutherlandCode(double px, double py, double rxmin, double rymin, double rxmax, double rymax)Compute the zone where the point is against the given rectangle according to the Cohen-Sutherland algorithm.This function considers that if a point coordinate is equal to the a border coordinate of the rectangle, it is inside the rectangle.
- Parameters:
px- is the coordinates of the points.py- is the coordinates of the points.rxmin- is the min of the coordinates of the rectangle.rymin- is the min of the coordinates of the rectangle.rxmax- is the max of the coordinates of the rectangle.rymax- is the max of the coordinates of the rectangle.- Returns:
- the zone
- See Also:
MathConstants.COHEN_SUTHERLAND_BOTTOM,MathConstants.COHEN_SUTHERLAND_TOP,MathConstants.COHEN_SUTHERLAND_LEFT,MathConstants.COHEN_SUTHERLAND_RIGHT,MathConstants.COHEN_SUTHERLAND_INSIDE
-
getCohenSutherlandCode3D
@Pure public static int getCohenSutherlandCode3D(int px, int py, int pz, int rxmin, int rymin, int rzmin, int rxmax, int rymax, int rzmax)Compute the zone where the point is against the given rectangular prism according to the Cohen-Sutherland algorithm.- Parameters:
px- is the coordinates of the point.py- is the coordinates of the point.pz- is the coordinates of the point.rxmin- is the min of the coordinates of the rectangular prism.rymin- is the min of the coordinates of the rectangular prism.rzmin- is the min of the coordinates of the rectangular prism.rxmax- is the max of the coordinates of the rectangular prism.rymax- is the max of the coordinates of the rectangular prism.rzmax- is the max of the coordinates of the rectangular prism.- Returns:
- the zone
-
getCohenSutherlandCode3D
@Pure public static int getCohenSutherlandCode3D(double px, double py, double pz, double rxmin, double rymin, double rzmin, double rxmax, double rymax, double rzmax)Compute the zone where the point is against the given rectangular prism according to the Cohen-Sutherland algorithm.This function considers that if a point coordinate is equal to the a border coordinate of the rectangle, it is inside the rectangle.
- Parameters:
px- is the coordinates of the point.py- is the coordinates of the point.pz- is the coordinates of the point.rxmin- is the min of the coordinates of the rectangular prism.rymin- is the min of the coordinates of the rectangular prism.rzmin- is the min of the coordinates of the rectangular prism.rxmax- is the max of the coordinates of the rectangular prism.rymax- is the max of the coordinates of the rectangular prism.rzmax- is the max of the coordinates of the rectangular prism.- Returns:
- the zone
-
getMinMax
public static DoubleRange getMinMax(double value1, double value2, double value3)
Determine the min and max values from a set of three values.This function has an algorithm that is efficient for 3 values.
If one of the value is
Double.NaN, it is ignored. If all the values areDouble.NaN, the function repliesnull.- Parameters:
value1- the first value.value2- the second value.value3- the third value.- Returns:
- the min max range; or
null. - Since:
- 13.0
-
csc
@Pure public static double csc(double angle)
Replies the cosecant of the specified angle.csc(a) = 1/sin(a)
![[Cosecant function]](./doc-files/trigo3.png)
- Parameters:
angle- the angle.- Returns:
- the cosecant of the angle.
-
sec
@Pure public static double sec(double angle)
Replies the secant of the specified angle.csc(a) = 1/cos(a)
![[Secant function]](./doc-files/trigo2.png)
- Parameters:
angle- the angle.- Returns:
- the secant of the angle.
-
cot
@Pure public static double cot(double angle)
Replies the cotangent of the specified angle.csc(a) = 1/tan(a)
![[Cotangent function]](./doc-files/trigo3.png)
- Parameters:
angle- the angle.- Returns:
- the cotangent of the angle.
-
versin
@Pure public static double versin(double angle)
Replies the versine of the specified angle.versin(a) = 1 - cos(a)![[Versine function]](./doc-files/trigo1.png)
- Parameters:
angle- the angle.- Returns:
- the versine of the angle.
-
exsec
@Pure public static double exsec(double angle)
Replies the exsecant of the specified angle.exsec(a) = sec(a) - 1![[Exsecant function]](./doc-files/trigo1.png)
- Parameters:
angle- the angle.- Returns:
- the exsecant of the angle..
-
crd
@Pure public static double crd(double angle)
Replies the chord of the specified angle.crd(a) = 2 sin(a/2)![[Chord function]](./doc-files/chord.png)
- Parameters:
angle- the angle.- Returns:
- the chord of the angle.
-
haversine
@Pure public static double haversine(double angle)
Replies the half of the versine (aka, haversine) of the specified angle.haversine(a) = sin2(a/2) = (1-cos(a)) / 2![[Excosecant function]](./doc-files/trigo1.png)
- Parameters:
angle- the angle.- Returns:
- the half of the versine of the angle.
-
-