bearing: Calculate the bearing given two points

Description Usage Arguments Value Examples

View source: R/bearing.R

Description

This function calculates the bearing (direction) for something (e.g. an animal) moving from point 1 to point 2.

Usage

1
bearing(x, y, x2, y2)

Arguments

x

Longitude of point 1

y

Latitude of point 1

x2

Longitude of point 2

y2

Latitude of point 2

Value

Bearing in radians from point 1 to point 2 (from -pi to pi)

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# Example 1
bearing(x = 0, y = 0, x2 = 2, y2 = 2)

# Example 2
library(data.table)

d = data.table(x  = rep(0, 21),
               y  = rep(0, 21),
               x2 = seq(-10, 10, 1),
               y2 = rep(2, 21) )

               d[, bearing := bearing(x, y, x2, y2), by = 1:nrow(d)]

               plot(bearing ~ x2, d, type = 'l')

mpio-be/windR documentation built on Feb. 2, 2020, 10:04 a.m.