Skip to content
Permalink
Browse files
QgsDistanceArea::bearing(): add comment why an apparently strange use…
… of atan2() is correct
  • Loading branch information
rouault authored and nyalldawson committed Jun 14, 2021
1 parent e79ae77 commit c7edffe21407006289f7e0039e11f75e3d5d81b6
Showing with 4 additions and 0 deletions.
  1. +4 −0 src/core/qgsdistancearea.cpp
@@ -867,6 +867,10 @@ double QgsDistanceArea::bearing( const QgsPointXY &p1, const QgsPointXY &p2 ) co
{
double dx = p2.x() - p1.x();
double dy = p2.y() - p1.y();
// Note: the prototype of std::atan2 is (y,x), to return the angle of
// vector (x,y) from the horizontal axis in counter-clock-wise orientation.
// But a bearing is expressed in clock-wise order from the vertical axis, so
// M_PI / 2 - std::atan2( dy, dx ) == std::atan2( dx, dy )
bearing = std::atan2( dx, dy );
}

0 comments on commit c7edffe

Please sign in to comment.