...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> auto azimuth(Point1 const & point1, Point2 const & point2)
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. |
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
#include <iostream> #include <boost/geometry.hpp> #include <boost/geometry/geometries/point_xy.hpp> int main() { typedef boost::geometry::model::d2::point_xy<double> point_type; point_type p1(0, 0); point_type p2(1, 1); auto azimuth = boost::geometry::azimuth(p1, p2); std::cout << "azimuth: " << azimuth << std::endl; return 0; }
Output:
azimuth: 0.785398