Chris@102
|
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
|
Chris@102
|
2
|
Chris@102
|
3 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
|
Chris@102
|
4
|
Chris@102
|
5 // This file was modified by Oracle on 2014.
|
Chris@102
|
6 // Modifications copyright (c) 2014 Oracle and/or its affiliates.
|
Chris@102
|
7
|
Chris@102
|
8 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
|
Chris@102
|
9
|
Chris@102
|
10 // Use, modification and distribution is subject to the Boost Software License,
|
Chris@102
|
11 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@102
|
12 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@102
|
13
|
Chris@102
|
14 #ifndef BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_ANDOYER_HPP
|
Chris@102
|
15 #define BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_ANDOYER_HPP
|
Chris@102
|
16
|
Chris@102
|
17
|
Chris@102
|
18 #include <boost/geometry/core/coordinate_type.hpp>
|
Chris@102
|
19 #include <boost/geometry/core/radian_access.hpp>
|
Chris@102
|
20 #include <boost/geometry/core/radius.hpp>
|
Chris@102
|
21 #include <boost/geometry/core/srs.hpp>
|
Chris@102
|
22
|
Chris@102
|
23 #include <boost/geometry/algorithms/detail/flattening.hpp>
|
Chris@102
|
24
|
Chris@102
|
25 #include <boost/geometry/strategies/distance.hpp>
|
Chris@102
|
26
|
Chris@102
|
27 #include <boost/geometry/util/math.hpp>
|
Chris@102
|
28 #include <boost/geometry/util/promote_floating_point.hpp>
|
Chris@102
|
29 #include <boost/geometry/util/select_calculation_type.hpp>
|
Chris@102
|
30
|
Chris@102
|
31
|
Chris@102
|
32 namespace boost { namespace geometry
|
Chris@102
|
33 {
|
Chris@102
|
34
|
Chris@102
|
35 namespace strategy { namespace distance
|
Chris@102
|
36 {
|
Chris@102
|
37
|
Chris@102
|
38
|
Chris@102
|
39 /*!
|
Chris@102
|
40 \brief Point-point distance approximation taking flattening into account
|
Chris@102
|
41 \ingroup distance
|
Chris@102
|
42 \tparam Spheroid The reference spheroid model
|
Chris@102
|
43 \tparam CalculationType \tparam_calculation
|
Chris@102
|
44 \author After Andoyer, 19xx, republished 1950, republished by Meeus, 1999
|
Chris@102
|
45 \note Although not so well-known, the approximation is very good: in all cases the results
|
Chris@102
|
46 are about the same as Vincenty. In my (Barend's) testcases the results didn't differ more than 6 m
|
Chris@102
|
47 \see http://nacc.upc.es/tierra/node16.html
|
Chris@102
|
48 \see http://sci.tech-archive.net/Archive/sci.geo.satellite-nav/2004-12/2724.html
|
Chris@102
|
49 \see http://home.att.net/~srschmitt/great_circle_route.html (implementation)
|
Chris@102
|
50 \see http://www.codeguru.com/Cpp/Cpp/algorithms/article.php/c5115 (implementation)
|
Chris@102
|
51 \see http://futureboy.homeip.net/frinksamp/navigation.frink (implementation)
|
Chris@102
|
52 \see http://www.voidware.com/earthdist.htm (implementation)
|
Chris@102
|
53 */
|
Chris@102
|
54 template
|
Chris@102
|
55 <
|
Chris@102
|
56 typename Spheroid,
|
Chris@102
|
57 typename CalculationType = void
|
Chris@102
|
58 >
|
Chris@102
|
59 class andoyer
|
Chris@102
|
60 {
|
Chris@102
|
61 public :
|
Chris@102
|
62 template <typename Point1, typename Point2>
|
Chris@102
|
63 struct calculation_type
|
Chris@102
|
64 : promote_floating_point
|
Chris@102
|
65 <
|
Chris@102
|
66 typename select_calculation_type
|
Chris@102
|
67 <
|
Chris@102
|
68 Point1,
|
Chris@102
|
69 Point2,
|
Chris@102
|
70 CalculationType
|
Chris@102
|
71 >::type
|
Chris@102
|
72 >
|
Chris@102
|
73 {};
|
Chris@102
|
74
|
Chris@102
|
75 typedef Spheroid model_type;
|
Chris@102
|
76
|
Chris@102
|
77 inline andoyer()
|
Chris@102
|
78 : m_spheroid()
|
Chris@102
|
79 {}
|
Chris@102
|
80
|
Chris@102
|
81 explicit inline andoyer(Spheroid const& spheroid)
|
Chris@102
|
82 : m_spheroid(spheroid)
|
Chris@102
|
83 {}
|
Chris@102
|
84
|
Chris@102
|
85
|
Chris@102
|
86 template <typename Point1, typename Point2>
|
Chris@102
|
87 inline typename calculation_type<Point1, Point2>::type
|
Chris@102
|
88 apply(Point1 const& point1, Point2 const& point2) const
|
Chris@102
|
89 {
|
Chris@102
|
90 return calc<typename calculation_type<Point1, Point2>::type>
|
Chris@102
|
91 (
|
Chris@102
|
92 get_as_radian<0>(point1), get_as_radian<1>(point1),
|
Chris@102
|
93 get_as_radian<0>(point2), get_as_radian<1>(point2)
|
Chris@102
|
94 );
|
Chris@102
|
95 }
|
Chris@102
|
96
|
Chris@102
|
97 inline Spheroid const& model() const
|
Chris@102
|
98 {
|
Chris@102
|
99 return m_spheroid;
|
Chris@102
|
100 }
|
Chris@102
|
101
|
Chris@102
|
102 private :
|
Chris@102
|
103 template <typename CT, typename T>
|
Chris@102
|
104 inline CT calc(T const& lon1,
|
Chris@102
|
105 T const& lat1,
|
Chris@102
|
106 T const& lon2,
|
Chris@102
|
107 T const& lat2) const
|
Chris@102
|
108 {
|
Chris@102
|
109 CT const G = (lat1 - lat2) / 2.0;
|
Chris@102
|
110 CT const lambda = (lon1 - lon2) / 2.0;
|
Chris@102
|
111
|
Chris@102
|
112 if (geometry::math::equals(lambda, 0.0)
|
Chris@102
|
113 && geometry::math::equals(G, 0.0))
|
Chris@102
|
114 {
|
Chris@102
|
115 return 0.0;
|
Chris@102
|
116 }
|
Chris@102
|
117
|
Chris@102
|
118 CT const F = (lat1 + lat2) / 2.0;
|
Chris@102
|
119
|
Chris@102
|
120 CT const sinG2 = math::sqr(sin(G));
|
Chris@102
|
121 CT const cosG2 = math::sqr(cos(G));
|
Chris@102
|
122 CT const sinF2 = math::sqr(sin(F));
|
Chris@102
|
123 CT const cosF2 = math::sqr(cos(F));
|
Chris@102
|
124 CT const sinL2 = math::sqr(sin(lambda));
|
Chris@102
|
125 CT const cosL2 = math::sqr(cos(lambda));
|
Chris@102
|
126
|
Chris@102
|
127 CT const S = sinG2 * cosL2 + cosF2 * sinL2;
|
Chris@102
|
128 CT const C = cosG2 * cosL2 + sinF2 * sinL2;
|
Chris@102
|
129
|
Chris@102
|
130 CT const c0 = 0;
|
Chris@102
|
131 CT const c1 = 1;
|
Chris@102
|
132 CT const c2 = 2;
|
Chris@102
|
133 CT const c3 = 3;
|
Chris@102
|
134
|
Chris@102
|
135 if (geometry::math::equals(S, c0) || geometry::math::equals(C, c0))
|
Chris@102
|
136 {
|
Chris@102
|
137 return c0;
|
Chris@102
|
138 }
|
Chris@102
|
139
|
Chris@102
|
140 CT const radius_a = CT(get_radius<0>(m_spheroid));
|
Chris@102
|
141 CT const flattening = geometry::detail::flattening<CT>(m_spheroid);
|
Chris@102
|
142
|
Chris@102
|
143 CT const omega = atan(math::sqrt(S / C));
|
Chris@102
|
144 CT const r3 = c3 * math::sqrt(S * C) / omega; // not sure if this is r or greek nu
|
Chris@102
|
145 CT const D = c2 * omega * radius_a;
|
Chris@102
|
146 CT const H1 = (r3 - c1) / (c2 * C);
|
Chris@102
|
147 CT const H2 = (r3 + c1) / (c2 * S);
|
Chris@102
|
148
|
Chris@102
|
149 return D * (c1 + flattening * (H1 * sinF2 * cosG2 - H2 * cosF2 * sinG2) );
|
Chris@102
|
150 }
|
Chris@102
|
151
|
Chris@102
|
152 Spheroid m_spheroid;
|
Chris@102
|
153 };
|
Chris@102
|
154
|
Chris@102
|
155
|
Chris@102
|
156 #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
|
Chris@102
|
157 namespace services
|
Chris@102
|
158 {
|
Chris@102
|
159
|
Chris@102
|
160 template <typename Spheroid, typename CalculationType>
|
Chris@102
|
161 struct tag<andoyer<Spheroid, CalculationType> >
|
Chris@102
|
162 {
|
Chris@102
|
163 typedef strategy_tag_distance_point_point type;
|
Chris@102
|
164 };
|
Chris@102
|
165
|
Chris@102
|
166
|
Chris@102
|
167 template <typename Spheroid, typename CalculationType, typename P1, typename P2>
|
Chris@102
|
168 struct return_type<andoyer<Spheroid, CalculationType>, P1, P2>
|
Chris@102
|
169 : andoyer<Spheroid, CalculationType>::template calculation_type<P1, P2>
|
Chris@102
|
170 {};
|
Chris@102
|
171
|
Chris@102
|
172
|
Chris@102
|
173 template <typename Spheroid, typename CalculationType>
|
Chris@102
|
174 struct comparable_type<andoyer<Spheroid, CalculationType> >
|
Chris@102
|
175 {
|
Chris@102
|
176 typedef andoyer<Spheroid, CalculationType> type;
|
Chris@102
|
177 };
|
Chris@102
|
178
|
Chris@102
|
179
|
Chris@102
|
180 template <typename Spheroid, typename CalculationType>
|
Chris@102
|
181 struct get_comparable<andoyer<Spheroid, CalculationType> >
|
Chris@102
|
182 {
|
Chris@102
|
183 static inline andoyer<Spheroid, CalculationType> apply(andoyer<Spheroid, CalculationType> const& input)
|
Chris@102
|
184 {
|
Chris@102
|
185 return input;
|
Chris@102
|
186 }
|
Chris@102
|
187 };
|
Chris@102
|
188
|
Chris@102
|
189 template <typename Spheroid, typename CalculationType, typename P1, typename P2>
|
Chris@102
|
190 struct result_from_distance<andoyer<Spheroid, CalculationType>, P1, P2>
|
Chris@102
|
191 {
|
Chris@102
|
192 template <typename T>
|
Chris@102
|
193 static inline typename return_type<andoyer<Spheroid, CalculationType>, P1, P2>::type
|
Chris@102
|
194 apply(andoyer<Spheroid, CalculationType> const& , T const& value)
|
Chris@102
|
195 {
|
Chris@102
|
196 return value;
|
Chris@102
|
197 }
|
Chris@102
|
198 };
|
Chris@102
|
199
|
Chris@102
|
200
|
Chris@102
|
201 template <typename Point1, typename Point2>
|
Chris@102
|
202 struct default_strategy<point_tag, point_tag, Point1, Point2, geographic_tag, geographic_tag>
|
Chris@102
|
203 {
|
Chris@102
|
204 typedef strategy::distance::andoyer
|
Chris@102
|
205 <
|
Chris@102
|
206 srs::spheroid
|
Chris@102
|
207 <
|
Chris@102
|
208 typename select_coordinate_type<Point1, Point2>::type
|
Chris@102
|
209 >
|
Chris@102
|
210 > type;
|
Chris@102
|
211 };
|
Chris@102
|
212
|
Chris@102
|
213
|
Chris@102
|
214 } // namespace services
|
Chris@102
|
215 #endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
|
Chris@102
|
216
|
Chris@102
|
217
|
Chris@102
|
218 }} // namespace strategy::distance
|
Chris@102
|
219
|
Chris@102
|
220
|
Chris@102
|
221 }} // namespace boost::geometry
|
Chris@102
|
222
|
Chris@102
|
223
|
Chris@102
|
224 #endif // BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_ANDOYER_HPP
|