Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Great Circles and a Point

Authors
Affiliations
NSF National Center for Atmospheric Research
A hockey puck is launched from London toward the west, on a stationary earth. The natural great circle motion of the puck takes it toward the equator, not along the original line of latitude, which we might normally call west. The great circle path also coincides with the line of sight toward the west (projected radially down to the earth'surface). Thus we must conclude that Costa Rica is due west of London. Credit: Oregon State (https://sites.science.oregonstate.edu/~mcintyre/coriolis/Curvilinear_GIF.html)

Great Circles and a Point


Overview

Oh no! A plane traveling across the country suddenly discovers it is low on fuel! It can no longer make it to the planned airport, instead it has to find the closest airport to its current position that it can make it with its remaining fuel.

In great circle terms, we want to determine how far a point (let’s say, the next closest airport) is from a great circle arc (the flight’s path). In this notebook we will:

  1. Determine the distance of a point to a great circle arc (cross-track and along-track distance)

  2. Determine if a point lies on a great circle arc and path (with and without tolerances)

Prerequisites

ConceptsImportanceNotes
NumpyNecessaryUsed to work with large arrays
PandasNecessaryUsed to read in and organize data (in particular dataframes)
Intro to CartopyHelpfulWill be used for adding maps to plotting
MatplotlibHelpfulWill be used for plotting
  • Time to learn: 40 minutes


Imports

  • Import Packages

  • Setup location dataframe with coordinates

Loading...

Determine the distance of a point to a great circle arc

The distance from a point to a great circle arc is known as the cross track distance (sometimes known as cross track error). For example, how far would a plane have to fly from its path to get to an unscheduled airport for refueling? Meantime, the along track distance measures how far along the great arc a point lies. For instance, what is your new position (latitude/longitude) when you’ve traveled 250 km into your 2000 km plane ride?

  • Cross track distance: angular distance from point P to great circle path

  • Along track distance: angular distance along the great circle path from A to B before hitting a point that is closest to point P

Cross Track Distance

Distance of a point to a great circle arc is defined as:

dxt=arcsin⁡(sin⁡(δ13)⋅sin⁡(θ13−θ12))∗Rdxt = \arcsin( \sin(δ_{13}) ⋅ \sin(θ_{13} − θ_{12}) ) * R

Where,

  • δ13 (δ13δ_{13}) is (angular) distance from start point to third point

  • θ13 (θ13θ_{13}) is (initial) bearing from start point to third point

  • θ12 (θ12θ_{12}) is (initial) bearing from start point to end point

  • R is the earth’s radius

Then,

dxt=arcsin⁡(sin⁡(δ13)∗sin⁡(θ13−θ12))∗Rd_{xt} = \arcsin(\sin(δ_{13})*\sin(θ_{13} - θ_{12})) * R
XTD=aarcsin⁡(sin⁡(distAD)∗sin⁡(crsAD−crsAB))XTD =a\arcsin(\sin(dist_{AD})*\sin(crs_{AD}-crs_{AB}))

Where,

  • Positive Cross-Track Distance: Point lies in the hemisphere to the left of the great circle

  • Negative Cross-Track Distance: Point lies in the hemiphere to the right of the great circle

Note: If the point A is the North or South Pole replace crs_AD-crs_AB with lon_D-lon_B or lon_B-lon_D, respectively

That was a lot of math, let’s see how that translates into a Python function. For the purpose of this example, let’s determine the forward bearing and distance between the great circle arc and the new point on an ellipsoid.

We will be creating two sides of a spherical triangle. Side 1 will be the great circle arc formed from Point A to Point B, while Side 2 will be a new great circle arc we will create from Point A to the new point C. We can use the angle—angular distance—between these two legs to determine the cross track distance:

Along Track Distance

Imagine a great circle arc that will appear like: A -------- C -------------------B, where the distance along the great circle arc (created from Point A to B) from Point A to Point C is the along-track distance.

This is defined as:

dat=arccos⁡(cos⁡(δ13)cos⁡(δxt))∗Rdat = \arccos(\frac{\cos(δ_{13})}{\cos(δ_{xt})}) * R
  • δ13 (δ13δ_{13}) is (angular) distance from start point to third point

  • δxt (δxtδ_{xt}) is (angular) cross-track distance

  • R is the earth’s radius

So,

dat=arccos⁡(cos⁡(δ13)cos⁡(δxt/R)∗Rd_{at} = \arccos(\frac{\cos(δ_{13})}{\cos(δ_{xt}/R)} * R
ATD=arccos⁡(cos⁡(distAD)cos⁡(XTD))ATD=\arccos(\frac{\cos(dist_{AD})}{\cos(XTD)})

However, for very short distances we can also use a new equation that is less susceptible to rounding errors:

ATD=arcsin⁡(sin⁡(distAD))2−(sin⁡(XTD))2)cos⁡(XTD)ATD=\arcsin(\sqrt{\frac{\sin(dist_{AD}))^2 - (\sin(XTD))^2 )}{\cos(XTD)}}

To similarly convert into a Python function, we will need to know the total length of the great circle arc from Point A to Point B. We will also measure the distance from the Point A to the new Point C along the great circle arc from Point A to Point B.

Determine Closest Point along Great Circle Arc

To be able to plot a cross track distance we need to find the point on the great circle that is closest to the new Point C. To do this we need to find the closest point from Point C to the arc and measure the along track distance that the intersection lies

Let’s see how of this looks on a map! Let’s plot!

In the previous notebook, we determined how to interpolate points along the great circle arc (interpolate_points_along_gc and arc_points). We will repeat the functions below to be able to use them to plot the great circle arc with the new information about cross-track and along-track distances

To begin, we will plot the cross track distance. This will look like a map with two arcs: one from Point A to Point B (the primary great circle arc) and a second that will show the angular distance between the great circle arc and a new point

  • Positive Cross-Track Distance: Point lies in the hemisphere to the left of the great circle

  • Negative Cross-Track Distance: Point lies in the hemiphere to the right of the great circle

Cross Track Distance: 
1593669.526094791 meters (1593.669526094791 km)
Along Track Distance: 
2076501.5510165778 meters (2076.5015510165777 km)

Closest Point To Point Along Great Circle Path:
(42.75525245755491, -80.62124342116076)
/home/runner/micromamba/envs/cookbook-gc/lib/python3.14/site-packages/cartopy/io/__init__.py:263: DownloadWarning: Downloading: https://naturalearth.s3.amazonaws.com/50m_physical/ne_50m_coastline.zip
  warnings.warn(f'Downloading: {url}', DownloadWarning)
/home/runner/micromamba/envs/cookbook-gc/lib/python3.14/site-packages/cartopy/io/__init__.py:263: DownloadWarning: Downloading: https://naturalearth.s3.amazonaws.com/50m_cultural/ne_50m_admin_0_boundary_lines_land.zip
  warnings.warn(f'Downloading: {url}', DownloadWarning)
<Figure size 1600x1000 with 2 Axes>

Determine if a point lies on a great circle arc and path

Does a given Point C lie on a great circle arc? Does it lie on the great circle path? We can check if a point lies on a great circle path/arc if:

  • Check if the latitude/longtiude matches the expected latitude that the same longitude position would have produced on the great circle path

This is possible with and without tolerances (in meters) to allow for some grace based on your precision.

Check if a point lies on a great circle arc

Let’s see this for ourselves. Does the city of Rockford lie on the great circle arc from Boulder to Boston?

Cross-Track Distance = 18201.48035911659 meters
False

Rockford is sitting about 18 km away from the great circle arc that is formed by Boulder and Boston. Let’s give it a look on a map:

Cross Track Distance: 
18201.48035911659 meters (18.20148035911659 km)
Along Track Distance: 
1378654.5186233742 meters (1378.654518623374 km)

Closest Point To Point Along Great Circle Path:
(42.434120910748035, -89.11630028269337)
<Figure size 1600x1000 with 2 Axes>

Hard to see, right? Let’s zoom in:

Cross Track Distance: 
18201.48035911659 meters (18.20148035911659 km)
Along Track Distance: 
1378654.5186233742 meters (1378.654518623374 km)

Closest Point To Point Along Great Circle Path:
(42.434120910748035, -89.11630028269337)
/home/runner/micromamba/envs/cookbook-gc/lib/python3.14/site-packages/cartopy/io/__init__.py:263: DownloadWarning: Downloading: https://naturalearth.s3.amazonaws.com/10m_physical/ne_10m_coastline.zip
  warnings.warn(f'Downloading: {url}', DownloadWarning)
/home/runner/micromamba/envs/cookbook-gc/lib/python3.14/site-packages/cartopy/io/__init__.py:263: DownloadWarning: Downloading: https://naturalearth.s3.amazonaws.com/10m_cultural/ne_10m_admin_0_boundary_lines_land.zip
  warnings.warn(f'Downloading: {url}', DownloadWarning)
/home/runner/micromamba/envs/cookbook-gc/lib/python3.14/site-packages/cartopy/io/__init__.py:263: DownloadWarning: Downloading: https://naturalearth.s3.amazonaws.com/10m_cultural/ne_10m_admin_1_states_provinces_lakes.zip
  warnings.warn(f'Downloading: {url}', DownloadWarning)
<Figure size 1600x1000 with 2 Axes>

18 km is far, but for the sake of clarity, maybe it serves our purposes as “on the arc”. If so, we can increase the tolerance of the function to about 18 km to encompass the town:

tolerance = 0
Cross-Track Distance = 18201.48035911659 meters
False

tolerance >= cross-track distance
Cross-Track Distance = 18201.48035911659 meters
True

(Optional) Additional Python Package: UXarray

UXarray acts as an Xarray extension for unstructured data (commonly used in climate and weather analysis). This includes multiple functions for working with great circles:

UXarray makes use of Cartesian coordinates and includes a very narrow built-in tolerance, but can be a simple solution if needed.

For example: Let’s check if a point lies on a great circle arc with UXarray (see example)

Boulder lies within the great circle arc = True

Summary

In this notebook, we calculated and plotted the cross track and along track distance for points around a great circle arc

What’s next?

Next, we will determine when a great circle path crosses a given parallel and the maximum and minimum latitude coordinates of a great circle path.

Resources and references