Calculating distance between two different scenes from aerial drone images can be done easily using their GPS co-ordinates. For example, the gps coordinate of scene 1 is 42.3755, -71.1180 and and the gps co-ordinate of scene 2 is 42.3770, -71.1167
Scene 1: (42.3755, -71.1180)
Scene 2: (42.3770, -71.1167)
And the distance between them is calculated by the Haversine formula which computes the shortest distance over the Earth's surface between two latitude-longitude points.
If the two locations have GPS coordinates (lat1,lon1) and (lat2,lon2):
The steps in Python are:
Convert latitudes and longitudes from degrees to radians.
Compute differences Δlat=lat2−lat1 and Δlon=lon2−lon1.
Use the Haversine formula:
a= 〖sin〗^2 (Δlat/2)+cos(〖lat〗_1 ) ×cos(〖lat〗_2 )× 〖sin〗^2 (Δlon/2)
c=2×arctan2(√a,√(1-a))
d=R×c
Where R is Earth's radius (mean radius = 6371 km).
import math
def haversine_distance(lat1, lon1, lat2, lon2):
R = 6371 # Earth radius in km
lat1_rad = math.radians(lat1)
lat2_rad = math.radians(lat2)
delta_lat = math.radians(lat2 - lat1)
delta_lon = math.radians(lon2 - lon1)
a = math.sin(delta_lat / 2) ** 2 + math.cos(lat1_rad) * math.cos(lat2_rad) * math.sin(delta_lon / 2) ** 2
c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a))
distance = R * c
return distance
# Example usage:
# Scene 1 GPS: lat1, lon1
# Scene 2 GPS: lat2, lon2
lat1, lon1 = 42.3770, -71.1167 # Scene 1 approx coords
lat2, lon2 = 42.3755, -71.1180 # Scene 2 approx coords
distance_km = haversine_distance(lat1, lon1, lat2, lon2)
print(f"Distance between scenes: {distance_km:.3f} km")
Distance between scenes: 0.198 km
No comments:
Post a Comment