spatstat (version 1.11-8)

nndist.psp: Nearest neighbour distances between line segments

Description

Computes the distance from each line segment to its nearest neighbour in a line segment pattern. Alternatively finds the distance to the second nearest, third nearest etc.

Usage

## S3 method for class 'psp':
nndist(X, \dots, k=1, method="Fortran")

Arguments

X
A line segment pattern (object of class "psp").
...
Ignored.
k
Integer. The algorithm will find the distance to the kth nearest neighbour.
method
String specifying which method of calculation to use. Values are "Fortran" and "interpreted". Usually not specified.

Value

  • A numeric vector whose [i] entry is the distance from the line segment numbered i to the nearest other line segment (or in general the distance to the kth nearest line segment).

Details

If k=1, this function computes the distance from each line segment to the nearest other line segment in X. In general it computes the distance from each line segment to the kth nearest other line segment.

This is a method for the generic function nndist for the class "psp".

Distances are calculated using the Hausdorff metric. The Hausdorff distance between two line segments is the maximum distance from any point on one of the segments to the nearest point on the other segment.

If there are fewer than k line segments in the pattern, the kth nearest neighbour distances will be infinite (Inf). 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="Fortran" (the default) then Fortran code is used. The Fortran code is somewhat faster.

See Also

nndist, nndist.ppp

Examples

Run this code
L <- psp(runif(10), runif(10), runif(10), runif(10), owin())
   D <- nndist(L)

Run the code above in your browser using DataCamp Workspace