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, 2016, 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_ALGORITHMS_DETAIL_AZIMUTH_HPP
16 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_AZIMUTH_HPP
18 #include <boost/geometry/core/cs.hpp>
19 #include <boost/geometry/core/access.hpp>
20 #include <boost/geometry/core/radian_access.hpp>
21 #include <boost/geometry/core/tags.hpp>
23 #include <boost/geometry/util/math.hpp>
25 #include <boost/geometry/algorithms/not_implemented.hpp>
27 #include <boost/geometry/formulas/spherical.hpp>
28 #include <boost/geometry/formulas/vincenty_inverse.hpp>
30 namespace boost { namespace geometry
33 // An azimuth is an angle between a vector/segment from origin to a point of
34 // interest and a reference vector. Typically north-based azimuth is used.
35 // North direction is used as a reference, angle is measured clockwise
36 // (North - 0deg, East - 90deg). For consistency in 2d cartesian CS
37 // the reference vector is Y axis, angle is measured clockwise.
38 // http://en.wikipedia.org/wiki/Azimuth
40 #ifndef DOXYGEN_NO_DISPATCH
41 namespace detail_dispatch
44 template <typename ReturnType, typename Tag>
46 : not_implemented<Tag>
49 template <typename ReturnType>
50 struct azimuth<ReturnType, geographic_tag>
52 template <typename P1, typename P2, typename Spheroid>
53 static inline ReturnType apply(P1 const& p1, P2 const& p2, Spheroid const& spheroid)
55 return geometry::formula::vincenty_inverse<ReturnType, false, true>().apply
56 ( get_as_radian<0>(p1), get_as_radian<1>(p1),
57 get_as_radian<0>(p2), get_as_radian<1>(p2),
61 template <typename P1, typename P2>
62 static inline ReturnType apply(P1 const& p1, P2 const& p2)
64 return apply(p1, p2, srs::spheroid<ReturnType>());
68 template <typename ReturnType>
69 struct azimuth<ReturnType, spherical_equatorial_tag>
71 template <typename P1, typename P2, typename Sphere>
72 static inline ReturnType apply(P1 const& p1, P2 const& p2, Sphere const& /*unused*/)
74 return geometry::formula::spherical_azimuth<ReturnType, false>
75 ( get_as_radian<0>(p1), get_as_radian<1>(p1),
76 get_as_radian<0>(p2), get_as_radian<1>(p2)).azimuth;
79 template <typename P1, typename P2>
80 static inline ReturnType apply(P1 const& p1, P2 const& p2)
82 return apply(p1, p2, 0); // dummy model
86 template <typename ReturnType>
87 struct azimuth<ReturnType, spherical_polar_tag>
88 : azimuth<ReturnType, spherical_equatorial_tag>
91 template <typename ReturnType>
92 struct azimuth<ReturnType, cartesian_tag>
94 template <typename P1, typename P2, typename Plane>
95 static inline ReturnType apply(P1 const& p1, P2 const& p2, Plane const& /*unused*/)
97 ReturnType x = get<0>(p2) - get<0>(p1);
98 ReturnType y = get<1>(p2) - get<1>(p1);
100 // NOTE: azimuth 0 is at Y axis, increasing right
101 // as in spherical/geographic where 0 is at North axis
105 template <typename P1, typename P2>
106 static inline ReturnType apply(P1 const& p1, P2 const& p2)
108 return apply(p1, p2, 0); // dummy model
113 #endif // DOXYGEN_NO_DISPATCH
115 #ifndef DOXYGEN_NO_DETAIL
119 /// Calculate azimuth between two points.
120 /// The result is in radians.
121 template <typename ReturnType, typename Point1, typename Point2>
122 inline ReturnType azimuth(Point1 const& p1, Point2 const& p2)
124 return detail_dispatch::azimuth
127 typename geometry::cs_tag<Point1>::type
131 /// Calculate azimuth between two points.
132 /// The result is in radians.
133 template <typename ReturnType, typename Point1, typename Point2, typename Model>
134 inline ReturnType azimuth(Point1 const& p1, Point2 const& p2, Model const& model)
136 return detail_dispatch::azimuth
139 typename geometry::cs_tag<Point1>::type
140 >::apply(p1, p2, model);
143 } // namespace detail
144 #endif // DOXYGEN_NO_DETAIL
146 }} // namespace boost::geometry
148 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_AZIMUTH_HPP