Geographical coordinates on the sphere

4 ビュー (過去 30 日間)
Mateusz Talarski
Mateusz Talarski 2017 年 1 月 23 日
コメント済み: Giora Enden 2022 年 7 月 17 日
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 件のコメント
John DeBriere
John DeBriere 2017 年 1 月 24 日
編集済み: Walter Roberson 2017 年 1 月 24 日
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 2017 年 1 月 24 日
編集済み: Stephen23 2017 年 1 月 24 日
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

サインインしてコメントする。

回答 (1 件)

Niels
Niels 2017 年 1 月 23 日
i guess your classmate asked this question some days before:
  5 件のコメント
Niels
Niels 2017 年 1 月 23 日
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 2022 年 7 月 17 日
  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?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGeographic Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by