123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- #ifndef BOOST_GEOMETRY_PROJECTIONS_VANDG_HPP
- #define BOOST_GEOMETRY_PROJECTIONS_VANDG_HPP
- #include <boost/geometry/util/math.hpp>
- #include <boost/geometry/srs/projections/impl/base_static.hpp>
- #include <boost/geometry/srs/projections/impl/base_dynamic.hpp>
- #include <boost/geometry/srs/projections/impl/projects.hpp>
- #include <boost/geometry/srs/projections/impl/factory_entry.hpp>
- namespace boost { namespace geometry
- {
- namespace projections
- {
- #ifndef DOXYGEN_NO_DETAIL
- namespace detail { namespace vandg
- {
- static const double tolerance = 1.e-10;
- template <typename T>
- inline T C2_27() { return .07407407407407407407407407407407; }
- template <typename T>
- inline T PI4_3() { return boost::math::constants::four_thirds_pi<T>(); }
- template <typename T>
- inline T TPISQ() { return 19.739208802178717237668981999752; }
- template <typename T>
- inline T HPISQ() { return 4.9348022005446793094172454999381; }
- template <typename T, typename Parameters>
- struct base_vandg_spheroid
- {
-
-
- inline void fwd(Parameters const& , T const& lp_lon, T const& lp_lat, T& xy_x, T& xy_y) const
- {
- static const T half_pi = detail::half_pi<T>();
- static const T pi = detail::pi<T>();
- T al, al2, g, g2, p2;
- p2 = fabs(lp_lat / half_pi);
- if ((p2 - tolerance) > 1.) {
- BOOST_THROW_EXCEPTION( projection_exception(error_tolerance_condition) );
- }
- if (p2 > 1.)
- p2 = 1.;
- if (fabs(lp_lat) <= tolerance) {
- xy_x = lp_lon;
- xy_y = 0.;
- } else if (fabs(lp_lon) <= tolerance || fabs(p2 - 1.) < tolerance) {
- xy_x = 0.;
- xy_y = pi * tan(.5 * asin(p2));
- if (lp_lat < 0.) xy_y = -xy_y;
- } else {
- al = .5 * fabs(pi / lp_lon - lp_lon / pi);
- al2 = al * al;
- g = sqrt(1. - p2 * p2);
- g = g / (p2 + g - 1.);
- g2 = g * g;
- p2 = g * (2. / p2 - 1.);
- p2 = p2 * p2;
- xy_x = g - p2; g = p2 + al2;
- xy_x = pi * (al * xy_x + sqrt(al2 * xy_x * xy_x - g * (g2 - p2))) / g;
- if (lp_lon < 0.) xy_x = -xy_x;
- xy_y = fabs(xy_x / pi);
- xy_y = 1. - xy_y * (xy_y + 2. * al);
- if (xy_y < -tolerance) {
- BOOST_THROW_EXCEPTION( projection_exception(error_tolerance_condition) );
- }
- if (xy_y < 0.)
- xy_y = 0.;
- else
- xy_y = sqrt(xy_y) * (lp_lat < 0. ? -pi : pi);
- }
- }
-
-
- inline void inv(Parameters const& , T const& xy_x, T const& xy_y, T& lp_lon, T& lp_lat) const
- {
- static const T half_pi = detail::half_pi<T>();
- static const T pi = detail::pi<T>();
- static const T pi_sqr = detail::pi_sqr<T>();
- static const T third = detail::third<T>();
- static const T two_pi = detail::two_pi<T>();
- static const T C2_27 = vandg::C2_27<T>();
- static const T PI4_3 = vandg::PI4_3<T>();
- static const T TPISQ = vandg::TPISQ<T>();
- static const T HPISQ = vandg::HPISQ<T>();
- T t, c0, c1, c2, c3, al, r2, r, m, d, ay, x2, y2;
- x2 = xy_x * xy_x;
- if ((ay = fabs(xy_y)) < tolerance) {
- lp_lat = 0.;
- t = x2 * x2 + TPISQ * (x2 + HPISQ);
- lp_lon = fabs(xy_x) <= tolerance ? 0. :
- .5 * (x2 - pi_sqr + sqrt(t)) / xy_x;
- return;
- }
- y2 = xy_y * xy_y;
- r = x2 + y2; r2 = r * r;
- c1 = - pi * ay * (r + pi_sqr);
- c3 = r2 + two_pi * (ay * r + pi * (y2 + pi * (ay + half_pi)));
- c2 = c1 + pi_sqr * (r - 3. * y2);
- c0 = pi * ay;
- c2 /= c3;
- al = c1 / c3 - third * c2 * c2;
- m = 2. * sqrt(-third * al);
- d = C2_27 * c2 * c2 * c2 + (c0 * c0 - third * c2 * c1) / c3;
- if (((t = fabs(d = 3. * d / (al * m))) - tolerance) <= 1.) {
- d = t > 1. ? (d > 0. ? 0. : pi) : acos(d);
- lp_lat = pi * (m * cos(d * third + PI4_3) - third * c2);
- if (xy_y < 0.) lp_lat = -lp_lat;
- t = r2 + TPISQ * (x2 - y2 + HPISQ);
- lp_lon = fabs(xy_x) <= tolerance ? 0. :
- .5 * (r - pi_sqr + (t <= 0. ? 0. : sqrt(t))) / xy_x;
- } else {
- BOOST_THROW_EXCEPTION( projection_exception(error_tolerance_condition) );
- }
- }
- static inline std::string get_name()
- {
- return "vandg_spheroid";
- }
- };
-
- template <typename Parameters>
- inline void setup_vandg(Parameters& par)
- {
- par.es = 0.;
- }
- }}
- #endif
-
- template <typename T, typename Parameters>
- struct vandg_spheroid : public detail::vandg::base_vandg_spheroid<T, Parameters>
- {
- template <typename Params>
- inline vandg_spheroid(Params const& , Parameters & par)
- {
- detail::vandg::setup_vandg(par);
- }
- };
- #ifndef DOXYGEN_NO_DETAIL
- namespace detail
- {
-
- BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_FI(srs::spar::proj_vandg, vandg_spheroid)
-
- BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_FI(vandg_entry, vandg_spheroid)
- BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_BEGIN(vandg_init)
- {
- BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(vandg, vandg_entry)
- }
- }
- #endif
- }
- }}
- #endif
|