# deg2km command does not calculate distance between two points

7 views (last 30 days)
Hülya Sukas on 28 Jan 2020
Commented: Hülya Sukas on 31 Jan 2020
Hello everyone.
I am trying to calculate distance between two geographical coordinates and I want to convert geographical coordinates to the km. Therefore I used deg2km function. However, I realize that it is not convert points properly.
For instance, I used these two points.
p_x=[5; 10]; %degree
p_y=[8; 16]; %degree
pos_y=deg2km(p_y,6378);
pos_x=deg2km(p_x,6378);
It returns as:
pos_x= [556.58549846099 1113.17099692198]
pos_y= [890.536797537587 1781.07359507517]
When I calculate distance ( sqrt((556.5-1113.2)^2+(890.5368-1781.1)^2) ) between these points I obtained distance as : 1050.2464
However I checked it google map and also other websites it should be 1042 km.
Do you have any suggestion to calculate distance and also points as kilometers properly?

Priyanshu Mishra on 31 Jan 2020
Hi Hülya,
Distance given by the deg2km depens on what radius of earth you are considering. Default value given in MATLAB documentation is 6371 km. You considered radius as 6378 km that is why there are differences in the values of distances. Also, the metric you are considering for calculating the distance sqrt(x^2+y^2) is not completely correct, since in case of earth there are other factors also involved because of it's shape.
Hülya Sukas on 31 Jan 2020
Hi Priyanshu. It tried another radius too. But it is not match distance that I calculated with google map or another websites. Do you have any suggestions?