Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext
azimuth

Calculate azimuth of a segment defined by a pair of points.

Synopsis

template<typename Point1, typename Point2>
auto azimuth(Point1 const & point1, Point2 const & point2)

Parameters

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.

Returns

Azimuth in radians.

Header

Either

#include <boost/geometry.hpp>

Or

#include <boost/geometry/algorithms/azimuth.hpp>

Conformance

The function azimuth is not defined by OGC.

[Note] 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.

Behavior

The algorithm calculates the azimuth of a segment defined by a pair of points.

[Note] Note

The result is in the range -pi to pi radians.

Example

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

PrevUpHomeNext