Learn R Programming

gear (version 0.1.5)

angle2d: Determine angle

Description

angle2d determines the angle between pairs of coordinates in degrees or radians. The coordinats are assumed to be in 2d space.

Usage

angle2d(coords1, coords2, radians = FALSE)

Arguments

coords1

An \(N \times 2\) matrix of spatial coordinates.

coords2

An \(N \times 2\) matrix of spatial coordinates.

radians

A logical indicating whether degrees or radians should be returned. Default is FALSE, meaning return angle in degrees.

Value

Returns a vector of angles.

Details

Note that the angle is between the actual pairs of points, not the angle between the vectors extending from the origin to the points. e.g., the angle between cbind(0, 1) and cbind(1, 1) would be 90 degrees, not 45. Sign of the direction not accounted for, e.g., a -135 degree angle is rotated by 180 degrees to become a 45 degree angle. All angles returned are in the interval [0, 180].

Examples

Run this code
# NOT RUN {
coords1 = matrix(0, nrow = 8, ncol = 2)
coords2 = cbind(c(2, 2, 0, -2, -2, -2, 0, 2), c(0, 2, 2, 2, 0, -2, -2, -2))
angle2d(coords1, coords2)
angle2d(coords1, coords2, radians = TRUE)
# }

Run the code above in your browser using DataLab