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"
|
|
|
|
|
2018-04-15 16:27:47 +02:00
|
|
|
PointD Mercator::ll2xy(const Coordinates &c) const
|
2017-03-29 00:17:47 +02:00
|
|
|
{
|
2018-04-15 16:27:47 +02:00
|
|
|
return PointD(deg2rad(c.lon()) * WGS84_RADIUS,
|
2018-02-16 19:37:04 +01:00
|
|
|
log(tan(M_PI/4.0 + deg2rad(c.lat())/2.0)) * WGS84_RADIUS);
|
2017-03-29 00:17:47 +02:00
|
|
|
}
|
|
|
|
|
2018-04-15 16:27:47 +02:00
|
|
|
Coordinates Mercator::xy2ll(const PointD &p) const
|
2017-03-29 00:17:47 +02:00
|
|
|
{
|
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
|
|
|
}
|