1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-24 11:45:53 +01:00

Precompute some more constants

This commit is contained in:
Martin Tůma 2018-05-19 20:55:43 +02:00
parent a66ca7b3a8
commit 59c95e53c4
2 changed files with 15 additions and 17 deletions

View File

@ -46,7 +46,6 @@ static Coordinates molodensky(const Coordinates &c, const Datum &from,
Point3D Datum::helmert(const Point3D &p) const
{
double scale = 1 + _ds * 1e-6;
double R00 = 1;
double R01 = _rz;
double R02 = -_ry;
@ -57,14 +56,13 @@ Point3D Datum::helmert(const Point3D &p) const
double R21 = -_rx;
double R22 = 1;
return Point3D(scale * (R00 * p.x() + R01 * p.y() + R02 * p.z()) + _dx,
scale * (R10 * p.x() + R11 * p.y() + R12 * p.z()) + _dy,
scale * (R20 * p.x() + R21 * p.y() + R22 * p.z()) + _dz);
return Point3D(_scale * (R00 * p.x() + R01 * p.y() + R02 * p.z()) + _dx,
_scale * (R10 * p.x() + R11 * p.y() + R12 * p.z()) + _dy,
_scale * (R20 * p.x() + R21 * p.y() + R22 * p.z()) + _dz);
}
Point3D Datum::helmertr(const Point3D &p) const
{
double scale = 1 + _ds * 1e-6;
double R00 = 1;
double R01 = _rz;
double R02 = -_ry;
@ -75,9 +73,9 @@ Point3D Datum::helmertr(const Point3D &p) const
double R21 = -_rx;
double R22 = 1;
double x = (p.x() - _dx) / scale;
double y = (p.y() - _dy) / scale;
double z = (p.z() - _dz) / scale;
double x = (p.x() - _dx) / _scale;
double y = (p.y() - _dy) / _scale;
double z = (p.z() - _dz) / _scale;
return Point3D(R00 * x + R10 * y + R20 * z, R01 * x + R11 * y + R21 * z,
R02 * x + R12 * y + R22 * z);
@ -86,11 +84,11 @@ Point3D Datum::helmertr(const Point3D &p) const
Datum::Datum(const Ellipsoid *ellipsoid, double dx, double dy, double dz,
double rx, double ry, double rz, double ds)
: _ellipsoid(ellipsoid), _dx(dx), _dy(dy), _dz(dz), _rx(as2rad(rx)),
_ry(as2rad(ry)), _rz(as2rad(rz)), _ds(ds)
_ry(as2rad(ry)), _rz(as2rad(rz)), _scale(1.0 + ds * 1e-6)
{
if (_ellipsoid->radius() == WGS84_RADIUS && _ellipsoid->flattening()
== WGS84_FLATTENING && _dx == 0.0 && _dy == 0.0 && _dz == 0.0
&& _rx == 0.0 && _ry == 0.0 && _rz == 0.0 && _ds == 0.0)
&& _rx == 0.0 && _ry == 0.0 && _rz == 0.0 && ds == 0.0)
_transformation = None;
else
_transformation = Helmert;
@ -98,7 +96,7 @@ Datum::Datum(const Ellipsoid *ellipsoid, double dx, double dy, double dz,
Datum::Datum(const Ellipsoid *ellipsoid, double dx, double dy, double dz)
: _ellipsoid(ellipsoid), _dx(dx), _dy(dy), _dz(dz), _rx(0.0), _ry(0.0),
_rz(0.0), _ds(0.0)
_rz(0.0), _scale(1.0)
{
if (_ellipsoid->radius() == WGS84_RADIUS && _ellipsoid->flattening()
== WGS84_FLATTENING && _dx == 0.0 && _dy == 0.0 && _dz == 0.0)
@ -139,7 +137,7 @@ QDebug operator<<(QDebug dbg, const Datum &datum)
dbg.nospace() << "Datum(" << *datum.ellipsoid() << ", " << datum.dx()
<< ", " << datum.dy() << ", " << datum.dz() << ", " << rad2as(datum.rx())
<< ", " << rad2as(datum.ry()) << ", " << rad2as(datum.rz()) << ", "
<< datum.ds() << ")";
<< (datum.scale() - 1.0) / 1e-6 << ")";
return dbg.space();
}
#endif // QT_NO_DEBUG

View File

@ -11,7 +11,7 @@ class Datum
{
public:
Datum() : _ellipsoid(0), _transformation(None), _dx(NAN), _dy(NAN),
_dz(NAN), _rx(NAN), _ry(NAN), _rz(NAN), _ds(NAN) {}
_dz(NAN), _rx(NAN), _ry(NAN), _rz(NAN), _scale(NAN) {}
Datum(const Ellipsoid *ellipsoid, double dx, double dy, double dz,
double rx, double ry, double rz, double ds);
Datum(const Ellipsoid *ellipsoid, double dx, double dy, double dz);
@ -20,16 +20,16 @@ public:
double dx() const {return _dx;}
double dy() const {return _dy;}
double dz() const {return _dz;}
double ds() const {return _ds;}
double rx() const {return _rx;}
double ry() const {return _ry;}
double rz() const {return _rz;}
double scale() const {return _scale;}
bool isNull() const
{return !_ellipsoid;}
bool isValid() const
{return (_ellipsoid && !std::isnan(_dx) && !std::isnan(_dy)
&& !std::isnan(_dz) && !std::isnan(_ds) && !std::isnan(_rx)
&& !std::isnan(_dz) && !std::isnan(_scale) && !std::isnan(_rx)
&& !std::isnan(_ry) && !std::isnan(_rz));}
Coordinates toWGS84(const Coordinates &c) const;
@ -47,13 +47,13 @@ private:
const Ellipsoid *_ellipsoid;
TransformationType _transformation;
double _dx, _dy, _dz, _rx, _ry, _rz, _ds;
double _dx, _dy, _dz, _rx, _ry, _rz, _scale;
};
inline bool operator==(const Datum &d1, const Datum &d2)
{return (*d1.ellipsoid() == *d2.ellipsoid() && d1.dx() == d2.dx()
&& d1.dy() == d2.dy() && d1.dz() == d2.dz() && d1.rx() == d2.rx()
&& d1.ry() == d2.ry() && d1.rz() == d2.rz() && d1.ds() == d2.ds());}
&& d1.ry() == d2.ry() && d1.rz() == d2.rz() && d1.scale() == d2.scale());}
#ifndef QT_NO_DEBUG
QDebug operator<<(QDebug dbg, const Datum &datum);