centralize the earth radius

This commit is contained in:
Sven Czarnian
2022-10-25 08:27:49 +02:00
parent abe73cdd8b
commit 6378630027

View File

@@ -1,5 +1,7 @@
import { Angle } from './angle';
const EarthRadius = 6371000;
export class WGS84 {
/// @brief Calculates the Haversine distance
/// @param coordinate0 The first coordinate
@@ -13,13 +15,12 @@ export class WGS84 {
const lon0 = Angle.deg2rad(coordinate0.lon);
const lat1 = Angle.deg2rad(coordinate1.lat);
const lon1 = Angle.deg2rad(coordinate1.lon);
const earthRadius = 6371000;
const a =
0.5 -
Math.cos(lat1 - lat0) * 0.5 +
Math.cos(lat0) * Math.cos(lat1) * (1 - Math.cos(lon1 - lon0) * 0.5);
return 2 * earthRadius * Math.asin(Math.sqrt(a));
return 2 * EarthRadius * Math.asin(Math.sqrt(a));
}
}