Problem calculating haversine. Obtained distance is too big

2 ビュー (過去 30 日間)
Jaime De La Mota Sanchis
Jaime De La Mota Sanchis 2021 年 3 月 13 日
回答済み: Jaime De La Mota Sanchis 2021 年 3 月 14 日
Hello everyone. I am working in airplane conflic detection. I have two aircraft optimized routes and I need to know the distance between them. The trajectories are given in degrees. I have tried to use the haversine to calculate the distance between each trajectory points as
RT=6378*1000;
haversine_angle=(sin((meanPhi2-meanPhi1)/2)).^2+cos(meanPhi1).*cos(meanPhi2).*(sin((meanLam2-meanLam1)/2)).^2;
haversine_sqrt=(haversine_angle).^0.5;
haversine_mean_distance_alternative =RT.*asin(haversine_sqrt);
figure
plot(meanTim2, haversine_mean_distance_alternative, 'b')
When I execute the code, I obtain the results displayed in figure 1.
However, if I calculate the distance between the starting points, it is way smaller that the one displayed in the figure 1.
I don't know what I am doing wrong in my calculation. As far as I see, I have implemented everything well. Also, note that if I use radians in the angles as
meanLam1=deg2rad(meanLam1);
meanLam2=deg2rad(meanLam2);
meanPhi1=deg2rad(meanPhi1);
meanPhi2=deg2rad(meanPhi2);
The distance is
Which still doesn't look like the one in the map.
Can someone help me?
Regards.
Jaime.
I am also attaching the files which contain the trajectories of both airplanes and the time (which is the same for both airplanes)

回答 (1 件)

Jaime De La Mota Sanchis
Jaime De La Mota Sanchis 2021 年 3 月 14 日
Never mind. i just found out I forgot a factor of 2 in the calculation of the haversine.

カテゴリ

Help Center および File ExchangeStatistics and Machine Learning Toolbox についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by