distance between two geo points , I am trying to convert Rhumb lines distance calculation in matlab but it is not work properly

3 Ansichten (letzte 30 Tage)
I am trying to convert Rhumb lines distance calculation in matlab but it is not work properly can some body help :
%rhumb line
clc
th1=4.385704984670893; % latitude 1
th2=4.382316850229801; % latitude 2
lon1= 100.97986760432356 ; % longitude 1
lon2= 100.96958025244206 ; % longitude 2
Dlon=lon2-lon1;
Dth=th2-th1;
R=6371
LD=log(tan(pi/4+th2/2)/tan(pi/4+th1/2)); % latitude difference
cos(th1)
abs(LD);
q=Dth/LD;
d=sqrt((Dth)^2 + ((q)^2) * (Dlon)^2)*R
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% following is pic of javascript coade and description

Antworten (1)

Raag
Raag am 5 Feb. 2025
Hi Abdul,
The issue in calculating the rhumb line distance between two geographical points, seems to arise from the way the differences in longitude and latitude are found, especially when dealing with the 180-degree meridian
Here are steps to resolve the issue :
  • Convert the starting and ending latitudes and longitudes from degrees to radians.
th1 = deg2rad(4.385704984670893);
th2 = deg2rad(4.382316850229801);
lon1 = deg2rad(100.97986760432356);
lon2 = deg2rad(100.96958025244206);
  • Compute the differences in longitude and latitude.
Dlon = lon2 - lon1;
Dth = th2 - th1;
  • Ensure longitude difference takes shortest path possible.
if abs(Dlon) > pi
Dlon = mod(Dlon + pi, 2*pi) - pi;
  • Use the below logarithmic formula to ensure accuracy in computing the latitude difference
LD = log(tan(pi/4 + th2/2) / tan(pi/4 + th1/2))
  • Use the below code snippet, to avoid division by zero
if abs(LD) < 1e-10
q = cos(th1);
else
q = Dth / LD;
end
  • Use the following formula to compute the rhumb line distance
R = 6371;
d = sqrt((Dth)^2 + ((q)^2) * (Dlon)^2) * R;
For a better understanding of the above solution, refer to the following documentations :

Kategorien

Mehr zu Cartesian Coordinate System Conversion finden Sie in Help Center und File Exchange

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by