add a function to project coordinates
This commit is contained in:
		| @@ -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) }; | ||||
|   } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user