1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
5 // This file was modified by Oracle on 2014-2017.
6 // Modifications copyright (c) 2014-2017, Oracle and/or its affiliates.
8 // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
9 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
11 // Use, modification and distribution is subject to the Boost Software License,
12 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
13 // http://www.boost.org/LICENSE_1_0.txt)
15 #ifndef BOOST_GEOMETRY_STRATEGIES_SPHERICAL_SIDE_BY_CROSS_TRACK_HPP
16 #define BOOST_GEOMETRY_STRATEGIES_SPHERICAL_SIDE_BY_CROSS_TRACK_HPP
18 #include <boost/geometry/core/cs.hpp>
19 #include <boost/geometry/core/access.hpp>
20 #include <boost/geometry/core/radian_access.hpp>
22 #include <boost/geometry/formulas/spherical.hpp>
24 #include <boost/geometry/util/math.hpp>
25 #include <boost/geometry/util/promote_floating_point.hpp>
26 #include <boost/geometry/util/select_calculation_type.hpp>
28 #include <boost/geometry/strategies/side.hpp>
29 //#include <boost/geometry/strategies/concepts/side_concept.hpp>
32 namespace boost { namespace geometry
36 namespace strategy { namespace side
40 \brief Check at which side of a Great Circle segment a point lies
41 left of segment (> 0), right of segment (< 0), on segment (0)
43 \tparam CalculationType \tparam_calculation
45 template <typename CalculationType = void>
46 class side_by_cross_track
50 template <typename P1, typename P2, typename P>
51 static inline int apply(P1 const& p1, P2 const& p2, P const& p)
53 typedef typename promote_floating_point
55 typename select_calculation_type_alt
62 calc_t d1 = 0.001; // m_strategy.apply(sp1, p);
64 calc_t lon1 = geometry::get_as_radian<0>(p1);
65 calc_t lat1 = geometry::get_as_radian<1>(p1);
66 calc_t lon2 = geometry::get_as_radian<0>(p2);
67 calc_t lat2 = geometry::get_as_radian<1>(p2);
68 calc_t lon = geometry::get_as_radian<0>(p);
69 calc_t lat = geometry::get_as_radian<1>(p);
71 calc_t crs_AD = geometry::formula::spherical_azimuth<calc_t, false>
72 (lon1, lat1, lon, lat).azimuth;
74 calc_t crs_AB = geometry::formula::spherical_azimuth<calc_t, false>
75 (lon1, lat1, lon2, lat2).azimuth;
77 calc_t XTD = asin(sin(d1) * sin(crs_AD - crs_AB));
79 return math::equals(XTD, 0) ? 0 : XTD < 0 ? 1 : -1;
83 }} // namespace strategy::side
86 }} // namespace boost::geometry
89 #endif // BOOST_GEOMETRY_STRATEGIES_SPHERICAL_SIDE_BY_CROSS_TRACK_HPP