Learn R Programming

shotGroups (version 0.8.2)

getMaxPairDist: Maximum pairwise distance for a set of points

Description

Calculates the maximum of pairwise distances between points given a set of coordinates.

Usage

getMaxPairDist(xy)

# S3 method for data.frame getMaxPairDist(xy)

# S3 method for default getMaxPairDist(xy)

Value

A list with the following components

d

numerical value with the maximum pairwise distance between points.

idx

a vector with two entries giving the row indices of the points that are farthest apart.

Arguments

xy

either a numerical (n x p)-matrix with the coordinates of n points in p-dimensional space (1 row of coordinates per point), or a data frame with either the variables x, y or point.x, point.y.

Examples

Run this code
# coordinates given by a suitable data frame
(maxPD <- getMaxPairDist(DFsavage))

# plot points and point pair with maximum distance
plot(point.y ~ point.x, data=DFsavage, asp=1, pch=16)
x0 <- DFsavage$point.x[maxPD$idx[1]]     # 1st point x
y0 <- DFsavage$point.y[maxPD$idx[1]]     # 1st point y
x1 <- DFsavage$point.x[maxPD$idx[2]]     # 2nd point x
y1 <- DFsavage$point.y[maxPD$idx[2]]     # 2nd point y
segments(x0, y0, x1, y1, col="green3", lwd=2)

# coordinates given by a matrix
if (FALSE) {
xy <- matrix(round(rnorm(20, 100, 15), 1), ncol=2)
getMaxPairDist(xy)
}

Run the code above in your browser using DataLab