Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

crossdist.default

Pairwise distances between two different sets of points


Description

Computes the distances between each pair of points taken from two different sets of points.

Usage

## Default S3 method:
crossdist(X, Y, x2, y2, ...,
             period=NULL, method="C", squared=FALSE)

Arguments

X,Y

Numeric vectors of equal length specifying the coordinates of the first set of points.

x2,y2

Numeric vectors of equal length specifying the coordinates of the second set of points.

...

Ignored.

period

Optional. Dimensions for periodic edge correction.

method

String specifying which method of calculation to use. Values are "C" and "interpreted".

squared

Logical. If squared=TRUE, the squared distances are returned instead (this computation is faster).

Details

Given two sets of points, this function computes the Euclidean distance from each point in the first set to each point in the second set, and returns a matrix containing these distances.

This is a method for the generic function crossdist.

This function expects X and Y to be numeric vectors of equal length specifying the coordinates of the first set of points. The arguments x2,y2 specify the coordinates of the second set of points.

Alternatively if period is given, then the distances will be computed in the ‘periodic’ sense (also known as ‘torus’ distance). The points will be treated as if they are in a rectangle of width period[1] and height period[2]. Opposite edges of the rectangle are regarded as equivalent.

The argument method is not normally used. It is retained only for checking the validity of the software. If method = "interpreted" then the distances are computed using interpreted R code only. If method="C" (the default) then C code is used. The C code is faster by a factor of 4.

Value

A matrix whose [i,j] entry is the distance from the i-th point in the first set of points to the j-th point in the second set of points.

Author(s)

See Also

Examples

d <- crossdist(runif(7), runif(7), runif(12), runif(12))
   d <- crossdist(runif(7), runif(7), runif(12), runif(12), period=c(1,1))

spatstat.geom

Geometrical Functionality of the 'spatstat' Family

v2.1-0
GPL (>= 2)
Authors
Adrian Baddeley [aut, cre], Rolf Turner [aut], Ege Rubak [aut], Tilman Davies [ctb], Ute Hahn [ctb], Abdollah Jalilian [ctb], Sebastian Meyer [ctb], Suman Rakshit [ctb], Dominic Schuhmacher [ctb], Rasmus Waagepetersen [ctb]
Initial release
2021-04-15

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.