1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-30 22:51:16 +01:00

Yet another optimization

This commit is contained in:
Martin Tůma 2018-09-13 01:45:17 +02:00
parent 8f9049a8d4
commit df104b16c6
2 changed files with 22 additions and 14 deletions

View File

@ -2,25 +2,33 @@
GreatCircle::GreatCircle(const Coordinates &c1, const Coordinates &c2)
{
_lat1 = deg2rad(c1.lat());
_lon1 = deg2rad(c1.lon());
_lat2 = deg2rad(c2.lat());
_lon2 = deg2rad(c2.lon());
double lat1 = deg2rad(c1.lat());
double lon1 = deg2rad(c1.lon());
double lat2 = deg2rad(c2.lat());
double lon2 = deg2rad(c2.lon());
_cosLat1 = cos(_lat1);
_cosLat2 = cos(_lat2);
_d = 2 * asin(sqrt(pow((sin((_lat1 - _lat2) / 2)), 2) + _cosLat1
* _cosLat2 * pow(sin((_lon1 - _lon2) / 2), 2)));
double cosLat1 = cos(lat1);
double cosLat2 = cos(lat2);
_sinLat1 = sin(lat1);
_sinLat2 = sin(lat2);
_xA = cosLat1 * cos(lon1);
_xB = cosLat2 * cos(lon2);
_yA = cosLat1 * sin(lon1);
_yB = cosLat2 * sin(lon2);
_d = 2 * asin(sqrt(pow((sin((lat1 - lat2) / 2)), 2) + cosLat1 * cosLat2
* pow(sin((lon1 - lon2) / 2), 2)));
_sinD = sin(_d);
}
Coordinates GreatCircle::pointAt(double f) const
{
double A = sin((1.0 - f) * _d) / _sinD;
double B = sin(f*_d) / _sinD;
double x = A * _cosLat1 * cos(_lon1) + B * _cosLat2 * cos(_lon2);
double y = A * _cosLat1 * sin(_lon1) + B * _cosLat2 * sin(_lon2);
double z = A * sin(_lat1) + B * sin(_lat2);
double B = sin(f * _d) / _sinD;
double x = A * _xA + B * _xB;
double y = A * _yA + B * _yB;
double z = A * _sinLat1 + B * _sinLat2;
return Coordinates(rad2deg(atan2(y, x)), rad2deg(atan2(z, sqrt(x*x + y*y))));
}

View File

@ -11,10 +11,10 @@ public:
Coordinates pointAt(double f) const;
private:
double _lat1, _lon1, _lat2, _lon2;
double _cosLat1, _cosLat2;
double _xA, _xB, _yA, _yB;
double _d;
double _sinD;
double _sinLat1, _sinLat2;
};
#endif // GREATCIRCLE_H