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

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, ..., k=1, method="C")

Arguments

X

A line segment pattern (object of class "psp").

...

Ignored.

k

Integer, or integer vector. The algorithm will compute the distance to the kth nearest neighbour.

method

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

Details

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

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. The argument k can also be a vector, and this computation will be performed for each value of k.

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 max(k)+1 line segments in the pattern, some of the 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="C" (the default) then compiled C code is used. The C code is somewhat faster.

Value

Numeric vector or matrix containing the nearest neighbour distances for each line segment.

If k = 1 (the default), the return value is a numeric vector v such that v[i] is the nearest neighbour distance for the ith segment.

If k is a single integer, then the return value is a numeric vector v such that v[i] is the kth nearest neighbour distance for the ith segment.

If k is a vector, then the return value is a matrix m such that m[i,j] is the k[j]th nearest neighbour distance for the ith segment.

Author(s)

and Rolf Turner r.turner@auckland.ac.nz

See Also

Examples

L <- psp(runif(10), runif(10), runif(10), runif(10), owin())
   D <- nndist(L)
   D <- nndist(L, k=1:3)

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.