Clear Filters
Clear Filters

Geographical coordinates on the sphere

3 views (last 30 days)
Mateusz Talarski
Mateusz Talarski on 23 Jan 2017
Commented: Giora Enden on 17 Jul 2022
Greetings,
I have to write the script that calculate the closest distance between two points on the sphere.
Radius is given, and points are set by the user (one give's latitude and longitude).
For example: You want to know a distance between two cities, so you enter their geographical cords and as a result you get distance bewtween them in km's.
I'm totally new. The deadline is tomorrow and I have no clue how to do that.
I wish You can help me :)!
  2 Comments
John DeBriere
John DeBriere on 24 Jan 2017
Edited: Walter Roberson on 24 Jan 2017
It's pretty strait forward:
Try the Haversine formula:
delta_latitude = lat2 - lat1;
delta_longitude = long2 - long1;
a = sin(delta_latitude /2.0) * sin(delta_latitude /2.0) + cos(lat1) * cos(lat2) * sin(delta_longitude /2.0) * sin(delta_longitude /2.0);
c = atan( sqrt(a), sqrt(1.0 - a));
d = R * c;
where R is the Earths Radius = 6371 km
Remember all angles are in radians so you need a conversion of Latitude and Longitude to radians. But first you normally also have to do the conversion from degrees, minutes, seconds to a decimal the convert that to a radian angle.
degree_to_radian = angle * Pi / 180;
radian_to_degree = radian * 180 / Pi;
You might also want to look into the "Lambert Conformal Conic to Geographic Transform". I believe that the New Zealand (.gov web sites) present this information well and you can also find formulas to calculate Bearings, Mid points and related Geo-Spatial info.
Good Luck, and hope this helped!
John D
John DeBriere
John DeBriere on 24 Jan 2017
Edited: Stephen23 on 24 Jan 2017
Sorry I was unaware of how the editor would format my message.
I hope this is better:
It's pretty strait forward:
Try the Haversine formula:
function distance = GeographcDistance(lat1, lat2, long1, long2)
delta_latitude = lat2 - lat1;
delta_longitude = long2 - long1;
a = sin(delta_latitude /2.0) * sin(delta_latitude /2.0) + cos (lat1) * cos(lat2) * sin(delta_longitude /2.0) * sin(delta_longitude /2.0);
c = atan( sqrt(a), sqrt(1.0 - a));
distance = R * c;
end
where R is the Earths Radius = 6371 km
Remember all angles are in radians so you need a conversion of Latitude and Longitude to radians.
But first you normally also have to do the conversion from degrees, minutes, seconds to a decimal the convert that to a radian angle.
degree_to_radian = angle * Pi / 180;
radian_to_degree = radian * 180 / Pi;
You might also want to look into the "Lambert Conformal Conic to Geographic Transform".
I believe that the New Zealand (.gov web sites) present this information well and you can also find formulas to calculate Bearings, Mid points and related Geo-Spatial info.
Good Luck, and hope this helped!
John D

Sign in to comment.

Answers (1)

Niels
Niels on 23 Jan 2017
i guess your classmate asked this question some days before:
  5 Comments
Niels
Niels on 23 Jan 2017
create a function with the coordinates as input arguments, or use the -"input" function inside your function to get the coordinates from the user, then adapt the code given in the second answer.
Giora Enden
Giora Enden on 17 Jul 2022
  1. Is the formula valid when delta_latitude is larger than 90 deg?
  2. Is it valid when the two geographical sites are on oposite hemisphers?

Sign in to comment.

Categories

Find more on Geographic Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!