annotate DEPENDENCIES/generic/include/boost/geometry/algorithms/detail/azimuth.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents f46d142149f5
children
rev   line source
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_ALGORITHMS_DETAIL_AZIMUTH_HPP
Chris@102 15 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_AZIMUTH_HPP
Chris@102 16
Chris@102 17 #include <boost/geometry/core/cs.hpp>
Chris@102 18 #include <boost/geometry/core/access.hpp>
Chris@102 19 #include <boost/geometry/core/radian_access.hpp>
Chris@102 20 #include <boost/geometry/core/tags.hpp>
Chris@102 21
Chris@102 22 #include <boost/geometry/util/math.hpp>
Chris@102 23
Chris@102 24 #include <boost/geometry/algorithms/not_implemented.hpp>
Chris@102 25 #include <boost/geometry/algorithms/detail/vincenty_inverse.hpp>
Chris@102 26
Chris@102 27 namespace boost { namespace geometry
Chris@102 28 {
Chris@102 29
Chris@102 30 // An azimuth is an angle between a vector/segment from origin to a point of
Chris@102 31 // interest and a reference vector. Typically north-based azimuth is used.
Chris@102 32 // North direction is used as a reference, angle is measured clockwise
Chris@102 33 // (North - 0deg, East - 90deg). For consistency in 2d cartesian CS
Chris@102 34 // the reference vector is Y axis, angle is measured clockwise.
Chris@102 35 // http://en.wikipedia.org/wiki/Azimuth
Chris@102 36
Chris@102 37 #ifndef DOXYGEN_NO_DISPATCH
Chris@102 38 namespace detail_dispatch
Chris@102 39 {
Chris@102 40
Chris@102 41 template <typename ReturnType, typename Tag>
Chris@102 42 struct azimuth
Chris@102 43 : not_implemented<Tag>
Chris@102 44 {};
Chris@102 45
Chris@102 46 template <typename ReturnType>
Chris@102 47 struct azimuth<ReturnType, geographic_tag>
Chris@102 48 {
Chris@102 49 template <typename P1, typename P2, typename Spheroid>
Chris@102 50 static inline ReturnType apply(P1 const& p1, P2 const& p2, Spheroid const& spheroid)
Chris@102 51 {
Chris@102 52 return geometry::detail::vincenty_inverse<ReturnType>
Chris@102 53 ( get_as_radian<0>(p1), get_as_radian<1>(p1),
Chris@102 54 get_as_radian<0>(p2), get_as_radian<1>(p2),
Chris@102 55 spheroid ).azimuth12();
Chris@102 56 }
Chris@102 57
Chris@102 58 template <typename P1, typename P2>
Chris@102 59 static inline ReturnType apply(P1 const& p1, P2 const& p2)
Chris@102 60 {
Chris@102 61 return apply(p1, p2, srs::spheroid<ReturnType>());
Chris@102 62 }
Chris@102 63 };
Chris@102 64
Chris@102 65 template <typename ReturnType>
Chris@102 66 struct azimuth<ReturnType, spherical_equatorial_tag>
Chris@102 67 {
Chris@102 68 template <typename P1, typename P2, typename Sphere>
Chris@102 69 static inline ReturnType apply(P1 const& p1, P2 const& p2, Sphere const& /*unused*/)
Chris@102 70 {
Chris@102 71 // http://williams.best.vwh.net/avform.htm#Crs
Chris@102 72 ReturnType dlon = get_as_radian<0>(p2) - get_as_radian<0>(p1);
Chris@102 73 ReturnType cos_p2lat = cos(get_as_radian<1>(p2));
Chris@102 74
Chris@102 75 // An optimization which should kick in often for Boxes
Chris@102 76 //if ( math::equals(dlon, ReturnType(0)) )
Chris@102 77 //if ( get<0>(p1) == get<0>(p2) )
Chris@102 78 //{
Chris@102 79 // return - sin(get_as_radian<1>(p1)) * cos_p2lat);
Chris@102 80 //}
Chris@102 81
Chris@102 82 // "An alternative formula, not requiring the pre-computation of d"
Chris@102 83 // In the formula below dlon is used as "d"
Chris@102 84 return atan2(sin(dlon) * cos_p2lat,
Chris@102 85 cos(get_as_radian<1>(p1)) * sin(get_as_radian<1>(p2))
Chris@102 86 - sin(get_as_radian<1>(p1)) * cos_p2lat * cos(dlon));
Chris@102 87 }
Chris@102 88
Chris@102 89 template <typename P1, typename P2>
Chris@102 90 static inline ReturnType apply(P1 const& p1, P2 const& p2)
Chris@102 91 {
Chris@102 92 return apply(p1, p2, 0); // dummy model
Chris@102 93 }
Chris@102 94 };
Chris@102 95
Chris@102 96 template <typename ReturnType>
Chris@102 97 struct azimuth<ReturnType, spherical_polar_tag>
Chris@102 98 : azimuth<ReturnType, spherical_equatorial_tag>
Chris@102 99 {};
Chris@102 100
Chris@102 101 template <typename ReturnType>
Chris@102 102 struct azimuth<ReturnType, cartesian_tag>
Chris@102 103 {
Chris@102 104 template <typename P1, typename P2, typename Plane>
Chris@102 105 static inline ReturnType apply(P1 const& p1, P2 const& p2, Plane const& /*unused*/)
Chris@102 106 {
Chris@102 107 ReturnType x = get<0>(p2) - get<0>(p1);
Chris@102 108 ReturnType y = get<1>(p2) - get<1>(p1);
Chris@102 109
Chris@102 110 // NOTE: azimuth 0 is at Y axis, increasing right
Chris@102 111 // as in spherical/geographic where 0 is at North axis
Chris@102 112 return atan2(x, y);
Chris@102 113 }
Chris@102 114
Chris@102 115 template <typename P1, typename P2>
Chris@102 116 static inline ReturnType apply(P1 const& p1, P2 const& p2)
Chris@102 117 {
Chris@102 118 return apply(p1, p2, 0); // dummy model
Chris@102 119 }
Chris@102 120 };
Chris@102 121
Chris@102 122 } // detail_dispatch
Chris@102 123 #endif // DOXYGEN_NO_DISPATCH
Chris@102 124
Chris@102 125 #ifndef DOXYGEN_NO_DETAIL
Chris@102 126 namespace detail
Chris@102 127 {
Chris@102 128
Chris@102 129 /// Calculate azimuth between two points.
Chris@102 130 /// The result is in radians.
Chris@102 131 template <typename ReturnType, typename Point1, typename Point2>
Chris@102 132 inline ReturnType azimuth(Point1 const& p1, Point2 const& p2)
Chris@102 133 {
Chris@102 134 return detail_dispatch::azimuth
Chris@102 135 <
Chris@102 136 ReturnType,
Chris@102 137 typename geometry::cs_tag<Point1>::type
Chris@102 138 >::apply(p1, p2);
Chris@102 139 }
Chris@102 140
Chris@102 141 /// Calculate azimuth between two points.
Chris@102 142 /// The result is in radians.
Chris@102 143 template <typename ReturnType, typename Point1, typename Point2, typename Model>
Chris@102 144 inline ReturnType azimuth(Point1 const& p1, Point2 const& p2, Model const& model)
Chris@102 145 {
Chris@102 146 return detail_dispatch::azimuth
Chris@102 147 <
Chris@102 148 ReturnType,
Chris@102 149 typename geometry::cs_tag<Point1>::type
Chris@102 150 >::apply(p1, p2, model);
Chris@102 151 }
Chris@102 152
Chris@102 153 } // namespace detail
Chris@102 154 #endif // DOXYGEN_NO_DETAIL
Chris@102 155
Chris@102 156 }} // namespace boost::geometry
Chris@102 157
Chris@102 158 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_AZIMUTH_HPP