Package com.irurueta.navigation.geodesic
Class GeoMath
java.lang.Object
com.irurueta.navigation.geodesic.GeoMath
Defines mathematical functions and constants.
Based on net.sf.geographiclib library.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Pair
angDiff
(double x, double y) The exact difference of two angles reduced to (−180°, 180°].static double
angNormalize
(double x) Normalizes an angle (restricted input range).static double
angRound
(double x) Makes the smallest gap in x = 1 / 16 - nextafter(1/16, 0) = 1/2^57 for reals = 0.7 pm on the earth if x is an angle in degrees.static double
atan2d
(double y, double x) Evaluate the atan2 function with the result in degrees.static double
atanh
(double x) The inverse hyperbolic tangent function.static double
cbrt
(double x) The cube root function.static double
copysign
(double x, double y) Copy the sign.static double
hypot
(double x, double y) The hypotenuse function avoiding underflow and overflow.static boolean
isFinite
(double x) Test for finiteness.static double
latFix
(double x) Normalizes latitude.static double
log1p
(double x) log(1 + x) accurate near x = 0.static Pair
norm
(double sinx, double cosx) Normalizes sinus and cosine.static double
polyval
(int n, double[] p, int s, double x) Evaluate a polynomial.static Pair
sincosd
(double x) Evaluate the sine and cosine function with the argument in degrees.static double
sq
(double x) Square a number.static Pair
sum
(double u, double v) The error-free sum of two numbers.
-
Field Details
-
DIGITS
public static final int DIGITSNumber of binary digits in the fraction of double precision number. This is equivalent to C++'snumeric_limits<double>::digits
.- See Also:
-
EPSILON
public static final double EPSILONEquivalent to C++'snumeric_limits<double>::epsilon()
. This is equal to 0.5^(DIGITS - 1). -
MIN
public static final double MINEquivalent to C++'snumeric_limits<double>::min()
. This is equal to 0.5^1022.- See Also:
-
-
Constructor Details
-
GeoMath
private GeoMath()Constructor. Prevents instantiation.
-
-
Method Details
-
sq
public static double sq(double x) Square a number.- Parameters:
x
- the argument.- Returns:
- x2.
-
hypot
public static double hypot(double x, double y) The hypotenuse function avoiding underflow and overflow. This is equivalent toMath.hypot(double, double)
.- Parameters:
x
- the first argument.y
- the second argument.- Returns:
- sqrt(x2 + y2).
-
log1p
public static double log1p(double x) log(1 + x) accurate near x = 0. This is equivalent toMath.log1p(double)
.This is taken from D.Goldberg, What every computer scientist should know about floating-point arithmetic (1991), Theorem 4. See also, N. J. Higham, Accuracy and Stability of Numerical Algorithms, 2nd Edition (SIAM, 2002), Answer to Problem 1.5, p 528.
- Parameters:
x
- the argument.- Returns:
- log(1 + x).
-
atanh
public static double atanh(double x) The inverse hyperbolic tangent function. This is defined in terms oflog1p(double)
in order to maintain accuracy near x = 0. In addition, the odd parity of the function is enforced.- Parameters:
x
- the argument.- Returns:
- atanh(x).
-
copysign
public static double copysign(double x, double y) Copy the sign. This is equivalent toMath.copySign(double, double)
- Parameters:
x
- gives the magnitude of the result.y
- gives the sign of the result.- Returns:
- value with the magnitude of x and with the sign of y.
-
cbrt
public static double cbrt(double x) The cube root function. This is equivalent toMath.cbrt(double)
.- Parameters:
x
- the argument.- Returns:
- the real cube root of x.
-
norm
Normalizes sinus and cosine.- Parameters:
sinx
- sinus of x.cosx
- cosine of x.- Returns:
- normalized values.
- Throws:
IllegalArgumentException
- if provided sinus and cosine values have zero norm.
-
sum
The error-free sum of two numbers. See D.E. Knuth, TAOCP, Vol 2, 4.2.2, Theorem B.- Parameters:
u
- the first number in the sum.v
- the second number in the sum.- Returns:
- Pair(s, t) with s = round(u + v) and t = u + v - s.
-
polyval
public static double polyval(int n, double[] p, int s, double x) Evaluate a polynomial.Evaluate y = ∑n=0..n ps+n xn−n. Return 0 if n < 0. Return ps, if n = 0 (even if x is infinite or a nan). The evaluation uses Horner's method. This is equivalent to
Polynomial.evaluate(double)
.- Parameters:
n
- the order of the polynomial.p
- the coefficient array (of size n + s + 1 or more).s
- starting index of the array.x
- the variable.- Returns:
- the value of the polynomial.
-
angRound
public static double angRound(double x) Makes the smallest gap in x = 1 / 16 - nextafter(1/16, 0) = 1/2^57 for reals = 0.7 pm on the earth if x is an angle in degrees. (This is about 1000 times more resolution than we get with angles around 90 degrees.). We use this to avoid having to deal with near singular cases when x is non-zero but tiny (e.g. 1.0e-200). This converts -0 to +0; however tiny negative numbers get converted to -0.- Parameters:
x
- value to be converted- Returns:
- rounded value.
-
angNormalize
public static double angNormalize(double x) Normalizes an angle (restricted input range). The range of x is unrestricted.- Parameters:
x
- the angle in degrees.- Returns:
- the angle reduced to the range [−180°, 180°).
-
latFix
public static double latFix(double x) Normalizes latitude.- Parameters:
x
- the angle in degrees.- Returns:
- x if it is in the range [−90°, 90°], otherwise return NaN.
-
angDiff
The exact difference of two angles reduced to (−180°, 180°]. This computes z = y − x exactly, reduced to (−180°, 180°]; and then sets z = d + e where d is the nearest representable number to z and e is the truncation error. If d = −180, then e > 0; If d = 180, then e ≤ 0.- Parameters:
x
- the first angle in degrees.y
- the second angle in degrees.- Returns:
- Pair(d, e) with d being the rounded difference and e being the error.
-
sincosd
Evaluate the sine and cosine function with the argument in degrees. The results obey exactly the elementary properties of the trigonometric functions, e.g. sin 9° = cos 81° = − sin 123456789°.- Parameters:
x
- in degrees.- Returns:
- Pair(s, t) with s = sin(x and c = cos(x).
-
atan2d
public static double atan2d(double y, double x) Evaluate the atan2 function with the result in degrees. The result is in the range (−180° 180°]. N.B., atan2d(±0, −1) = +180°; atan2d(−ε,−1) = −180°, for ε positive and tiny; atan2d(±0, 1) = +plusmn;0°.- Parameters:
y
- the sine of the angle.x
- the cosine of the angle.- Returns:
- atan2(y, x) in degrees.
-
isFinite
public static boolean isFinite(double x) Test for finiteness.- Parameters:
x
- the argument.- Returns:
- true if number is finite, false if NaN or infinite.
-