123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
- #ifndef BOOST_GEOMETRY_PROJECTIONS_ORTHO_HPP
- #define BOOST_GEOMETRY_PROJECTIONS_ORTHO_HPP
- #include <boost/config.hpp>
- #include <boost/geometry/util/math.hpp>
- #include <boost/math/special_functions/hypot.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 ortho
- {
- enum mode_type {
- n_pole = 0,
- s_pole = 1,
- equit = 2,
- obliq = 3
- };
- template <typename T>
- struct par_ortho
- {
- T sinph0;
- T cosph0;
- mode_type mode;
- };
- static const double epsilon10 = 1.e-10;
- template <typename T, typename Parameters>
- struct base_ortho_spheroid
- {
- par_ortho<T> m_proj_parm;
-
-
- inline void fwd(Parameters const& par, T const& lp_lon, T const& lp_lat, T& xy_x, T& xy_y) const
- {
- static const T half_pi = detail::half_pi<T>();
- T coslam, cosphi, sinphi;
- cosphi = cos(lp_lat);
- coslam = cos(lp_lon);
- switch (this->m_proj_parm.mode) {
- case equit:
- if (cosphi * coslam < - epsilon10) {
- BOOST_THROW_EXCEPTION( projection_exception(error_tolerance_condition) );
- }
- xy_y = sin(lp_lat);
- break;
- case obliq:
- if (this->m_proj_parm.sinph0 * (sinphi = sin(lp_lat)) +
- this->m_proj_parm.cosph0 * cosphi * coslam < - epsilon10) {
- BOOST_THROW_EXCEPTION( projection_exception(error_tolerance_condition) );
- }
- xy_y = this->m_proj_parm.cosph0 * sinphi - this->m_proj_parm.sinph0 * cosphi * coslam;
- break;
- case n_pole:
- coslam = - coslam;
- BOOST_FALLTHROUGH;
- case s_pole:
- if (fabs(lp_lat - par.phi0) - epsilon10 > half_pi) {
- BOOST_THROW_EXCEPTION( projection_exception(error_tolerance_condition) );
- }
- xy_y = cosphi * coslam;
- break;
- }
- xy_x = cosphi * sin(lp_lon);
- }
-
-
- inline void inv(Parameters const& par, T xy_x, T xy_y, T& lp_lon, T& lp_lat) const
- {
- static const T half_pi = detail::half_pi<T>();
- T rh, cosc, sinc;
- if ((sinc = (rh = boost::math::hypot(xy_x, xy_y))) > 1.) {
- if ((sinc - 1.) > epsilon10) {
- BOOST_THROW_EXCEPTION( projection_exception(error_tolerance_condition) );
- }
- sinc = 1.;
- }
- cosc = sqrt(1. - sinc * sinc);
- if (fabs(rh) <= epsilon10) {
- lp_lat = par.phi0;
- lp_lon = 0.0;
- } else {
- switch (this->m_proj_parm.mode) {
- case n_pole:
- xy_y = -xy_y;
- lp_lat = acos(sinc);
- break;
- case s_pole:
- lp_lat = - acos(sinc);
- break;
- case equit:
- lp_lat = xy_y * sinc / rh;
- xy_x *= sinc;
- xy_y = cosc * rh;
- goto sinchk;
- case obliq:
- lp_lat = cosc * this->m_proj_parm.sinph0 + xy_y * sinc * this->m_proj_parm.cosph0 /rh;
- xy_y = (cosc - this->m_proj_parm.sinph0 * lp_lat) * rh;
- xy_x *= sinc * this->m_proj_parm.cosph0;
- sinchk:
- if (fabs(lp_lat) >= 1.)
- lp_lat = lp_lat < 0. ? -half_pi : half_pi;
- else
- lp_lat = asin(lp_lat);
- break;
- }
- lp_lon = (xy_y == 0. && (this->m_proj_parm.mode == obliq || this->m_proj_parm.mode == equit))
- ? (xy_x == 0. ? 0. : xy_x < 0. ? -half_pi : half_pi)
- : atan2(xy_x, xy_y);
- }
- }
- static inline std::string get_name()
- {
- return "ortho_spheroid";
- }
- };
-
- template <typename Parameters, typename T>
- inline void setup_ortho(Parameters& par, par_ortho<T>& proj_parm)
- {
- if (fabs(fabs(par.phi0) - geometry::math::half_pi<T>()) <= epsilon10)
- proj_parm.mode = par.phi0 < 0. ? s_pole : n_pole;
- else if (fabs(par.phi0) > epsilon10) {
- proj_parm.mode = obliq;
- proj_parm.sinph0 = sin(par.phi0);
- proj_parm.cosph0 = cos(par.phi0);
- } else
- proj_parm.mode = equit;
- par.es = 0.;
- }
- }}
- #endif
-
- template <typename T, typename Parameters>
- struct ortho_spheroid : public detail::ortho::base_ortho_spheroid<T, Parameters>
- {
- template <typename Params>
- inline ortho_spheroid(Params const& , Parameters & par)
- {
- detail::ortho::setup_ortho(par, this->m_proj_parm);
- }
- };
- #ifndef DOXYGEN_NO_DETAIL
- namespace detail
- {
-
- BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_FI(srs::spar::proj_ortho, ortho_spheroid)
-
- BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_FI(ortho_entry, ortho_spheroid)
- BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_BEGIN(ortho_init)
- {
- BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(ortho, ortho_entry)
- }
- }
- #endif
- }
- }}
- #endif
|