...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
Calculate azimuth of a segment defined by a pair of points.
template<typename Point1, typename Point2, typename Strategy> auto azimuth(Point1 const & point1, Point2 const & point2, Strategy const & strategy)
Type |
Concept |
Name |
Description |
---|---|---|---|
Point1 const & |
Type of the first point of a segment. |
point1 |
First point of a segment. |
Point2 const & |
Type of the second point of a segment. |
point2 |
Second point of a segment. |
Strategy const & |
Type of an umbrella strategy defining azimuth strategy. |
strategy |
Umbrella strategy defining azimuth strategy. |
Azimuth in radians.
Either
#include <boost/geometry.hpp>
Or
#include <boost/geometry/algorithms/azimuth.hpp>
The function azimuth is not defined by OGC.
Note | |
---|---|
PostGIS contains an algorithm ST_Azimuth with the same functionality but could return different results e.g. result normalized to range 0 to pi instead of range -pi to pi. See the PostGIS documentation. |
The algorithm calculates the azimuth of a segment defined by a pair of points.
Note | |
---|---|
The result is in the range -pi to pi radians. |
Shows how to calculate azimuth in geographic coordinate system
#include <iostream> #include <boost/geometry.hpp> #include <boost/geometry/geometries/point.hpp> int main() { namespace bg = boost::geometry; typedef bg::model::point<double, 2, bg::cs::geographic<bg::degree> > point_type; point_type p1(0, 0); point_type p2(1, 1); bg::srs::spheroid<double> spheroid(6378137.0, 6356752.3142451793); bg::strategies::azimuth::geographic<> strategy(spheroid); auto azimuth = boost::geometry::azimuth(p1, p2, strategy); std::cout << "azimuth: " << azimuth << std::endl; return 0; }
Output:
azimuth: 0.788674