]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // Boost.Geometry (aka GGL, Generic Geometry Library) |
2 | ||
3 | // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. | |
4 | ||
b32b8144 FG |
5 | // This file was modified by Oracle on 2014, 2016, 2017. |
6 | // Modifications copyright (c) 2014-2017, Oracle and/or its affiliates. | |
7c673cae | 7 | |
b32b8144 | 8 | // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle |
7c673cae FG |
9 | // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle |
10 | ||
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) | |
14 | ||
15 | #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_AZIMUTH_HPP | |
16 | #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_AZIMUTH_HPP | |
17 | ||
11fdf7f2 TL |
18 | |
19 | #include <boost/geometry/algorithms/not_implemented.hpp> | |
20 | ||
7c673cae FG |
21 | #include <boost/geometry/core/cs.hpp> |
22 | #include <boost/geometry/core/access.hpp> | |
23 | #include <boost/geometry/core/radian_access.hpp> | |
24 | #include <boost/geometry/core/tags.hpp> | |
25 | ||
b32b8144 FG |
26 | #include <boost/geometry/formulas/spherical.hpp> |
27 | #include <boost/geometry/formulas/vincenty_inverse.hpp> | |
7c673cae | 28 | |
11fdf7f2 TL |
29 | #include <boost/geometry/srs/spheroid.hpp> |
30 | ||
31 | #include <boost/geometry/util/math.hpp> | |
32 | ||
33 | ||
7c673cae FG |
34 | namespace boost { namespace geometry |
35 | { | |
36 | ||
37 | // An azimuth is an angle between a vector/segment from origin to a point of | |
38 | // interest and a reference vector. Typically north-based azimuth is used. | |
39 | // North direction is used as a reference, angle is measured clockwise | |
40 | // (North - 0deg, East - 90deg). For consistency in 2d cartesian CS | |
41 | // the reference vector is Y axis, angle is measured clockwise. | |
42 | // http://en.wikipedia.org/wiki/Azimuth | |
43 | ||
44 | #ifndef DOXYGEN_NO_DISPATCH | |
45 | namespace detail_dispatch | |
46 | { | |
47 | ||
48 | template <typename ReturnType, typename Tag> | |
49 | struct azimuth | |
50 | : not_implemented<Tag> | |
51 | {}; | |
52 | ||
53 | template <typename ReturnType> | |
54 | struct azimuth<ReturnType, geographic_tag> | |
55 | { | |
56 | template <typename P1, typename P2, typename Spheroid> | |
57 | static inline ReturnType apply(P1 const& p1, P2 const& p2, Spheroid const& spheroid) | |
58 | { | |
b32b8144 | 59 | return geometry::formula::vincenty_inverse<ReturnType, false, true>().apply |
7c673cae FG |
60 | ( get_as_radian<0>(p1), get_as_radian<1>(p1), |
61 | get_as_radian<0>(p2), get_as_radian<1>(p2), | |
62 | spheroid ).azimuth; | |
63 | } | |
64 | ||
65 | template <typename P1, typename P2> | |
66 | static inline ReturnType apply(P1 const& p1, P2 const& p2) | |
67 | { | |
68 | return apply(p1, p2, srs::spheroid<ReturnType>()); | |
69 | } | |
70 | }; | |
71 | ||
72 | template <typename ReturnType> | |
73 | struct azimuth<ReturnType, spherical_equatorial_tag> | |
74 | { | |
75 | template <typename P1, typename P2, typename Sphere> | |
76 | static inline ReturnType apply(P1 const& p1, P2 const& p2, Sphere const& /*unused*/) | |
77 | { | |
b32b8144 FG |
78 | return geometry::formula::spherical_azimuth<ReturnType, false> |
79 | ( get_as_radian<0>(p1), get_as_radian<1>(p1), | |
80 | get_as_radian<0>(p2), get_as_radian<1>(p2)).azimuth; | |
7c673cae FG |
81 | } |
82 | ||
83 | template <typename P1, typename P2> | |
84 | static inline ReturnType apply(P1 const& p1, P2 const& p2) | |
85 | { | |
86 | return apply(p1, p2, 0); // dummy model | |
87 | } | |
88 | }; | |
89 | ||
90 | template <typename ReturnType> | |
91 | struct azimuth<ReturnType, spherical_polar_tag> | |
92 | : azimuth<ReturnType, spherical_equatorial_tag> | |
93 | {}; | |
94 | ||
95 | template <typename ReturnType> | |
96 | struct azimuth<ReturnType, cartesian_tag> | |
97 | { | |
98 | template <typename P1, typename P2, typename Plane> | |
99 | static inline ReturnType apply(P1 const& p1, P2 const& p2, Plane const& /*unused*/) | |
100 | { | |
101 | ReturnType x = get<0>(p2) - get<0>(p1); | |
102 | ReturnType y = get<1>(p2) - get<1>(p1); | |
103 | ||
104 | // NOTE: azimuth 0 is at Y axis, increasing right | |
105 | // as in spherical/geographic where 0 is at North axis | |
106 | return atan2(x, y); | |
107 | } | |
108 | ||
109 | template <typename P1, typename P2> | |
110 | static inline ReturnType apply(P1 const& p1, P2 const& p2) | |
111 | { | |
112 | return apply(p1, p2, 0); // dummy model | |
113 | } | |
114 | }; | |
115 | ||
116 | } // detail_dispatch | |
117 | #endif // DOXYGEN_NO_DISPATCH | |
118 | ||
119 | #ifndef DOXYGEN_NO_DETAIL | |
120 | namespace detail | |
121 | { | |
122 | ||
123 | /// Calculate azimuth between two points. | |
124 | /// The result is in radians. | |
125 | template <typename ReturnType, typename Point1, typename Point2> | |
126 | inline ReturnType azimuth(Point1 const& p1, Point2 const& p2) | |
127 | { | |
128 | return detail_dispatch::azimuth | |
129 | < | |
130 | ReturnType, | |
131 | typename geometry::cs_tag<Point1>::type | |
132 | >::apply(p1, p2); | |
133 | } | |
134 | ||
135 | /// Calculate azimuth between two points. | |
136 | /// The result is in radians. | |
137 | template <typename ReturnType, typename Point1, typename Point2, typename Model> | |
138 | inline ReturnType azimuth(Point1 const& p1, Point2 const& p2, Model const& model) | |
139 | { | |
140 | return detail_dispatch::azimuth | |
141 | < | |
142 | ReturnType, | |
143 | typename geometry::cs_tag<Point1>::type | |
144 | >::apply(p1, p2, model); | |
145 | } | |
146 | ||
147 | } // namespace detail | |
148 | #endif // DOXYGEN_NO_DETAIL | |
149 | ||
150 | }} // namespace boost::geometry | |
151 | ||
152 | #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_AZIMUTH_HPP |