2018-02-26 19:13:57 +01:00
|
|
|
#include <cmath>
|
|
|
|
#include "ellipsoid.h"
|
2017-11-14 23:30:25 +01:00
|
|
|
#include "lambertazimuthal.h"
|
2017-11-14 22:17:59 +01:00
|
|
|
|
2018-02-22 00:46:05 +01:00
|
|
|
#define sin2(x) (sin(x) * sin(x))
|
|
|
|
#define sqr(x) ((x) * (x))
|
|
|
|
|
2018-01-20 20:13:56 +01:00
|
|
|
LambertAzimuthal::LambertAzimuthal(const Ellipsoid *ellipsoid,
|
2017-11-14 22:17:59 +01:00
|
|
|
double latitudeOrigin, double longitudeOrigin, double falseEasting,
|
|
|
|
double falseNorthing)
|
|
|
|
{
|
2018-02-22 00:46:05 +01:00
|
|
|
double lat0 = deg2rad(latitudeOrigin);
|
2017-11-14 22:17:59 +01:00
|
|
|
|
2020-01-23 23:19:32 +01:00
|
|
|
_fe = falseEasting;
|
|
|
|
_fn = falseNorthing;
|
2018-02-22 00:46:05 +01:00
|
|
|
_lon0 = deg2rad(longitudeOrigin);
|
2017-11-14 22:17:59 +01:00
|
|
|
|
2018-02-22 00:46:05 +01:00
|
|
|
_a = ellipsoid->radius();
|
2018-05-17 22:41:56 +02:00
|
|
|
_es = ellipsoid->es();
|
|
|
|
_e = sqrt(_es);
|
2017-11-14 22:17:59 +01:00
|
|
|
|
2018-05-17 22:41:56 +02:00
|
|
|
double q0 = (1.0 - _es) * ((sin(lat0) / (1.0 - _es * sin2(lat0)))
|
|
|
|
- ((1.0/(2.0*_e)) * log((1.0 - _e * sin(lat0)) / (1.0 + _e
|
2018-02-22 00:46:05 +01:00
|
|
|
* sin(lat0)))));
|
2018-05-17 22:41:56 +02:00
|
|
|
_qP = (1.0 - _es) * ((1.0 / (1.0 - _es)) - ((1.0/(2.0*_e))
|
|
|
|
* log((1.0 - _e) / (1.0 + _e))));
|
2018-02-22 00:46:05 +01:00
|
|
|
_beta0 = asin(q0 / _qP);
|
2020-01-23 23:19:32 +01:00
|
|
|
_rq = _a * sqrt(_qP / 2.0);
|
|
|
|
_d = _a * (cos(lat0) / sqrt(1.0 - _es * sin2(lat0))) / (_rq * cos(_beta0));
|
2017-11-14 22:17:59 +01:00
|
|
|
}
|
|
|
|
|
2018-04-15 16:27:47 +02:00
|
|
|
PointD LambertAzimuthal::ll2xy(const Coordinates &c) const
|
2017-11-14 22:17:59 +01:00
|
|
|
{
|
2018-02-22 00:46:05 +01:00
|
|
|
double lon = deg2rad(c.lon());
|
|
|
|
double lat = deg2rad(c.lat());
|
2017-11-14 22:17:59 +01:00
|
|
|
|
2018-05-17 22:41:56 +02:00
|
|
|
double q = (1.0 - _es) * ((sin(lat) / (1.0 - _es * sin2(lat)))
|
|
|
|
- ((1.0/(2.0*_e)) * log((1.0 - _e * sin(lat)) / (1.0 + _e
|
2018-02-22 00:46:05 +01:00
|
|
|
* sin(lat)))));
|
|
|
|
double beta = asin(q / _qP);
|
2020-01-23 23:19:32 +01:00
|
|
|
double B = _rq * sqrt(2.0 / (1.0 + sin(_beta0) * sin(beta) + (cos(_beta0)
|
2018-02-22 00:46:05 +01:00
|
|
|
* cos(beta) * cos(lon - _lon0))));
|
2017-11-14 22:17:59 +01:00
|
|
|
|
2020-01-23 23:19:32 +01:00
|
|
|
double x = _fe + ((B * _d) * (cos(beta) * sin(lon - _lon0)));
|
|
|
|
double y = _fn + (B / _d) * ((cos(_beta0) * sin(beta))
|
2018-02-22 00:46:05 +01:00
|
|
|
- (sin(_beta0) * cos(beta) * cos(lon - _lon0)));
|
2017-11-14 22:17:59 +01:00
|
|
|
|
2018-04-15 16:27:47 +02:00
|
|
|
return PointD(x, y);
|
2017-11-14 22:17:59 +01:00
|
|
|
}
|
|
|
|
|
2018-04-15 16:27:47 +02:00
|
|
|
Coordinates LambertAzimuthal::xy2ll(const PointD &p) const
|
2017-11-14 22:17:59 +01:00
|
|
|
{
|
2018-05-17 22:41:56 +02:00
|
|
|
double es4 = _es * _es;
|
|
|
|
double es6 = _es * es4;
|
2018-02-22 00:46:05 +01:00
|
|
|
|
2020-01-23 23:19:32 +01:00
|
|
|
double rho = sqrt(sqr((p.x() - _fe) / _d) + sqr(_d * (p.y()
|
|
|
|
- _fn)));
|
|
|
|
double C = 2.0 * asin(rho / (2.0*_rq));
|
|
|
|
double betaS = asin((cos(C) * sin(_beta0)) + ((_d * (p.y() -_fn)
|
2018-02-22 00:46:05 +01:00
|
|
|
* sin(C) * cos(_beta0)) / rho));
|
|
|
|
|
2020-01-23 23:19:32 +01:00
|
|
|
double lon = _lon0 + atan((p.x() - _fe) * sin(C) / (_d * rho
|
|
|
|
* cos(_beta0) * cos(C) - sqr(_d) * (p.y() - _fn) * sin(_beta0)
|
2018-02-22 00:46:05 +01:00
|
|
|
* sin(C)));
|
2018-05-17 22:41:56 +02:00
|
|
|
double lat = betaS + ((_es/3.0 + 31.0*es4/180.0 + 517.0*es6/5040.0)
|
2018-02-22 18:12:47 +01:00
|
|
|
* sin(2.0*betaS)) + ((23.0*es4/360.0 + 251.0*es6/3780.0) * sin(4.0*betaS))
|
|
|
|
+ ((761.0*es6/45360.0)*sin(6.0*betaS));
|
2017-11-14 22:17:59 +01:00
|
|
|
|
|
|
|
return Coordinates(rad2deg(lon), rad2deg(lat));
|
|
|
|
}
|
2020-04-21 23:26:35 +02:00
|
|
|
|
|
|
|
bool LambertAzimuthal::operator==(const CT &ct) const
|
|
|
|
{
|
|
|
|
const LambertAzimuthal *other = dynamic_cast<const LambertAzimuthal*>(&ct);
|
|
|
|
return (other != 0 && _lon0 == other->_lon0 && _fn == other->_fn
|
|
|
|
&& _fe == other->_fe && _a == other->_a && _es == other->_es
|
|
|
|
&& _beta0 == other->_beta0 && _rq == other->_rq && _d == other->_d);
|
|
|
|
}
|