65#define _coeffs (65341)
72 double sinml[
_361 + 1],
double cosml[
_361 + 1],
76 const double GM = 0.3986004418e15;
78 const double ae = 6378137.0;
86 for (
unsigned n = 2; n <=
_nmax; n++)
93 for (
unsigned m = 1; m <= n; m++)
109 return ((a * GM) / (gr * re)) + (ac / 100.0) - 0.53;
114 double a = sin(rlon);
115 double b = cos(rlon);
119 sinml[2] = 2 * b * a;
120 cosml[2] = 2 * b * b - 1;
122 for (
unsigned m = 3; m <=
_nmax; m++)
124 sinml[m] = 2 * b * sinml[m - 1] - sinml[m - 2];
125 cosml[m] = 2 * b * cosml[m - 1] - cosml[m - 2];
143 static double drts[1301], dirt[1301], cothet, sithet, rlnn[
_361 + 1];
146 unsigned nmax1 =
_nmax + 1;
147 unsigned nmax2p = (2 *
_nmax) + 1;
156 for (n = 1; n <= nmax2p; n++)
159 dirt[n] = 1 / drts[n];
168 rlnn[2] = sithet * drts[3];
169 for (n1 = 3; n1 <= m1; n1++)
173 rlnn[n1] = drts[n2 + 1] * dirt[n2] * sithet * rlnn[n];
180 rleg[3] = drts[5] * cothet * rleg[2];
184 rleg[2] = cothet * drts[3];
191 rleg[m2] = drts[m1 * 2 + 1] * cothet * rleg[m1];
194 for (n1 = m3; n1 <= nmax1; n1++)
197 if ((!m && n < 2) || (m == 1 && n < 3))
continue;
199 rleg[n1] = drts[n2 + 1] * dirt[n + m] * dirt[n - m] * (drts[n2 - 1] * cothet * rleg[n1 - 1] - drts[n + m - 1] * drts[n - m - 1] * dirt[n2 - 3] * rleg[n1 - 2]);
219void radgra(
double lat,
double lon,
double* rlat,
double* gr,
double* re)
221 const double a = 6378137.0;
222 const double e2 = 0.00669437999013;
223 const double geqt = 9.7803253359;
224 const double k = 0.00193185265246;
225 double t1 = sin(lat) * sin(lat);
226 double n = a / sqrt(1.0 - (e2 * t1));
227 double t2 = n * cos(lat);
228 double x = t2 * cos(lon);
229 double y = t2 * sin(lon);
230 double z = (n * (1 - e2)) * sin(lat);
232 *re = sqrt((x * x) + (y * y) + (z * z));
233 *rlat = atan(z / sqrt((x * x) + (y * y)));
234 *gr = geqt * (1 + (k * t1)) / sqrt(1 - (e2 * t1));
243double undulation(
double lat,
double lon)
248 unsigned nmax1 =
_nmax + 1;
251 radgra(lat, lon, &rlat, &gr, &re);
252 rlat = (M_PI / 2) - rlat;
254 for (
unsigned j = 1; j <= nmax1; j++)
258 for (
unsigned i = j; i <= nmax1; i++)
260 p[(((i - 1) * i) / 2) + m + 1] = rleg[i];
263 dscml(lon, sinml, cosml);
265 return hundu(p, sinml, cosml, gr, re);
274 return undulation(lat, lon);
#define _coeffs
Size of correction and harmonic coefficients arrays (361*181)
#define _nmax
Maximum degree and orders of harmonic coefficients.
static const double egm96_data[65342][4]
Precomputed EGM96 correction and harmonic coefficients.
double egm96_compute_altitude_offset(double lat, double lon)
Compute the geoid undulation from the EGM96 potential coefficient model to The WGS84 ellipsoid.
double hundu(double p[_coeffs+1], double sinml[_361+1], double cosml[_361+1], double gr, double re)
void dscml(double rlon, double sinml[_361+1], double cosml[_361+1])
void legfdn(unsigned m, double theta, double rleg[_361+1])