public class GeoMath extends Object
Define mathematical functions and constants so that any version of Java can be used.
| Modifier and Type | Field and Description |
|---|---|
static int |
digits
The number of binary digits in the fraction of a double precision
number (equivalent to C++'s
numeric_limits<double>::digits). |
| Modifier and Type | Method and Description |
|---|---|
static void |
AngDiff(Pair p,
double x,
double y)
The exact difference of two angles reduced to [−180°, 180°].
|
static double |
AngNormalize(double x)
Normalize an angle.
|
static double |
AngRound(double x)
Coarsen a value close to zero.
|
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 |
LatFix(double x)
Normalize a latitude.
|
static void |
norm(Pair p,
double sinx,
double cosx)
Normalize a sine cosine pair.
|
static double |
polyval(int N,
double[] p,
int s,
double x)
Evaluate a polynomial.
|
static void |
sincosd(Pair p,
double x)
Evaluate the sine and cosine function with the argument in degrees
|
static void |
sincosde(Pair p,
double x,
double t)
Evaluate the sine and cosine function with reduced argument plus correction
|
static double |
sq(double x)
Square a number.
|
static void |
sum(Pair p,
double u,
double v)
The error-free sum of two numbers.
|
public static final int digits
numeric_limits<double>::digits).public static double sq(double x)
x - the argument.public static double atanh(double x)
x - the argument.public static void norm(Pair p, double sinx, double cosx)
p - return parameter for normalized quantities with sinx2
+ cosx2 = 1.sinx - the sine.cosx - the cosine.public static void sum(Pair p, double u, double v)
u - the first number in the sum.v - the second number in the sum.p - output Pair(s, t) with s = round(u +
v) and t = u + v - s.
See D. E. Knuth, TAOCP, Vol 2, 4.2.2, Theorem B.
public static double polyval(int N,
double[] p,
int s,
double x)
N - the order of the polynomial.p - the coefficient array (of size N + s + 1 or more).s - starting index for the array.x - the variable.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.
public static double AngRound(double x)
x - the argumentThis makes the smallest gap in x = 1/16 − nextafter(1/16, 0) = 1/257 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., 10−200). This converts −0 to +0; however tiny negative numbers get converted to −0.
public static double AngNormalize(double x)
x - the angle in degrees.The range of x is unrestricted.
public static double LatFix(double x)
x - the angle in degrees.public static void AngDiff(Pair p, double x, double y)
x - the first angle in degrees.y - the second angle in degrees.p - output Pair(d, e) with d being the rounded
difference and e being the error.
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 z = ±0° or ±180°, then the sign of d is given by the sign of y − x. The maximum absolute value of e is 2−26 (for doubles).
public static void sincosd(Pair p, double x)
p - return Pair(s, t) with s = sin(x) and
c = cos(x).x - in degrees.
The results obey exactly the elementary properties of the trigonometric functions, e.g., sin 9° = cos 81° = − sin 123456789°.
public static void sincosde(Pair p, double x, double t)
p - return Pair(s, t) with s =
sin(x + t) and c = cos(x + t).x - reduced angle in degrees.t - correction in degrees.
This is a variant of GeoMath.sincosd allowing a correction to the angle to be supplied. x x must be in [−180°, 180°] and t is assumed to be a small correction. GeoMath.AngRound is applied to the reduced angle to prevent problems with x + t being extremely close but not exactly equal to one of the four cardinal directions.
public static double atan2d(double y,
double x)
y - the sine of the anglex - the cosine of the angleThe result is in the range [−180° 180°]. N.B., atan2d(±0, −1) = ±180°.
Copyright © 2022. All rights reserved.