I have coded the simple Haversine formula (matlab) and it works fine (see below). If I provide 2 sets of latitude/longitude I can find the distance between them.
Despite this, I need to invert the procedure and calculate 2 sets of coordinates based on a specified distance. Although the formula is quite short, it seems difficult to back calculate.
For example, if I have the global coordinate (3,50), I want to calculate the corner coordinates of a square bounding box around this point with specified length/width.
lat1 = 3.5; lon1 = 50.1; lat2 = 3.6; lon2 = 50.1 % Input coordinates
delta_lat = degtorad(lat2 - lat1); % difference in latitude
delta_lon = degtorad(lon2 - lon1); % difference in longitude
a = sin(delta_lat/2)^2 + cos(lat1) * cos(lat2) * sin(delta_lon/2)^2;
c = 2 * atan2(sqrt(a), sqrt(1-a));
km = 6371 * c % distance in km
Thanks
The circumference of the earth at equator = 40,076 km. The equator is divided into 360 degrees of longitude, so each degree at the equator represents approximately 111.32 km. Moving away from the equator towards a pole this distance decreases to zero at the pole.
To calculate the distance at different latitudes multiply it by the cosine of the latitude. As your latidude of 3.5 is near the equator you will not need any correction as the cos(3.5) gives a value of 111.11 km.
To calculate a "box" each km = 1/111 degrees (0.009009) ie a 2 km "box" surrounding coordinate 3,50 would have coordinates (3.009009,50.0090049) (2.990991,49.990991)
As you move towards the poles you will have to adjust the longitude value by multiplying by the cosine of the average of the latitude values.