# 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)
Run the code above in your browser using DataLab