100 using namespace MSP::CCS;
108 const double PI = 3.14159265358979323e0;
122 double ellipsoidSemiMajorAxis,
123 double ellipsoidFlattening ) :
125 Geocent_e2( 0.0066943799901413800 ),
126 Geocent_ep2( 0.00673949675658690300 )
136 double inv_f = 1 / ellipsoidFlattening;
138 if (ellipsoidSemiMajorAxis <= 0.0)
140 if ((inv_f < 250) || (inv_f > 350))
149 Geocent_ep2 = (1 / (1 - Geocent_e2)) - 1;
152 Geocent_algorithm = UNDEFINED;
160 Geocent_e2 = g.Geocent_e2;
161 Geocent_ep2 = g.Geocent_ep2;
162 Geocent_algorithm = g.Geocent_algorithm;
177 Geocent_e2 = g.Geocent_e2;
178 Geocent_ep2 = g.Geocent_ep2;
179 Geocent_algorithm = g.Geocent_algorithm;
208 double longitude = geodeticCoordinates->
longitude();
209 double latitude = geodeticCoordinates->
latitude();
210 double height = geodeticCoordinates->
height();
216 if ((longitude < -
PI) || (longitude > (2*
PI)))
223 Sin_Lat = sin(latitude);
224 Cos_Lat = cos(latitude);
225 Sin2_Lat = Sin_Lat * Sin_Lat;
227 double X = (Rn + height) * Cos_Lat * cos(longitude);
228 double Y = (Rn + height) * Cos_Lat * sin(longitude);
229 double Z = ((Rn * (1 - Geocent_e2)) + height) * Sin_Lat;
256 double X = cartesianCoordinates->
x();
257 double Y = cartesianCoordinates->
y();
258 double Z = cartesianCoordinates->
z();
259 double latitude, longitude, height;
261 if( Geocent_algorithm == UNDEFINED )
263 Geocent_algorithm = ITERATIVE;
264 char *geotransConv = getenv(
"MSPCCS_USE_LEGACY_GEOTRANS" );
265 if( geotransConv != NULL )
267 Geocent_algorithm = GEOTRANS;
271 if( Geocent_algorithm == ITERATIVE )
273 geocentricToGeodetic( X, Y, Z, latitude, longitude, height );
296 longitude = atan2(Y,X);
332 S0 = sqrt(T0 * T0 + W2);
335 Sin3_B0 = Sin_B0 * Sin_B0 * Sin_B0;
336 T1 = Z + Geocent_b * Geocent_ep2 * Sin3_B0;
337 Sum = W -
semiMajorAxis * Geocent_e2 * Cos_B0 * Cos_B0 * Cos_B0;
338 S1 = sqrt(T1*T1 + Sum * Sum);
341 Rn =
semiMajorAxis / sqrt(1.0 - Geocent_e2 * Sin_p1 * Sin_p1);
344 height = W / Cos_p1 - Rn;
348 height = W / -Cos_p1 - Rn;
352 height = Z / Sin_p1 + Rn * (Geocent_e2 - 1.0);
354 if (At_Pole ==
FALSE)
356 latitude = atan(Sin_p1 / Cos_p1);
358 double Sin_Lat = sin(latitude);
359 double Cos_Lat = cos(latitude);
360 double Sin2_Lat = Sin_Lat * Sin_Lat;
361 double Rnn =
semiMajorAxis / (sqrt(1.0e0 - Geocent_e2 * Sin2_Lat));
362 double X1 = (Rnn + height) * Cos_Lat * cos(longitude);
363 double Y1 = (Rnn + height) * Cos_Lat * sin(longitude);
364 double Z1 = ((Rnn * (1 - Geocent_e2)) + height) * Sin_Lat;
366 if( ( (X-X1) * (X-X1) + (Y-Y1) * (Y-Y1) + (Z-Z1) * (Z-Z1) ) > 1 )
376 void Geocentric::geocentricToGeodetic(
385 double eccentricity_squared = Geocent_e2;
387 double rho, c, s, ct2, e1, e2a;
389 e1 = 1.0 - eccentricity_squared;
390 e2a = eccentricity_squared * equatorial_radius;
392 rho = sqrt(x * x + y * y);
402 double ct, new_ct, zabs;
403 double f, new_f, df_dct, e2;
415 e2 = sqrt(e1 + ct*ct);
417 new_f = rho - zabs*ct - e2a*ct/e2;
419 if (new_f == 0.0)
break;
421 df_dct = -zabs - (e2a*e1)/(e2*e2*e2);
423 new_ct = ct - new_f / df_dct;
425 if (new_ct < 0.0) new_ct = 0.0;
427 while (fabs(new_f) < fabs(f));
429 s = 1.0 / sqrt(1.0 + ct * ct);
435 lat = -atan(1.0 / ct);
438 lat = atan(1.0 / ct);
444 ht = rho*c + z*s - equatorial_radius*sqrt(1.0 - eccentricity_squared*s*s);
static const char * ellipsoidFlattening
Geocentric(double ellipsoidSemiMajorAxis, double ellipsoidFlattening)
static const char * longitude
MSP::CCS::GeodeticCoordinates * convertToGeodetic(MSP::CCS::CartesianCoordinates *cartesianCoordinates)
static const char * semiMajorAxis
static const char * latitude
MSP::CCS::CartesianCoordinates * convertFromGeodetic(const MSP::CCS::GeodeticCoordinates *geodeticCoordinates)
Geocentric & operator=(const Geocentric &g)