torus_dist {ridgetorus} | R Documentation |
Toroidal distances
Description
Computation of distances on [-\pi, \pi)^d
, d\geq 1
,
between two sets of observations.
Usage
torus_dist(x, y, squared = FALSE)
Arguments
x |
a matrix of size |
y |
either a matrix with the same size as |
squared |
return the squared distance? Defaults to |
Details
The maximal distance on [-\pi, \pi)^d
is \sqrt{d}\pi
.
Value
A vector of size nx
with the distances between the
observations of x
and y
.
Examples
# Illustration of torus distances
n <- 10
x <- matrix(runif(2 * n, -pi, pi), nrow = n, ncol = 2)
y <- c(pi / 2, pi / 3)
col <- rainbow(n)
plot(x, xlim = c(-pi, pi), ylim = c(-pi, pi), axes = FALSE, col = col,
xlab = expression(theta[1]), ylab = expression(theta[2]), pch = 16)
sdetorus::torusAxis()
points(y[1], y[2], col = 1, pch = 17)
for (i in 1:n) {
sdetorus::linesTorus(x = c(x[i, 1], y[1]),
y = c(x[i, 2], y[2]), lty = 2, col = col[i])
}
text(x = x, labels = sprintf("%.2f", torus_dist(x, y)), col = col, pos = 1)
[Package ridgetorus version 1.0.2 Index]