19 double lat = std::min(89.5, std::max(
p.lat, -89.5));
20 double phi = lat * M_PI / 180.0;
21 double con =
Eccent * std::sin(phi);
22 con = std::pow((1.0 - con) / (1.0 + con), 0.5 *
Eccent);
23 double ts = std::tan(0.5 * (M_PI * 0.5 - phi)) / con;
24 const double y = -
RMajor * std::log(ts);
25 const double x =
RMajor *
p.lon * M_PI / 180.;
29 double ts = std::exp(-
p.y() /
RMajor);
30 double phi = M_PI / 2 - 2 * std::atan(ts);
32 for (
int i = 0; fabs(dphi) > 0.000000001 && i < 15; i++) {
33 double con =
Eccent * sin(phi);
34 dphi = M_PI / 2 - 2 * atan(ts * pow((1.0 - con) / (1.0 + con), 0.5 *
Eccent)) - phi;
37 const double lat = 180 / M_PI * phi;
38 const double lon = 180 / M_PI *
p.x() /
RMajor;
39 return {lat, lon,
p.z()};
43 static constexpr
double RMajor{6378137.0};
44 static constexpr
double RMinor{6356752.3142};
45 static constexpr
double Eccent{0.081819190928906924};