Created
November 29, 2024 12:26
-
-
Save joaofig/0de0b4733eed9e79607feeeaf95bc0c1 to your computer and use it in GitHub Desktop.
Revisions
-
joaofig created this gist
Nov 29, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ def delta_location(lat: float, lon: float, bearing: float, meters: float) -> Tuple[float, float]: """ Calculates a destination location from a starting location, a bearing and a distance in meters. :param lat: Start latitude :param lon: Start longitude :param bearing: Bearing (North is zero degrees, measured clockwise) :param meters: Distance to displace from the starting point :return: Tuple with the new latitude and longitude """ delta = meters / 6378137.0 theta = math.radians(bearing) lat_r = math.radians(lat) lon_r = math.radians(lon) lat_r2 = math.asin(math.sin(lat_r) * math.cos(delta) + math.cos(lat_r) * math.sin(delta) * math.cos(theta)) lon_r2 = lon_r + math.atan2(math.sin(theta) * math.sin(delta) * math.cos(lat_r), math.cos(delta) - math.sin(lat_r) * math.sin(lat_r2)) return math.degrees(lat_r2), math.degrees(lon_r2)