File Exchange

## Geodetic distance on WGS84 earth ellipsoid

version 1.0.0.0 (2.24 KB) by
Rapidly computes the geodetic distance between coordinates on the ellipsoidal earth.

Updated 01 Sep 2004

In 1975, Vincenty published a rapidly converging algorithm for computing the distance between points on an ellipsoidal earth. The algorithm is precise to within a few millimeters. Since then, his algorithm has since seen significant implementation in geodesy and engineering. After adjusting the algorithm to converge in all cases (the original suffers from convergence failure in a few outlying cases), I have provided it here in MATLAB form. The function itself does not require the Mapping Toolbox, but I have included a (commented-out) code section following the body of the function, which you can use if you have the Mapping Toolbox to compare the accuracy of this algorithm to spherical earth distances. Note that in that toolbox, the Mathworks uses a fast but somewhat less precise method for computing geodetic distances on an ellipsoid. This function will provide rapid, extremely precise results. Please see code comments for references.

### Cite As

Michael Kleder (2021). Geodetic distance on WGS84 earth ellipsoid (https://www.mathworks.com/matlabcentral/fileexchange/5379-geodetic-distance-on-wgs84-earth-ellipsoid), MATLAB Central File Exchange. Retrieved .

### Comments and Ratings (21)

Zhao Yiyun

Lin KuanHong

BlueEyes

Thank you, Bradley, for your check up of my test.
@ Amanda Fay. What do you mean for arclens? The function vdist has 4 inputs (in degrees) and properly returns the distance (s) in meters, or in km by dividing per 1e3, as per my example below:
---------
>> format long g
>> vdist(37.0328,15.065,45.0,7.82)/1e3 % distance in km over the ellipsoid WGS84
ans = 1073.34180201461
---------
Cheers

Amanda Fay

my results are showing values in arclens and not in m as it states in the script.

Very good job! @BlueEyes, I get 1.073341802014612e+06 in MATLAB

BlueEyes

Please, could someone verify the precision of the follwing test carried out through Octave 4.0.0?
>> format long g
>> vdist(37.0328,15.065,45.0,7.82)/1e3 % distance in km over the ellipsoid WGS84
ans = 1073.34180201461
>>

Mauricio Saldivia

lauren orr

catur anindhito

thanx for sharing. That is very good

Goran Nystrom

xzn dasds

Michael Draugelis

Works like a charm. I love it. Thanks for sharing!

Chuck B

Works great.

Frederic B.

Thanks!
The file has been really useful!

The Author

Thank you for your helpful comment. The problem you reported is actually addressed in the function which has superceded this one. The new function is vectorized, computes azimuth as well as distance, and features improved handling of anomalous cases. Please see

Tro Han

Returns imaginary result for lon1=0 lon2=0.
Fix by preventing asin of # > 1 in alpha equation i.e.
alpha = asin(max(min(cos(U1)*cos(U2)*sin(lambda)/sin(sigma),1),-1));

Michael Kleder

See the following URL (Matlab File Exchange item #8607) for vectorized inputs and forward / reverse azimuth outputs, in addition to the Vincenty distance:

Gerald Dalley

Very nice. It would be convenient to allow the input coordinates to be vectors/matrices.

Gabor Vali

Very helpful. Much more transparent than the equaazim.m routine.

Ashish Misra

I have verified the output of this function with my Garmin MapSource software and I got the answers to be close enough. I found this function very useful

I have verified the output of this function with my Garmin MapSource software and I got the answers to be close enough. I found this function very useful.

##### MATLAB Release Compatibility
Created with R13
Compatible with any release
##### Platform Compatibility
Windows macOS Linux

### Community Treasure Hunt

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

Start Hunting!