Azzera filtri
Azzera filtri

Geographical coordinates on the sphere

3 visualizzazioni (ultimi 30 giorni)
Mateusz Talarski
Mateusz Talarski il 23 Gen 2017
Commentato: Giora Enden il 17 Lug 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 Commenti
John DeBriere
John DeBriere il 24 Gen 2017
Modificato: Walter Roberson il 24 Gen 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 il 24 Gen 2017
Modificato: Stephen23 il 24 Gen 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

Accedi per commentare.

Risposte (1)

Niels
Niels il 23 Gen 2017
i guess your classmate asked this question some days before:
  5 Commenti
Niels
Niels il 23 Gen 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 il 17 Lug 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?

Accedi per commentare.

Categorie

Scopri di più su Geographic Plots in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by