Helper Functions¶
Constants¶
-
py1090.helpers.
EARTH_RADIUS
= 6371008.7714¶ The average earth radius \(R_0\). It is defined as the mean radius of the semi-axes. The values are taken from the WGS 84 (World Geodetic System 1984) ellipsoid (definition of the Department Of Defense, Jan. 2000, p. 37) .
\[R_0 = 6371008.7714 \mathrm{m}\]
Position geometry¶
-
py1090.helpers.
distance_between
(lat1, lon1, lat2, lon2)[source]¶ Calculates the distance between two locations, in meters, using the Haversine formula.
The bearing between latitude, longitude: \((\phi_1, \lambda_1)\) and \((\phi_2, \lambda_2)\) is given by
\[a = \sin^2(\frac{\phi_2 - \phi_1}{2}) + \cos(\phi_1) \cos(\phi_2) \sin^2(\frac{\lambda_2 - \lambda_1}{2})\]\[d = 2 R_0 \cdot \mathrm{atan2}(\sqrt{a}, \sqrt{1-a})\]The earth radius \(R_0\) is taken to be
py1090.helpers.EARTH_RADIUS
. The approximation of a spherical earth is made.Parameters: Returns: the distance in meters.
Return type:
-
py1090.helpers.
bearing_between
(lat1, lon1, lat2, lon2)[source]¶ Calculates the bearing angle between two locations, in radians.
The bearing between latitude, longitude: \((\phi_1, \lambda_1)\) and \((\phi_2, \lambda_2)\) is given by
\[\mathrm{atan2}(\sin(\lambda_2 - \lambda_1) \cos(\phi_1), \cos(\phi_2) \sin(\phi_1) - \sin(\phi_2) \cos(\phi_2) \cos(\lambda_2 - \lambda_1))\]Parameters: Returns: the bearing angle in radians, between \(-\pi\) and \(\pi\).
Return type: