Geographical coordinates on the sphere
1 次查看(过去 30 天)
显示 更早的评论
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
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
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
2017-1-23
i guess your classmate asked this question some days before:
5 个评论
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
2022-7-17
- Is the formula valid when delta_latitude is larger than 90 deg?
- Is it valid when the two geographical sites are on oposite hemisphers?
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Geographic Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!