Class GeoMath

java.lang.Object
com.irurueta.navigation.geodesic.GeoMath

public class GeoMath extends Object
Defines mathematical functions and constants. Based on net.sf.geographiclib library.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Number of binary digits in the fraction of double precision number.
    static final double
    Equivalent to C++'s numeric_limits<double>::epsilon().
    static final double
    Equivalent to C++'s numeric_limits<double>::min().
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    static 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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DIGITS

      public static final int DIGITS
      Number of binary digits in the fraction of double precision number. This is equivalent to C++'s numeric_limits<double>::digits.
      See Also:
    • EPSILON

      public static final double EPSILON
      Equivalent to C++'s numeric_limits<double>::epsilon(). This is equal to 0.5^(DIGITS - 1).
    • MIN

      public static final double MIN
      Equivalent to C++'s numeric_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 to Math.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 to Math.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 of log1p(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 to Math.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 to Math.cbrt(double).
      Parameters:
      x - the argument.
      Returns:
      the real cube root of x.
    • norm

      public static Pair norm(double sinx, double cosx)
      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

      public static Pair sum(double u, double v)
      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 xnn. 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

      public static Pair angDiff(double x, double y)
      The exact difference of two angles reduced to (−180°, 180°]. This computes z = yx 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

      public static Pair sincosd(double x)
      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.