The minimum distance between two arbitrary geometries is non-trivial and is only exactly defined for non-circular geometries. distance_squared() will return the exact squared distance between geometries with x and y being recycled to the maximum length of either. distance_matrix will return a matrix of distances given as numerics (and thus not exact), with the geometries of x in the rows and the geometries of y in the columns so that the value of mat[i, j] corresponds to the distance between x[i] and y[j].

distance_squared(x, y)

approx_distance_matrix(x, y)

## Arguments

x, y eometry vectors or bounding boxes

## Value

A euclid_exact_numeric vector for distance_squared() and a numeric matrix for distance_matrix()

## Examples

# Calculate distances between lines and rays in 3D
p <- point(sample(100, 20), sample(100, 20), sample(100, 20))
l <- line(p[1:5], p[6:10])
r <- ray(p[11:15], p[16:20])

# Pairwise exact distance
distance_squared(l, r)
#> <exact numerics >
#>   277.83139 1952.05705   13.46348  180.30916 2364.90037
# All distances
approx_distance_matrix(l, r)
#>            [,1]      [,2]      [,3]      [,4]       [,5]
#> [1,] 16.6682751 11.907760  7.305162  1.925140  0.5411494
#> [2,]  0.9550823 44.182090 27.894085 54.879626 43.4921308
#> [3,]  2.2641643 11.936908  3.669261  7.854165  7.2842733
#> [4,] 40.8338731  3.536245  3.023829 13.427925 16.8036308
#> [5,]  4.6013258 70.789292 60.004589 51.756396 48.6302413