Computes the flat-torus distance between each row of X and the
point p: for each coordinate, the shortest wraparound distance
min(|x-p|, 1-|x-p|) on the unit circle, combined across
coordinates via the usual Euclidean norm.
Arguments
- X
A matrix or data frame of torus data in \([0,1)^d\); rows are
samples, columns are coordinates.
- p
Numeric vector of length ncol(X): a point on the torus.
Value
Numeric vector of length nrow(X): the torus distance from
each row of X to p.
Examples
X <- matrix(runif(20), nrow = 10, ncol = 2)
dist_torus(X, c(0.5, 0.5))
#> [1] 0.3862986 0.2257753 0.1360062 0.2427071 0.2138850 0.6169328 0.1618739
#> [8] 0.3004848 0.4296474 0.4127701