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.
- Ensure longitude difference takes shortest path possible.
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
- Use the following formula to compute the rhumb line distance
d = sqrt((Dth)^2 + ((q)^2) * (Dlon)^2) * R;
For a better understanding of the above solution, refer to the following documentations :