Created
November 29, 2024 12:26
-
-
Save joaofig/0de0b4733eed9e79607feeeaf95bc0c1 to your computer and use it in GitHub Desktop.
Computes a location based on a start location, a heading and a distance
This file contains 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 characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment