2017-03-29 00:17:47 +02:00
|
|
|
#include <cmath>
|
2018-02-16 19:37:04 +01:00
|
|
|
#include "common/coordinates.h"
|
|
|
|
#include "common/wgs84.h"
|
2017-03-29 00:17:47 +02:00
|
|
|
#include "mercator.h"
|
|
|
|
|
|
|
|
QPointF Mercator::ll2xy(const Coordinates &c) const
|
|
|
|
{
|
2018-02-16 19:37:04 +01:00
|
|
|
return QPointF(deg2rad(c.lon()) * WGS84_RADIUS,
|
|
|
|
log(tan(M_PI/4.0 + deg2rad(c.lat())/2.0)) * WGS84_RADIUS);
|
2017-03-29 00:17:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Coordinates Mercator::xy2ll(const QPointF &p) const
|
|
|
|
{
|
2018-02-16 19:37:04 +01:00
|
|
|
return Coordinates(rad2deg(p.x() / WGS84_RADIUS),
|
|
|
|
rad2deg(2 * atan(exp(p.y() / WGS84_RADIUS)) - M_PI/2));
|
2017-03-29 00:17:47 +02:00
|
|
|
}
|