Learn R Programming

stormwindmodel (version 0.1.4)

calc_bearing: Calculate bearing from one location to another

Description

Calculates the bearing of a second location, as seen from the first location, based on latitude and longitude coordinates for both locations.

Usage

calc_bearing(tclat_1, tclon_1, tclat_2, tclon_2)

Arguments

tclat_1

A numeric vector giving latitude of the first location (degrees)

tclon_1

A numeric vector giving longitude of the first location (degrees). This value should be expressed as a positive value for Western hemisphere longitudes.

tclat_2

A numeric vector giving latitude of the second location (degrees)

tclon_2

A numeric vector giving longitude of the second location (degrees). This value should be expressed as a positive value for Western hemisphere longitudes.

Value

A numeric vector giving the direction of the second location from the first location, in degrees. A direction of 0 degrees indicates the second location is due east of the first, 90 degrees indicates the second location is due north of the first, etc.

Details

This function uses the following equations to calculate the bearing from one latitude-longitude pair to another:

$$S = cos(\phi_2) * sin(L_1 - L_2)$$

$$C = cos(\phi_1) * sin(\phi_2) - sin(\phi_1) * cos(\phi_2) * cos(L_1 - L_2)$$

$$\theta = atan2(S, C) * \frac{180}{\pi} + 90$$

where:

  • \(\phi_1\): Latitude of first location, in radians

  • \(L_1\): Longitude of first location, in radians

  • \(\phi_2\): Latitude of second location, in radians

  • \(L_2\): Longitude of second location, in radians

  • \(S, C\): Intermediary results

  • \(\theta\): Direction of the storm movement, in degrees

In cases where this equation results in values below 0 degrees or above 360 degrees, the function applies modular arithmetic to bring the value back within the 0--360 degree range.