calcGCdist function

Calculate Great-Circle Distance

Calculate Great-Circle Distance

Calculate the great-circle distance between geographic (LL) coordinates. Also calculate the initial bearing of the great-circle arc (at its starting point).

calcGCdist(lon1, lat1, lon2, lat2, R=6371.2)

Arguments

  • lon1: numeric -- Longitude coordinate (degrees) of the start point.
  • lat1: numeric -- Latitude coordinate(degrees) of the start point.
  • lon2: numeric -- Longitude coordinate(degrees) of the end point.
  • lat2: numeric -- Latitude coordinate(degrees) of the end point.
  • R: numeric -- Mean radius (km) of the Earth.

Details

The great-circle distance is calculated between two points along a spherical surface using the shortest distance and disregarding topography.

Method 1: Haversine Formula

a=sin2((ϕ2ϕ1)/2)+cos(ϕ1)cos(ϕ2)sin2((λ2λ1)/2) a = \sin^2((\phi_2 - \phi_1)/2) + \cos(\phi_1) \cos(\phi_2) \sin^2((\lambda_2 - \lambda_1)/2)%a = sin^2((phi2-phi1)/2) + cos(phi1) cos(phi2) sin^2((lambda2-lambda1)/2) c=2 atan2(a,1a) c = 2~\mathrm{atan2}(\sqrt{a}, \sqrt{1-a})%c = 2 * atan2(sqrt(a), sqrt(1-a)) d=Rcd=Rc d = R cd = R * c

where

phiphi = latitude (in radians),

lambdalambda = longitude (in radians),

RR = radius (km) of the Earth,

aa = square of half the chord length between the points,

cc = angular distance in radians,

dd = great-circle distance (km) between two points.

Method 2: Spherical Law of Cosines

d=acos(sin(ϕ1)sin(ϕ2)+cos(ϕ1)cos(ϕ2)cos(λ2λ1))R d = \mathrm{acos}(\sin(\phi_1)\sin(\phi_2) + \cos(\phi_1)\cos(\phi_2)\cos(\lambda_2 - \lambda_1)) R%d = acos(sin(phi1) sin(phi2) + cos(phi1) cos(phi2) cos(lambda2-lambda1)) * R

The initial bearing (aka forward azimuth) for the start point can be calculated using:

θ=atan2(sin(λ2λ1)cos(ϕ2),cos(ϕ1)sin(ϕ2)sin(ϕ1)cos(ϕ2)cos(λ2λ1)) \theta = \mathrm{atan2}(\sin(\lambda_2-\lambda_1)\cos(\phi_2), \cos(\phi_1)\sin(\phi_2) - \sin(\phi_1)\cos(\phi_2)\cos(\lambda_2-\lambda_1))%theta = atan2( sin(lambda2-lambda1) cos(phi2), cos(phi1) sin(phi2) - sin(phi1) cos(phi2) cos(lambda2-lambda1) )

Returns

A list obect containing:

a -- Haversine aa = square of half the chord length between the points,

c -- Haversine cc = angular distance in radians,

d -- Haversine dd = great-circle distance (km) between two points,

d2 -- Law of Cosines dd = great-circle distance (km) between two points,

theta -- Initial bearing thetatheta (degrees) for the start point.

References

Movable Type Scripts -- Calculate distance, bearing and more between Latitude/Longitude points

Author(s)

Rowan Haigh, Program Head -- Offshore Rockfish

Pacific Biological Station (PBS), Fisheries & Oceans Canada (DFO), Nanaimo BC

locus opus: Remote office, Vancouver BC

Last modified Rd: 2024-03-11

Note

If one uses the north geomagnetic pole as an end point, thetatheta crudely approximates the magnetic declination.

See Also

In package PBSmapping:

addCompass, calcArea, calcCentroid, calcLength

Examples

local(envir=.PBSmapEnv,expr={ #-- Distance between southern BC waters and north geomagnetic pole print(calcGCdist(-126.5,48.6,-72.7,80.4)) })