side_by_cross_track.hpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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-2017.
  4. // Modifications copyright (c) 2014-2017, 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/cs.hpp>
  13. #include <boost/geometry/core/access.hpp>
  14. #include <boost/geometry/core/radian_access.hpp>
  15. #include <boost/geometry/formulas/spherical.hpp>
  16. #include <boost/geometry/util/math.hpp>
  17. #include <boost/geometry/util/promote_floating_point.hpp>
  18. #include <boost/geometry/util/select_calculation_type.hpp>
  19. #include <boost/geometry/strategies/side.hpp>
  20. //#include <boost/geometry/strategies/concepts/side_concept.hpp>
  21. namespace boost { namespace geometry
  22. {
  23. namespace strategy { namespace side
  24. {
  25. /*!
  26. \brief Check at which side of a Great Circle segment a point lies
  27. left of segment (> 0), right of segment (< 0), on segment (0)
  28. \ingroup strategies
  29. \tparam CalculationType \tparam_calculation
  30. */
  31. template <typename CalculationType = void>
  32. class side_by_cross_track
  33. {
  34. public :
  35. template <typename P1, typename P2, typename P>
  36. static inline int apply(P1 const& p1, P2 const& p2, P const& p)
  37. {
  38. typedef typename promote_floating_point
  39. <
  40. typename select_calculation_type_alt
  41. <
  42. CalculationType,
  43. P1, P2, P
  44. >::type
  45. >::type calc_t;
  46. calc_t d1 = 0.001; // m_strategy.apply(sp1, p);
  47. calc_t lon1 = geometry::get_as_radian<0>(p1);
  48. calc_t lat1 = geometry::get_as_radian<1>(p1);
  49. calc_t lon2 = geometry::get_as_radian<0>(p2);
  50. calc_t lat2 = geometry::get_as_radian<1>(p2);
  51. calc_t lon = geometry::get_as_radian<0>(p);
  52. calc_t lat = geometry::get_as_radian<1>(p);
  53. calc_t crs_AD = geometry::formula::spherical_azimuth<calc_t, false>
  54. (lon1, lat1, lon, lat).azimuth;
  55. calc_t crs_AB = geometry::formula::spherical_azimuth<calc_t, false>
  56. (lon1, lat1, lon2, lat2).azimuth;
  57. calc_t XTD = asin(sin(d1) * sin(crs_AD - crs_AB));
  58. return math::equals(XTD, 0) ? 0 : XTD < 0 ? 1 : -1;
  59. }
  60. };
  61. }} // namespace strategy::side
  62. }} // namespace boost::geometry
  63. #endif // BOOST_GEOMETRY_STRATEGIES_SPHERICAL_SIDE_BY_CROSS_TRACK_HPP