1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2011-2012 Barend Gehrels, Amsterdam, the Netherlands.
5 // This file was modified by Oracle on 2016.
6 // Modifications copyright (c) 2016, Oracle and/or its affiliates.
7 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
9 // Use, modification and distribution is subject to the Boost Software License,
10 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
11 // http://www.boost.org/LICENSE_1_0.txt)
13 #ifndef BOOST_GEOMETRY_STRATEGIES_SPHERICAL_SSF_HPP
14 #define BOOST_GEOMETRY_STRATEGIES_SPHERICAL_SSF_HPP
17 #include <boost/geometry/core/cs.hpp>
18 #include <boost/geometry/core/access.hpp>
19 #include <boost/geometry/core/radian_access.hpp>
21 #include <boost/geometry/util/math.hpp>
22 #include <boost/geometry/util/promote_floating_point.hpp>
23 #include <boost/geometry/util/select_calculation_type.hpp>
25 #include <boost/geometry/strategies/side.hpp>
26 //#include <boost/geometry/strategies/concepts/side_concept.hpp>
29 namespace boost { namespace geometry
33 namespace strategy { namespace side
36 #ifndef DOXYGEN_NO_DETAIL
41 int spherical_side_formula(T const& lambda1, T const& delta1,
42 T const& lambda2, T const& delta2,
43 T const& lambda, T const& delta)
45 // Create temporary points (vectors) on unit a sphere
46 T const cos_delta1 = cos(delta1);
47 T const c1x = cos_delta1 * cos(lambda1);
48 T const c1y = cos_delta1 * sin(lambda1);
49 T const c1z = sin(delta1);
51 T const cos_delta2 = cos(delta2);
52 T const c2x = cos_delta2 * cos(lambda2);
53 T const c2y = cos_delta2 * sin(lambda2);
54 T const c2z = sin(delta2);
56 // (Third point is converted directly)
57 T const cos_delta = cos(delta);
59 // Apply the "Spherical Side Formula" as presented on my blog
61 = (c1y * c2z - c1z * c2y) * cos_delta * cos(lambda)
62 + (c1z * c2x - c1x * c2z) * cos_delta * sin(lambda)
63 + (c1x * c2y - c1y * c2x) * sin(delta);
66 return math::equals(dist, zero) ? 0
72 #endif // DOXYGEN_NO_DETAIL
75 \brief Check at which side of a Great Circle segment a point lies
76 left of segment (> 0), right of segment (< 0), on segment (0)
78 \tparam CalculationType \tparam_calculation
80 template <typename CalculationType = void>
81 class spherical_side_formula
85 template <typename P1, typename P2, typename P>
86 static inline int apply(P1 const& p1, P2 const& p2, P const& p)
88 typedef typename promote_floating_point
90 typename select_calculation_type_alt
95 >::type calculation_type;
97 calculation_type const lambda1 = get_as_radian<0>(p1);
98 calculation_type const delta1 = get_as_radian<1>(p1);
99 calculation_type const lambda2 = get_as_radian<0>(p2);
100 calculation_type const delta2 = get_as_radian<1>(p2);
101 calculation_type const lambda = get_as_radian<0>(p);
102 calculation_type const delta = get_as_radian<1>(p);
104 return detail::spherical_side_formula(lambda1, delta1,
111 #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
115 /*template <typename CalculationType>
116 struct default_strategy<spherical_polar_tag, CalculationType>
118 typedef spherical_side_formula<CalculationType> type;
121 template <typename CalculationType>
122 struct default_strategy<spherical_equatorial_tag, CalculationType>
124 typedef spherical_side_formula<CalculationType> type;
127 template <typename CalculationType>
128 struct default_strategy<geographic_tag, CalculationType>
130 typedef spherical_side_formula<CalculationType> type;
136 }} // namespace strategy::side
138 }} // namespace boost::geometry
141 #endif // BOOST_GEOMETRY_STRATEGIES_SPHERICAL_SSF_HPP