Migrate to radians instead of degrees to lessen conversion errors
This commit is contained in:
@@ -41,11 +41,16 @@ namespace geodata
|
||||
|
||||
static inline double toRadians(double value) { return value * M_PI / 180; }
|
||||
|
||||
static inline double normalize(double value)
|
||||
static inline double normalizeD(double value)
|
||||
{
|
||||
return fmod(value + 360, 360);
|
||||
}
|
||||
|
||||
static inline double normalizeR(double value)
|
||||
{
|
||||
return value < 0 ? 2 * M_PI + value : value;
|
||||
}
|
||||
|
||||
// Input and Output in degrees
|
||||
static inline double bearingDD(double fromLatitude,
|
||||
double fromLongitude,
|
||||
@@ -58,7 +63,22 @@ namespace geodata
|
||||
sin(toRadians(fromLatitude)) * cos(toRadians(toLatitude)) *
|
||||
cos(toRadians(toLongitude) - toRadians(fromLongitude));
|
||||
|
||||
return normalize(toDegrees(atan2(y, x)));
|
||||
return normalizeD(toDegrees(atan2(y, x)));
|
||||
}
|
||||
|
||||
// Input in degrees, Output in radians
|
||||
static inline double bearingDR(double fromLatitude,
|
||||
double fromLongitude,
|
||||
double toLatitude,
|
||||
double toLongitude)
|
||||
{
|
||||
double y = sin(toRadians(toLongitude) - toRadians(fromLongitude)) *
|
||||
cos(toRadians(toLatitude));
|
||||
double x = cos(toRadians(fromLatitude)) * sin(toRadians(toLatitude)) -
|
||||
sin(toRadians(fromLatitude)) * cos(toRadians(toLatitude)) *
|
||||
cos(toRadians(toLongitude) - toRadians(fromLongitude));
|
||||
|
||||
return normalizeR(atan2(y, x));
|
||||
}
|
||||
|
||||
// Input in degrees, Output in metres
|
||||
|
||||
Reference in New Issue
Block a user