File indexing completed on 2025-01-18 09:35:39
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039 #ifndef BOOST_GEOMETRY_PROJECTIONS_PROJ_MDIST_HPP
0040 #define BOOST_GEOMETRY_PROJECTIONS_PROJ_MDIST_HPP
0041
0042
0043 #include <boost/geometry/srs/projections/exception.hpp>
0044 #include <boost/geometry/srs/projections/impl/pj_strerrno.hpp>
0045 #include <boost/geometry/util/math.hpp>
0046
0047
0048 namespace boost { namespace geometry { namespace projections
0049 {
0050 namespace detail
0051 {
0052 template <typename T>
0053 struct mdist
0054 {
0055 static const int static_size = 20;
0056
0057 T es;
0058 T E;
0059 T b[static_size];
0060 int nb;
0061 };
0062
0063 template <typename T>
0064 inline bool proj_mdist_ini(T const& es, mdist<T>& b)
0065 {
0066 T numf, numfi, twon1, denf, denfi, ens, t, twon;
0067 T den, El, Es;
0068 T E[mdist<T>::static_size];
0069 int i, j;
0070
0071
0072 ens = es;
0073 numf = twon1 = denfi = 1.;
0074 denf = 1.;
0075 twon = 4.;
0076 Es = El = E[0] = 1.;
0077 for (i = 1; i < mdist<T>::static_size ; ++i)
0078 {
0079 numf *= (twon1 * twon1);
0080 den = twon * denf * denf * twon1;
0081 t = numf/den;
0082 E[i] = t * ens;
0083 Es -= E[i];
0084 ens *= es;
0085 twon *= 4.;
0086 denf *= ++denfi;
0087 twon1 += 2.;
0088 if (Es == El)
0089 break;
0090 El = Es;
0091 }
0092 b.nb = i - 1;
0093 b.es = es;
0094 b.E = Es;
0095
0096 b.b[0] = Es = 1. - Es;
0097 numf = denf = 1.;
0098 numfi = 2.;
0099 denfi = 3.;
0100 for (j = 1; j < i; ++j)
0101 {
0102 Es -= E[j];
0103 numf *= numfi;
0104 denf *= denfi;
0105 b.b[j] = Es * numf / denf;
0106 numfi += 2.;
0107 denfi += 2.;
0108 }
0109 return true;
0110 }
0111
0112 template <typename T>
0113 inline T proj_mdist(T const& phi, T const& sphi, T const& cphi, mdist<T> const& b)
0114 {
0115 T sc, sum, sphi2, D;
0116 int i;
0117
0118 sc = sphi * cphi;
0119 sphi2 = sphi * sphi;
0120 D = phi * b.E - b.es * sc / sqrt(1. - b.es * sphi2);
0121 sum = b.b[i = b.nb];
0122 while (i) sum = b.b[--i] + sphi2 * sum;
0123 return(D + sc * sum);
0124 }
0125
0126 template <typename T>
0127 inline T proj_inv_mdist(T const& dist, mdist<T> const& b)
0128 {
0129 static const T TOL = 1e-14;
0130 T s, t, phi, k;
0131 int i;
0132
0133 k = 1./(1.- b.es);
0134 i = mdist<T>::static_size;
0135 phi = dist;
0136 while ( i-- ) {
0137 s = sin(phi);
0138 t = 1. - b.es * s * s;
0139 phi -= t = (proj_mdist(phi, s, cos(phi), b) - dist) *
0140 (t * sqrt(t)) * k;
0141 if (geometry::math::abs(t) < TOL)
0142 return phi;
0143 }
0144
0145 BOOST_THROW_EXCEPTION( projection_exception(error_non_conv_inv_meri_dist) );
0146 }
0147 }
0148
0149 }}}
0150
0151 #endif