1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // This file is manually converted from PROJ4
4 // Copyright (c) 2008-2012 Barend Gehrels, Amsterdam, the Netherlands.
6 // This file was modified by Oracle on 2017, 2018.
7 // Modifications copyright (c) 2017-2018, Oracle and/or its affiliates.
8 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
10 // Use, modification and distribution is subject to the Boost Software License,
11 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
12 // http://www.boost.org/LICENSE_1_0.txt)
14 // This file is converted from PROJ4, http://trac.osgeo.org/proj
15 // PROJ4 is originally written by Gerald Evenden (then of the USGS)
16 // PROJ4 is maintained by Frank Warmerdam
17 // PROJ4 is converted to Geometry Library by Barend Gehrels (Geodan, Amsterdam)
19 // Original copyright notice:
21 // Permission is hereby granted, free of charge, to any person obtaining a
22 // copy of this software and associated documentation files (the "Software"),
23 // to deal in the Software without restriction, including without limitation
24 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
25 // and/or sell copies of the Software, and to permit persons to whom the
26 // Software is furnished to do so, subject to the following conditions:
28 // The above copyright notice and this permission notice shall be included
29 // in all copies or substantial portions of the Software.
31 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
32 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
33 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
34 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
35 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
36 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
37 // DEALINGS IN THE SOFTWARE.
39 /* meridional distance for ellipsoid and inverse
40 ** 8th degree - accurate to < 1e-5 meters when used in conjunction
41 ** with typical major axis values.
42 ** Inverse determines phi to EPS (1e-11) radians, about 1e-6 seconds.
45 #ifndef BOOST_GEOMETRY_PROJECTIONS_PJ_MLFN_HPP
46 #define BOOST_GEOMETRY_PROJECTIONS_PJ_MLFN_HPP
51 #include <boost/geometry/srs/projections/exception.hpp>
52 #include <boost/geometry/srs/projections/impl/pj_strerrno.hpp>
53 #include <boost/geometry/util/math.hpp>
56 namespace boost { namespace geometry { namespace projections {
63 static const std::size_t size = 5;
65 T const& operator[](size_t i) const { return data[i]; }
66 T & operator[](size_t i) { return data[i]; }
73 inline en<T> pj_enfn(T const& es)
75 static const T C00 = 1.;
76 static const T C02 = .25;
77 static const T C04 = .046875;
78 static const T C06 = .01953125;
79 static const T C08 = .01068115234375;
80 static const T C22 = .75;
81 static const T C44 = .46875;
82 static const T C46 = .01302083333333333333;
83 static const T C48 = .00712076822916666666;
84 static const T C66 = .36458333333333333333;
85 static const T C68 = .00569661458333333333;
86 static const T C88 = .3076171875;
92 en[0] = C00 - es * (C02 + es * (C04 + es * (C06 + es * C08)));
93 en[1] = es * (C22 - es * (C04 + es * (C06 + es * C08)));
94 en[2] = (t = es * es) * (C44 - es * (C46 + es * C48));
95 en[3] = (t *= es) * (C66 - es * C68);
102 template <typename T>
103 inline T pj_mlfn(T const& phi, T sphi, T cphi, detail::en<T> const& en)
107 return(en[0] * phi - cphi * (en[1] + sphi*(en[2]
108 + sphi*(en[3] + sphi*en[4]))));
111 template <typename T>
112 inline T pj_inv_mlfn(T const& arg, T const& es, detail::en<T> const& en)
114 static const T EPS = 1e-11;
115 static const int MAX_ITER = 10;
117 T s, t, phi, k = 1./(1.-es);
121 for (i = MAX_ITER; i ; --i) { /* rarely goes over 2 iterations */
124 phi -= t = (pj_mlfn(phi, s, cos(phi), en) - arg) * (t * sqrt(t)) * k;
125 if (geometry::math::abs(t) < EPS)
128 BOOST_THROW_EXCEPTION( projection_exception(error_non_conv_inv_meri_dist) );
132 } // namespace detail
133 }}} // namespace boost::geometry::projections