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/spherical/disjoint_segment_box.hpp>
27 #include <boost/geometry/strategies/spherical/envelope_segment.hpp>
28 //#include <boost/geometry/strategies/concepts/side_concept.hpp>
31 namespace boost { namespace geometry
35 namespace strategy { namespace side
38 #ifndef DOXYGEN_NO_DETAIL
43 int spherical_side_formula(T const& lambda1, T const& delta1,
44 T const& lambda2, T const& delta2,
45 T const& lambda, T const& delta)
47 // Create temporary points (vectors) on unit a sphere
48 T const cos_delta1 = cos(delta1);
49 T const c1x = cos_delta1 * cos(lambda1);
50 T const c1y = cos_delta1 * sin(lambda1);
51 T const c1z = sin(delta1);
53 T const cos_delta2 = cos(delta2);
54 T const c2x = cos_delta2 * cos(lambda2);
55 T const c2y = cos_delta2 * sin(lambda2);
56 T const c2z = sin(delta2);
58 // (Third point is converted directly)
59 T const cos_delta = cos(delta);
61 // Apply the "Spherical Side Formula" as presented on my blog
63 = (c1y * c2z - c1z * c2y) * cos_delta * cos(lambda)
64 + (c1z * c2x - c1x * c2z) * cos_delta * sin(lambda)
65 + (c1x * c2y - c1y * c2x) * sin(delta);
68 return math::equals(dist, zero) ? 0
74 #endif // DOXYGEN_NO_DETAIL
77 \brief Check at which side of a Great Circle segment a point lies
78 left of segment (> 0), right of segment (< 0), on segment (0)
80 \tparam CalculationType \tparam_calculation
82 template <typename CalculationType = void>
83 class spherical_side_formula
87 typedef strategy::envelope::spherical_segment<CalculationType> envelope_strategy_type;
89 static inline envelope_strategy_type get_envelope_strategy()
91 return envelope_strategy_type();
94 typedef strategy::disjoint::segment_box_spherical disjoint_strategy_type;
96 static inline disjoint_strategy_type get_disjoint_strategy()
98 return disjoint_strategy_type();
101 template <typename P1, typename P2, typename P>
102 static inline int apply(P1 const& p1, P2 const& p2, P const& p)
104 typedef typename promote_floating_point
106 typename select_calculation_type_alt
111 >::type calculation_type;
113 calculation_type const lambda1 = get_as_radian<0>(p1);
114 calculation_type const delta1 = get_as_radian<1>(p1);
115 calculation_type const lambda2 = get_as_radian<0>(p2);
116 calculation_type const delta2 = get_as_radian<1>(p2);
117 calculation_type const lambda = get_as_radian<0>(p);
118 calculation_type const delta = get_as_radian<1>(p);
120 return detail::spherical_side_formula(lambda1, delta1,
127 #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
131 /*template <typename CalculationType>
132 struct default_strategy<spherical_polar_tag, CalculationType>
134 typedef spherical_side_formula<CalculationType> type;
137 template <typename CalculationType>
138 struct default_strategy<spherical_equatorial_tag, CalculationType>
140 typedef spherical_side_formula<CalculationType> type;
143 template <typename CalculationType>
144 struct default_strategy<geographic_tag, CalculationType>
146 typedef spherical_side_formula<CalculationType> type;
152 }} // namespace strategy::side
154 }} // namespace boost::geometry
157 #endif // BOOST_GEOMETRY_STRATEGIES_SPHERICAL_SSF_HPP