Collapse computeAngle into coordinate calculation

This commit is contained in:
Daniel J. Hofmann
2016-01-21 12:58:24 +01:00
committed by Patrick Niklaus
parent 0fcca04150
commit 46fc6f8da4
5 changed files with 33 additions and 44 deletions
+22
View File
@@ -2,6 +2,7 @@
#include "util/mercator.hpp"
#include "util/string_util.hpp"
#include "util/trigonometry_table.hpp"
#include <boost/assert.hpp>
@@ -218,6 +219,27 @@ double bearing(const FixedPointCoordinate &first_coordinate,
}
return result;
}
double computeAngle(const FixedPointCoordinate &first,
const FixedPointCoordinate &second,
const FixedPointCoordinate &third)
{
const double v1x = (first.lon - second.lon) / COORDINATE_PRECISION;
const double v1y = mercator::latToY(first.lat / COORDINATE_PRECISION) -
mercator::latToY(second.lat / COORDINATE_PRECISION);
const double v2x = (third.lon - second.lon) / COORDINATE_PRECISION;
const double v2y = mercator::latToY(third.lat / COORDINATE_PRECISION) -
mercator::latToY(second.lat / COORDINATE_PRECISION);
double angle = (atan2_lookup(v2y, v2x) - atan2_lookup(v1y, v1x)) * 180. / M_PI;
while (angle < 0.)
{
angle += 360.;
}
return angle;
}
}
}
}