How to calculate the middle point between two points on the Earth in matlab?

27 ビュー (過去 30 日間)
Ray Lee
Ray Lee 2015 年 7 月 9 日
コメント済み: Ted Shultz 2019 年 8 月 20 日
Given the latitudes and longitudes of two points, how to get the middle point efficiently?
My trouble is there are millions of point pairs to calculate....
  2 件のコメント
Sad Grad Student
Sad Grad Student 2015 年 7 月 9 日
could you give an example of your input and the expected output?
James Tursa
James Tursa 2015 年 7 月 9 日
編集済み: James Tursa 2015 年 7 月 9 日
Middle point on a great circle arc assuming a sphere? Or something else?
How is your data stored?

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

採用された回答

Mohammad Abouali
Mohammad Abouali 2015 年 7 月 10 日
編集済み: Mohammad Abouali 2015 年 7 月 10 日
Go to this page you will find bunch of useful formula. The one that you are looking for is called "midpoint" on that page. You have the JavaScript code, but implementation is rather easy
% lat1,lat2,lon1,lon2 should be in radian
Bx = cos(lat2) * cos(lon2-lon1);
By = cos(lat2) * sin(lon2-lon1);
latMid = atan2(sin(lat1) + sin(lat2), ...
sqrt( (cos(lat1)+Bx)*(cos(lat1)+Bx) + By*By ) );
lonMid = lon1 + atan2(By, cos(lat1) + Bx);
  1 件のコメント
Ted Shultz
Ted Shultz 2019 年 8 月 20 日
Here is the matlab code of the formula provided by Mohammad, but all in degrees. Often lat/lon are in degrees, so this nearly identical code my be easier to use.
function [latMid, lonMid] = midpointLatLon(lat1, lon1, lat2, lon2)
% midpoint of two lat long cord on a sphere, all units are deg
Bx = cosd(lat2) * cosd(lon2-lon1);
By = cosd(lat2) * sind(lon2-lon1);
latMid = atan2d(sind(lat1) + sind(lat2), ...
sqrt( (cosd(lat1)+Bx)*(cosd(lat1)+Bx) + By*By ) );
lonMid = lon1 + atan2d(By, cosd(lat1) + Bx);

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

その他の回答 (1 件)

Ted Shultz
Ted Shultz 2019 年 8 月 20 日
There is a built in function in the matlab mapping toolbox that does what I think you are looking for: meanm
Mean location of geographic coordinates
Syntax
[latmean,lonmean] = meanm(lat,lon)
[latmean,lonmean] = meanm(lat,lon,units)
[latmean,lonmean] = meanm(lat,lon,ellipsoid)

カテゴリ

Help Center および File ExchangeMap Display についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by