side_by_cross_track.hpp 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
  3. // This file was modified by Oracle on 2014-2021.
  4. // Modifications copyright (c) 2014-2021, Oracle and/or its affiliates.
  5. // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
  6. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  7. // Use, modification and distribution is subject to the Boost Software License,
  8. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  9. // http://www.boost.org/LICENSE_1_0.txt)
  10. #ifndef BOOST_GEOMETRY_STRATEGIES_SPHERICAL_SIDE_BY_CROSS_TRACK_HPP
  11. #define BOOST_GEOMETRY_STRATEGIES_SPHERICAL_SIDE_BY_CROSS_TRACK_HPP
  12. #include <boost/geometry/core/access.hpp>
  13. #include <boost/geometry/core/coordinate_promotion.hpp>
  14. #include <boost/geometry/core/cs.hpp>
  15. #include <boost/geometry/core/radian_access.hpp>
  16. #include <boost/geometry/formulas/spherical.hpp>
  17. //#include <boost/geometry/strategies/concepts/side_concept.hpp>
  18. #include <boost/geometry/strategies/side.hpp>
  19. #include <boost/geometry/strategies/spherical/point_in_point.hpp>
  20. #include <boost/geometry/util/math.hpp>
  21. #include <boost/geometry/util/select_calculation_type.hpp>
  22. namespace boost { namespace geometry
  23. {
  24. namespace strategy { namespace side
  25. {
  26. /*!
  27. \brief Check at which side of a Great Circle segment a point lies
  28. left of segment (> 0), right of segment (< 0), on segment (0)
  29. \ingroup strategies
  30. \tparam CalculationType \tparam_calculation
  31. */
  32. template <typename CalculationType = void>
  33. class side_by_cross_track
  34. {
  35. public :
  36. template <typename P1, typename P2, typename P>
  37. static inline int apply(P1 const& p1, P2 const& p2, P const& p)
  38. {
  39. typedef strategy::within::spherical_point_point
  40. equals_point_point_strategy_type;
  41. if (equals_point_point_strategy_type::apply(p, p1)
  42. || equals_point_point_strategy_type::apply(p, p2)
  43. || equals_point_point_strategy_type::apply(p1, p2))
  44. {
  45. return 0;
  46. }
  47. typedef typename promote_floating_point
  48. <
  49. typename select_calculation_type_alt
  50. <
  51. CalculationType,
  52. P1, P2, P
  53. >::type
  54. >::type calc_t;
  55. calc_t d1 = 0.001; // m_strategy.apply(sp1, p);
  56. calc_t lon1 = geometry::get_as_radian<0>(p1);
  57. calc_t lat1 = geometry::get_as_radian<1>(p1);
  58. calc_t lon2 = geometry::get_as_radian<0>(p2);
  59. calc_t lat2 = geometry::get_as_radian<1>(p2);
  60. calc_t lon = geometry::get_as_radian<0>(p);
  61. calc_t lat = geometry::get_as_radian<1>(p);
  62. calc_t crs_AD = geometry::formula::spherical_azimuth<calc_t, false>
  63. (lon1, lat1, lon, lat).azimuth;
  64. calc_t crs_AB = geometry::formula::spherical_azimuth<calc_t, false>
  65. (lon1, lat1, lon2, lat2).azimuth;
  66. calc_t XTD = asin(sin(d1) * sin(crs_AD - crs_AB));
  67. return math::equals(XTD, 0) ? 0 : XTD < 0 ? 1 : -1;
  68. }
  69. };
  70. }} // namespace strategy::side
  71. }} // namespace boost::geometry
  72. #endif // BOOST_GEOMETRY_STRATEGIES_SPHERICAL_SIDE_BY_CROSS_TRACK_HPP