quarter_meridian.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // Boost.Geometry
  2. // Copyright (c) 2018 Oracle and/or its affiliates.
  3. // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
  4. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  5. // Use, modification and distribution is subject to the Boost Software License,
  6. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. #ifndef BOOST_GEOMETRY_FORMULAS_QUARTER_MERIDIAN_HPP
  9. #define BOOST_GEOMETRY_FORMULAS_QUARTER_MERIDIAN_HPP
  10. #include <boost/geometry/algorithms/not_implemented.hpp>
  11. #include <boost/geometry/core/radius.hpp>
  12. #include <boost/geometry/core/tag.hpp>
  13. #include <boost/geometry/core/tags.hpp>
  14. #include <boost/geometry/formulas/flattening.hpp>
  15. #include <boost/geometry/util/math.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 quarter_meridian
  23. : not_implemented<Tag>
  24. {};
  25. template <typename ResultType, typename Geometry>
  26. struct quarter_meridian<ResultType, Geometry, srs_spheroid_tag>
  27. {
  28. //https://en.wikipedia.org/wiki/Meridian_arc#Generalized_series
  29. //http://www.wolframalpha.com/input/?i=(sum(((2*j-3)!!%2F(2*j)!!)%5E2*n%5E(2*j),j,0,8))
  30. static inline ResultType apply(Geometry const& geometry)
  31. {
  32. //order 8 expansion
  33. ResultType const C[] =
  34. {
  35. 1073741824,
  36. 268435456,
  37. 16777216,
  38. 4194304,
  39. 1638400,
  40. 802816,
  41. 451584,
  42. 278784,
  43. 184041
  44. };
  45. ResultType const c2 = 2;
  46. ResultType const c4 = 4;
  47. ResultType const f = formula::flattening<ResultType>(geometry);
  48. ResultType const n = f / (c2 - f);
  49. ResultType const ab4 = (get_radius<0>(geometry)
  50. + get_radius<2>(geometry)) / c4;
  51. return geometry::math::pi<ResultType>() * ab4 *
  52. horner_evaluate(n*n, C, C+8) / C[0];
  53. }
  54. private :
  55. //TODO: move the following to a more general space to be used by other
  56. // classes as well
  57. /*
  58. Evaluate the polynomial in x using Horner's method.
  59. */
  60. template <typename NT, typename IteratorType>
  61. static inline NT horner_evaluate(NT x,
  62. IteratorType begin,
  63. IteratorType end)
  64. {
  65. NT result(0);
  66. if (begin == end)
  67. {
  68. return result;
  69. }
  70. IteratorType it = end;
  71. do
  72. {
  73. result = result * x + *--it;
  74. }
  75. while (it != begin);
  76. return result;
  77. }
  78. };
  79. } // namespace formula_dispatch
  80. #endif // DOXYGEN_NO_DISPATCH
  81. #ifndef DOXYGEN_NO_DETAIL
  82. namespace formula
  83. {
  84. template <typename ResultType, typename Geometry>
  85. ResultType quarter_meridian(Geometry const& geometry)
  86. {
  87. return formula_dispatch::quarter_meridian<ResultType, Geometry>::apply(geometry);
  88. }
  89. } // namespace formula
  90. #endif // DOXYGEN_NO_DETAIL
  91. }} // namespace boost::geometry
  92. #endif // BOOST_GEOMETRY_FORMULAS_QUARTER_MERIDIAN_HPP