distanceToPoint {celltrackR} | R Documentation |
Distance to a Reference Point
Description
Compute the distance between the starting point of a track and a reference point. Useful to detect directed movement towards a point (see examples).
Usage
distanceToPoint(x, p = c(0, 0, 0), from = 1)
Arguments
x |
a single input track; a matrix whose first column is time and whose remaining columns are a spatial coordinate. |
p |
numeric vector of coordinates of the reference point p to compute distances to. |
from |
index, or vector of indices, of the first row of the track. If
|
Value
A single distance.
See Also
angleToPoint
to compute the angle to the reference point, and
AngleAnalysis
for other methods to compute angles and distances.
Examples
## Plotting the angle versus the distance to a reference point can be informative to
## detect biased movement towards that point. We should be suspicious especially
## when small angles are more frequent at lower distances.
steps <- subtracks( Neutrophils, 1 )
bb <- boundingBox( Neutrophils )
angles <- sapply( steps, angleToPoint, p = bb["max",-1] )
distances <- sapply( steps, distanceToPoint, p = bb["max",-1] )
scatter.smooth( distances, angles )
abline( h = 90, col = "red" )
[Package celltrackR version 1.2.0 Index]