vecAngle {celltrackR} | R Documentation |
Angle Between Two Vectors
Description
Compute the angle between two vectors a and b, which can be numeric vectors
or matrices in which each row represents a numeric vector.
In the last case, one angle is returned for each row. By default, angles
are returned in degrees – set degrees = TRUE
to return radians.
Usage
vecAngle(a, b, degrees = TRUE)
Arguments
a |
the first vector or set of vectors. Must be a numeric vector or a matrix where each row represents a numeric vector. |
b |
the second vector or set of vectors, for which angles with the vector (set) a must be computed. Must have the same dimensions as a. |
degrees |
logical: if |
Value
A single angle (if a and b are single vectors) or a numeric vector of angles (if a and b are matrices; in that case, the output vector contains one angle for each row in matrices a and b).
Examples
## The angle between the vectors [0,1] and [1,0] is 90 degrees:
vecAngle( c(0,1), c(1,0) )
## The same holds for 3D angles:
vecAngle( c(0,1,0), c(1,0,0) )