Determines the heading between spatial points.

heading(from, to)

# S4 method for SpatialPoints,SpatialPoints
heading(from, to)

# S4 method for matrix,matrix
heading(from, to)

# S4 method for matrix,SpatialPoints
heading(from, to)

# S4 method for SpatialPoints,matrix
heading(from, to)

Arguments

from

The starting position; an object of class SpatialPoints.

to

The ending position; an object of class SpatialPoints.

Value

The heading between the points, in degrees.

Examples

library(sp) N <- 10L # number of agents x1 <- stats::runif(N, -50, 50) # previous X location y1 <- stats::runif(N, -50, 50) # previous Y location x0 <- stats::rnorm(N, x1, 5) # current X location y0 <- stats::rnorm(N, y1, 5) # current Y location # using SpatialPoints prev <- SpatialPoints(cbind(x = x1, y = y1)) curr <- SpatialPoints(cbind(x = x0, y = y0)) heading(prev, curr)
#> [1] 134.966074 76.404123 3.865539 281.727773 316.915898 324.598216 #> [7] 226.947345 309.777891 237.550413 343.233212
# using matrix prev <- matrix(c(x1, y1), ncol = 2, dimnames = list(NULL, c("x","y"))) curr <- matrix(c(x0, y0), ncol = 2, dimnames = list(NULL, c("x","y"))) heading(prev, curr)
#> [1] 134.966074 76.404123 3.865539 281.727773 316.915898 324.598216 #> [7] 226.947345 309.777891 237.550413 343.233212
#using both prev <- SpatialPoints(cbind(x = x1, y = y1)) curr <- matrix(c(x0, y0), ncol = 2, dimnames = list(NULL, c("x","y"))) heading(prev, curr)
#> [1] 134.966074 76.404123 3.865539 281.727773 316.915898 324.598216 #> [7] 226.947345 309.777891 237.550413 343.233212
prev <- matrix(c(x1, y1), ncol = 2, dimnames = list(NULL, c("x","y"))) curr <- SpatialPoints(cbind(x = x0, y = y0)) heading(prev, curr)
#> [1] 134.966074 76.404123 3.865539 281.727773 316.915898 324.598216 #> [7] 226.947345 309.777891 237.550413 343.233212