Geographical coordinates on the sphere

4 Ansichten (letzte 30 Tage)
Mateusz Talarski
Mateusz Talarski am 23 Jan. 2017
Kommentiert: Giora Enden am 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 Kommentare
John DeBriere
John DeBriere am 24 Jan. 2017
Bearbeitet: Walter Roberson am 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 am 24 Jan. 2017
Bearbeitet: Stephen23 am 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

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Niels
Niels am 23 Jan. 2017
i guess your classmate asked this question some days before:
  5 Kommentare
Niels
Niels am 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 am 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?

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Geographic Plots finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by