watex.utils.get_bearing#

watex.utils.get_bearing(latlon1, latlon2, to_deg=True)[source]#

Calculate the bearing between two points.

A bearing can be defined as a direction of one point relative to another point, usually given as an angle measured clockwise from north. The formula of the bearing \(eta\) between two points 1(lat1 , lon1) and 2(lat2, lon2) is expressed as below:

\[eta = atan2(sin(y_2-y_1)*cos(x_2), cos(x_1)*sin(x_2) – sin(x_1)*cos(x_2)*cos(y_2-y_1))\]

where:

  • :math:`x_1`(lat1): the latitude of the first coordinate

  • :math:`y_1`(lon1): the longitude of the first coordinate

  • :math:`x_2`(lat2) : the latitude of the second coordinate

  • :math:`y_2`(lon2): the longitude of the second coordinate

Parameters:
  • latlon (Tuple ( latitude, longitude)) – A latitude and longitude coordinates of the first point in degree.

  • latlon2 (Tuple ( latitude, longitude)) – A latitude and longitude of coordinates of the second point in degree.

  • to_deg (bool, default=True) – Convert the bearing from radians to degree.

Returns:

Examples

>>> from watex.utils import get_bearing
>>> latlon1 = (28.41196763902007, 109.3328724432221) # (lat, lon) point 1
>>> latlon2= (28.38756530909265, 109.36931920880758) # (lat, lon) point 2
>>> get_bearing (latlon1, latlon2 )
127.26739270447973 # in degree