fArcDistance

Function to calculate the great circle distance, forward and backward azimuths between two geographic points on a spherical earth.
0 Downloads
Updated 3 Oct 2024

View License

Function to calculate the great circle distance and azimuth between two geographic points on a spherical earth.
In surveying science, the azimuth is also known as 'bearing'. It is measured clockwise from the north.
There are the fore bearing and back bearing; the difference between them is 180 degrees. They are opposite to each other.
This function is useful when you do not have access to MATLAB's Mapping Toolbox.
Inputs:
Lon1 is the longitude of the first point; specified in decimal degrees.
Lon2 is the longitude of the second point; specified in decimal degrees.
Lat1 is the latitude of the first point; specified in decimal degrees.
Lat2 is the latitude of the second point; specified in decimal degrees.
DistanceUnit ::optional:: is the unit to express the computed distance in; specified as a string. Default is "km".
Outputs:
Distance is the great circle distance between the two geographic points. Unit is given by DistanceUnit; default is km.
ForeAzimuth is the direction (bearing) from the first point to the second point using the north as reference. Unit is degree or radian; default is degree.
BackAzimuth is the direction (bearing) from the second point to the first point using the north as reference. Unit is degree or radian; default is degree.
Usage example:
Lon1 = -10.167293 * ones(10,1);
Lon2 = -109.089123 * ones(10,1);
Lat1 = -59.810366 * ones(10,1);
Lat2 = 71.1873231 * ones(10,1);
[Distance, ForeAzimuth, BackAzimuth] = fArcDistance(Lon1, Lon2, Lat1, Lat2); % Distance in kilometres, Azimuth in degrees
[Distance, ForeAzimuth, BackAzimuth] = fArcDistance(Lon1, Lon2, Lat1, Lat2, "m"); % Distance in metres, Azimuth in degrees
[Distance, ForeAzimuth, BackAzimuth] = fArcDistance(Lon1, Lon2, Lat1, Lat2, "km"); % Distance in kilometres, Azimuth in degrees
[Distance, ForeAzimuth, BackAzimuth] = fArcDistance(Lon1, Lon2, Lat1, Lat2, "deg"); % Distance in degrees, Azimuth in degrees
[Distance, ForeAzimuth, BackAzimuth] = fArcDistance(Lon1, Lon2, Lat1, Lat2, "rad"); % Distance in radians, Azimuth in radians
[Distance, ForeAzimuth, BackAzimuth] = fArcDistance(Lon1, Lon2, Lat1, Lat2, "mile"); % Distance in statute miles, Azimuth in degrees
[Distance, ForeAzimuth, BackAzimuth] = fArcDistance(Lon1, Lon2, Lat1, Lat2, "nautical"); % Distance in nautical miles, Azimuth in degrees

Cite As

Richard Fiifi Annan (2024). fArcDistance (https://www.mathworks.com/matlabcentral/fileexchange/173410-farcdistance), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2020a
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!
Version Published Release Notes
1.0.0