Learn R Programming

celltrackR (version 1.2.1)

distanceToPoint: 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)

Value

A single distance.

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 from is a vector, distances are returned for all steps starting at the indices in from.

See Also

angleToPoint to compute the angle to the reference point, and AngleAnalysis for other methods to compute angles and distances.

Examples

Run this code
## 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" )

Run the code above in your browser using DataLab