mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-06-27 11:39:16 +02:00
Now drawing path segments > 1 arc minute as great circle curves instead of rhumb lines
This commit is contained in:
23
src/common/greatcircle.cpp
Normal file
23
src/common/greatcircle.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
#include "greatcircle.h"
|
||||
|
||||
Coordinates GreatCircle::pointAt(const Coordinates &c1, const Coordinates &c2,
|
||||
double f)
|
||||
{
|
||||
double lat1 = deg2rad(c1.lat());
|
||||
double lon1 = deg2rad(c1.lon());
|
||||
double lat2 = deg2rad(c2.lat());
|
||||
double lon2 = deg2rad(c2.lon());
|
||||
|
||||
double cosLat1 = cos(lat1);
|
||||
double cosLat2 = cos(lat2);
|
||||
double d = 2 * asin(sqrt(pow((sin((lat1 - lat2) / 2)), 2) + cosLat1
|
||||
* cosLat2 * pow(sin((lon1 - lon2) / 2), 2)));
|
||||
double sinD = sin(d);
|
||||
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);
|
||||
|
||||
return Coordinates(rad2deg(atan2(y, x)), rad2deg(atan2(z, sqrt(x*x + y*y))));
|
||||
}
|
11
src/common/greatcircle.h
Normal file
11
src/common/greatcircle.h
Normal file
@ -0,0 +1,11 @@
|
||||
#ifndef GREATCIRCLE_H
|
||||
#define GREATCIRCLE_H
|
||||
|
||||
#include "coordinates.h"
|
||||
|
||||
namespace GreatCircle
|
||||
{
|
||||
Coordinates pointAt(const Coordinates &c1, const Coordinates &c2, double f);
|
||||
}
|
||||
|
||||
#endif // GREATCIRCLE_H
|
Reference in New Issue
Block a user