Procházet zdrojové kódy

add a function to project coordinates

Sven Czarnian před 2 roky
rodič
revize
0349931f0f
1 změnil soubory, kde provedl 27 přidání a 0 odebrání
  1. 27 0
      src/math/wgs84.ts

+ 27 - 0
src/math/wgs84.ts

@@ -23,4 +23,31 @@ export class WGS84 {
 
     return 2 * EarthRadius * Math.asin(Math.sqrt(a));
   }
+
+  /// @brief Projects coordinate based on the distance and bearing
+  /// @param coordinate The root coordinate
+  /// @param distance The distance in metres
+  /// @param bearing The bearing in degree
+  static project(
+    coordinate: { lat: number; lon: number },
+    distance: number,
+    bearing: number,
+  ): { lat: number; lon: number } {
+    const lat0 = Angle.deg2rad(coordinate.lat);
+    const lon0 = Angle.deg2rad(coordinate.lon);
+    const radians = Angle.deg2rad(bearing);
+
+    const lat1 = Math.asin(
+      Math.sin(lat0) * Math.cos(distance / EarthRadius) +
+        Math.cos(lat0) * Math.sin(distance / EarthRadius) * Math.cos(radians),
+    );
+    const lon1 =
+      lon0 +
+      Math.atan2(
+        Math.sin(radians) * Math.sin(distance / EarthRadius) * Math.cos(lat0),
+        Math.cos(distance / EarthRadius) - Math.sin(lat0) * Math.sin(lat1),
+      );
+
+    return { lat: Angle.rad2deg(lat1), lon: Angle.rad2deg(lon1) };
+  }
 }