closepairs.pp3
Close Pairs of Points in 3 Dimensions
Low-level functions to find all close pairs of points in three-dimensional point patterns.
Usage
# S3 method for pp3
closepairs(X, rmax, twice=TRUE,
what=c("all", "indices", "ijd"),
distinct=TRUE, neat=TRUE, …)# S3 method for pp3
crosspairs(X, Y, rmax, what=c("all", "indices", "ijd"), …)
Arguments
- X,Y
Point patterns in three dimensions (objects of class
"pp3"
).- rmax
Maximum distance between pairs of points to be counted as close pairs.
- twice
Logical value indicating whether all ordered pairs of close points should be returned. If
twice=TRUE
, each pair will appear twice in the output, as(i,j)
and again as(j,i)
. Iftwice=FALSE
, then each pair will appear only once, as the pair(i,j)
such thati < j
.- what
String specifying the data to be returned for each close pair of points. If
what="all"
(the default) then the returned information includes the indicesi,j
of each pair, theirx,y,z
coordinates, and the distance between them. Ifwhat="indices"
then only the indicesi,j
are returned. Ifwhat="ijd"
then the indicesi,j
and the distanced
are returned.- distinct
Logical value indicating whether to return only the pairs of points with different indices
i
andj
(distinct=TRUE
, the default) or to also include the pairs wherei=j
(distinct=FALSE
).- neat
Logical value indicating whether to ensure that
i < j
in each output pair, whentwice=FALSE
.- …
Ignored.
Details
These are the efficient low-level functions used by spatstat to find all close pairs of points in a three-dimensional point pattern or all close pairs between two point patterns in three dimensions.
closepairs(X,rmax)
identifies all pairs of neighbours
in the pattern X
and returns them. The result is
a list with the following components:
- i
Integer vector of indices of the first point in each pair.
- j
Integer vector of indices of the second point in each pair.
- xi,yi,zi
Coordinates of the first point in each pair.
- xj,yj,zj
Coordinates of the second point in each pair.
- dx
Equal to
xj-xi
- dy
Equal to
yj-yi
- dz
Equal to
zj-zi
- d
Euclidean distance between each pair of points.
If what="indices"
then only the components i
and
j
are returned. This is slightly faster.
crosspairs(X,rmax)
identifies all pairs of neighbours
(X[i], Y[j])
between the patterns X
and Y
,
and returns them. The result is
a list with the same format as for closepairs
.
Value
A list with components i
and j
,
and possibly other components as described under Details.
Warning about accuracy
The results of these functions may not agree exactly with
the correct answer (as calculated by a human) and may not
be consistent between different computers and different installations
of R. The discrepancies arise in marginal cases where the interpoint
distance is equal to, or very close to, the threshold rmax
.
Floating-point numbers in a computer
are not mathematical Real Numbers: they are approximations using
finite-precision binary arithmetic.
The approximation is accurate to a tolerance of about
.Machine$double.eps
.
If the true interpoint distance \(d\) and the threshold rmax
are equal, or if their difference is no more than .Machine$double.eps
,
the result may be incorrect.
See Also
Examples
# NOT RUN {
X <- pp3(runif(10), runif(10), runif(10), box3(c(0,1)))
Y <- pp3(runif(10), runif(10), runif(10), box3(c(0,1)))
a <- closepairs(X, 0.1)
b <- crosspairs(X, Y, 0.1)
# }