Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:35:38

0001 // Boost.Geometry (aka GGL, Generic Geometry Library)
0002 // This file is manually converted from PROJ4
0003 
0004 // Copyright (c) 2008-2012 Barend Gehrels, Amsterdam, the Netherlands.
0005 
0006 // This file was modified by Oracle on 2017, 2018.
0007 // Modifications copyright (c) 2017-2018, Oracle and/or its affiliates.
0008 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
0009 
0010 // Use, modification and distribution is subject to the Boost Software License,
0011 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0012 // http://www.boost.org/LICENSE_1_0.txt)
0013 
0014 // This file is converted from PROJ4, http://trac.osgeo.org/proj
0015 // PROJ4 is originally written by Gerald Evenden (then of the USGS)
0016 // PROJ4 is maintained by Frank Warmerdam
0017 // PROJ4 is converted to Geometry Library by Barend Gehrels (Geodan, Amsterdam)
0018 
0019 // Original copyright notice:
0020 
0021 // Permission is hereby granted, free of charge, to any person obtaining a
0022 // copy of this software and associated documentation files (the "Software"),
0023 // to deal in the Software without restriction, including without limitation
0024 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
0025 // and/or sell copies of the Software, and to permit persons to whom the
0026 // Software is furnished to do so, subject to the following conditions:
0027 
0028 // The above copyright notice and this permission notice shall be included
0029 // in all copies or substantial portions of the Software.
0030 
0031 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
0032 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0033 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
0034 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
0035 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
0036 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
0037 // DEALINGS IN THE SOFTWARE.
0038 
0039 #ifndef BOOST_GEOMETRY_PROJECTIONS_IMPL_PJ_GAUSS_HPP
0040 #define BOOST_GEOMETRY_PROJECTIONS_IMPL_PJ_GAUSS_HPP
0041 
0042 
0043 #include <boost/geometry/srs/projections/constants.hpp>
0044 #include <boost/geometry/srs/projections/exception.hpp>
0045 
0046 
0047 namespace boost { namespace geometry { namespace projections {
0048 
0049 namespace detail {
0050 
0051 
0052 template <typename T>
0053 struct gauss
0054 {
0055     T C;
0056     T K;
0057     T e;
0058     T ratexp;
0059 };
0060 
0061 template <typename T>
0062 inline T srat(T const& esinp, T const& exp)
0063 {
0064     return (math::pow((T(1) - esinp) / (T(1) + esinp), exp));
0065 }
0066 
0067 template <typename T>
0068 inline gauss<T> gauss_ini(T const& e, T const& phi0, T& chi, T& rc)
0069 {
0070     static const T fourth_pi = detail::fourth_pi<T>();
0071 
0072     using std::asin;
0073     using std::cos;
0074     using std::sin;
0075     using std::sqrt;
0076     using std::tan;
0077 
0078     T sphi = 0;
0079     T cphi = 0;
0080     T es = 0;
0081 
0082     gauss<T> en;
0083     es = e * e;
0084     en.e = e;
0085     sphi = sin(phi0);
0086     cphi = cos(phi0);
0087     cphi *= cphi;
0088 
0089     rc = sqrt(1.0 - es) / (1.0 - es * sphi * sphi);
0090     en.C = sqrt(1.0 + es * cphi * cphi / (1.0 - es));
0091     chi = asin(sphi / en.C);
0092     en.ratexp = 0.5 * en.C * e;
0093     en.K = tan(0.5 * chi + fourth_pi)
0094            / (math::pow(tan(T(0.5) * phi0 + fourth_pi), en.C) * srat(en.e * sphi, en.ratexp));
0095 
0096     return en;
0097 }
0098 
0099 template <typename T>
0100 inline void gauss_fwd(gauss<T> const& en, T& lam, T& phi)
0101 {
0102     static const T fourth_pi = detail::fourth_pi<T>();
0103     static const T half_pi = detail::half_pi<T>();
0104 
0105     phi = T(2) * atan(en.K * math::pow(tan(T(0.5) * phi + fourth_pi), en.C)
0106           * srat(en.e * sin(phi), en.ratexp) ) - half_pi;
0107 
0108     lam *= en.C;
0109 }
0110 
0111 template <typename T>
0112 inline void gauss_inv(gauss<T> const& en, T& lam, T& phi)
0113 {
0114     static const int max_iter = 20;
0115     static const T fourth_pi = detail::fourth_pi<T>();
0116     static const T half_pi = detail::half_pi<T>();
0117     static const T del_tol = 1e-14;
0118 
0119     lam /= en.C;
0120     const T num = math::pow(tan(T(0.5) * phi + fourth_pi) / en.K, T(1) / en.C);
0121 
0122     int i = 0;
0123     for (i = max_iter; i; --i)
0124     {
0125         const T elp_phi = 2.0 * atan(num * srat(en.e * sin(phi), - 0.5 * en.e)) - half_pi;
0126 
0127         if (geometry::math::abs(elp_phi - phi) < del_tol)
0128         {
0129             break;
0130         }
0131         phi = elp_phi;
0132     }
0133 
0134     /* convergence failed */
0135     if (!i)
0136     {
0137         BOOST_THROW_EXCEPTION( projection_exception(error_non_conv_inv_meri_dist) );
0138     }
0139 }
0140 
0141 } // namespace detail
0142 
0143 }}} // namespace boost::geometry::projections
0144 
0145 #endif // BOOST_GEOMETRY_PROJECTIONS_IMPL_PJ_GAUSS_HPP