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"
|
2018-05-12 22:38:42 +02:00
|
|
|
#include "webmercator.h"
|
2017-03-29 00:17:47 +02:00
|
|
|
|
2018-05-12 22:38:42 +02:00
|
|
|
PointD WebMercator::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-05-15 21:51:56 +02:00
|
|
|
log(tan(M_PI_4 + deg2rad(c.lat())/2.0)) * WGS84_RADIUS);
|
2017-03-29 00:17:47 +02:00
|
|
|
}
|
|
|
|
|
2018-05-12 22:38:42 +02:00
|
|
|
Coordinates WebMercator::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),
|
2018-05-15 21:51:56 +02:00
|
|
|
rad2deg(2.0 * atan(exp(p.y() / WGS84_RADIUS)) - M_PI_2));
|
2017-03-29 00:17:47 +02:00
|
|
|
}
|