clouddrift.sphere.bearing

Contents

clouddrift.sphere.bearing#

clouddrift.sphere.bearing(lon1: float | list | ndarray | DataArray, lat1: float | list | ndarray | DataArray, lon2: float | list | ndarray | DataArray, lat2: float | list | ndarray | DataArray) float | ndarray[source]#

Return elementwise initial (forward) bearing in radians from arrays of latitude and longitude in degrees, based on the spherical law of cosines.

The formula is:

θ = atan2(cos φ1 ⋅ sin φ2 - sin φ1 ⋅ cos φ2 ⋅ cos Δλ, sin Δλ ⋅ cos φ2)

where (φ, λ) is (lat, lon) and θ is bearing, all in radians. Bearing is defined as zero toward East and positive counterclockwise.

Parameters#

lon1float or array-like

Longitudes of the first set of points, in degrees

lat1float or array-like

Latitudes of the first set of points, in degrees

lon2float or array-like

Longitudes of the second set of points, in degrees

lat2float or array-like

Latitudes of the second set of points, in degrees

Returns#

thetafloat or np.ndarray

Bearing angles in radians

Examples#

Calculate the bearing of one degree longitude on the equator:

>>> bearing(0, 0, 1, 0)
0.0

Calculate the bearing of 10 degrees longitude at 45-degrees North latitude:

>>> bearing(0, 45, 10, 45)
0.06178508761798218