Browse Source

centralize the earth radius

Sven Czarnian 2 năm trước cách đây
mục cha
commit
6378630027
1 tập tin đã thay đổi với 3 bổ sung2 xóa
  1. 3 2
      src/math/wgs84.ts

+ 3 - 2
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));
   }
 }