Skip to contents

Given a set of locations defining a trajectory, this function computes the linear distances between each pair of successive locations along the trajectory.

Usage

linear_dist(x, y, geo = FALSE)

linDist(x, y, geo = FALSE)

Arguments

x

A vector of x (or longitude) coordinates corresponding to a single trajectory.

y

A vector of y (or latitude) coordinates corresponding to a single trajectory.

geo

A logical value indicating whether the locations are defined by geographic coordinates (pairs of longitude/latitude values). Default: FALSE.

Value

A vector of the same length as x and y corresponding to the linear distances between each pair of successive locations along the trajectory.

Author

Simon Garnier, garnier@njit.edu

Examples

x <- rnorm(25)
y <- rnorm(25, sd = 3)
linear_dist(x, y)
#>  [1] 0.0000000 2.1224557 6.4515769 7.4805521 6.6275497 2.2168288 0.3966968
#>  [8] 4.9869101 1.6330218 4.9397814 2.8045739 3.9143356 2.5650248 0.9565507
#> [15] 2.2529109 4.2216233 4.4858431 4.9944346 6.1745498 4.4643456 2.3386291
#> [22] 5.9363143 1.8681482 4.4162667 3.2274435