authalic_radius_sqr.hpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // Boost.Geometry
  2. // Copyright (c) 2017 Oracle and/or its affiliates.
  3. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  4. // Use, modification and distribution is subject to the Boost Software License,
  5. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. #ifndef BOOST_GEOMETRY_FORMULAS_AUTHALIC_RADIUS_SQR_HPP
  8. #define BOOST_GEOMETRY_FORMULAS_AUTHALIC_RADIUS_SQR_HPP
  9. #include <boost/geometry/core/radius.hpp>
  10. #include <boost/geometry/core/tag.hpp>
  11. #include <boost/geometry/core/tags.hpp>
  12. #include <boost/geometry/formulas/eccentricity_sqr.hpp>
  13. #include <boost/geometry/util/math.hpp>
  14. #include <boost/geometry/algorithms/not_implemented.hpp>
  15. #include <boost/math/special_functions/atanh.hpp>
  16. namespace boost { namespace geometry
  17. {
  18. #ifndef DOXYGEN_NO_DISPATCH
  19. namespace formula_dispatch
  20. {
  21. template <typename ResultType, typename Geometry, typename Tag = typename tag<Geometry>::type>
  22. struct authalic_radius_sqr
  23. : not_implemented<Tag>
  24. {};
  25. template <typename ResultType, typename Geometry>
  26. struct authalic_radius_sqr<ResultType, Geometry, srs_sphere_tag>
  27. {
  28. static inline ResultType apply(Geometry const& geometry)
  29. {
  30. return math::sqr<ResultType>(get_radius<0>(geometry));
  31. }
  32. };
  33. template <typename ResultType, typename Geometry>
  34. struct authalic_radius_sqr<ResultType, Geometry, srs_spheroid_tag>
  35. {
  36. static inline ResultType apply(Geometry const& geometry)
  37. {
  38. ResultType const a2 = math::sqr<ResultType>(get_radius<0>(geometry));
  39. ResultType const e2 = formula::eccentricity_sqr<ResultType>(geometry);
  40. return apply(a2, e2);
  41. }
  42. static inline ResultType apply(ResultType const& a2, ResultType const& e2)
  43. {
  44. ResultType const c0 = 0;
  45. if (math::equals(e2, c0))
  46. {
  47. return a2;
  48. }
  49. ResultType const e = math::sqrt(e2);
  50. ResultType const c2 = 2;
  51. //ResultType const b2 = math::sqr(get_radius<2>(geometry));
  52. //return a2 / c2 + b2 * boost::math::atanh(e) / (c2 * e);
  53. ResultType const c1 = 1;
  54. return (a2 / c2) * ( c1 + (c1 - e2) * boost::math::atanh(e) / e );
  55. }
  56. };
  57. } // namespace formula_dispatch
  58. #endif // DOXYGEN_NO_DISPATCH
  59. #ifndef DOXYGEN_NO_DETAIL
  60. namespace formula
  61. {
  62. template <typename ResultType, typename Geometry>
  63. inline ResultType authalic_radius_sqr(Geometry const& geometry)
  64. {
  65. return formula_dispatch::authalic_radius_sqr<ResultType, Geometry>::apply(geometry);
  66. }
  67. } // namespace formula
  68. #endif // DOXYGEN_NO_DETAIL
  69. }} // namespace boost::geometry
  70. #endif // BOOST_GEOMETRY_FORMULAS_AUTHALIC_RADIUS_SQR_HPP