From 63786300276cfad06febb7a98fd433adfbe0499a Mon Sep 17 00:00:00 2001 From: Sven Czarnian Date: Tue, 25 Oct 2022 08:27:49 +0200 Subject: [PATCH] centralize the earth radius --- src/math/wgs84.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/math/wgs84.ts b/src/math/wgs84.ts index 04549b2..505c8e1 100644 --- a/src/math/wgs84.ts +++ b/src/math/wgs84.ts @@ -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)); } }