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].

## Usage

distance_squared(x, y, ...)

approx_distance_matrix(x, y, ...)

## Arguments

x, y

geometry vectors or bounding boxes

...

arguments passed on to methods

## Value

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

Other Measures: approx_angle(), geometry_measures

## 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 >
#>   421.77716 2752.98285 4091.17283   42.85453  434.08593

# All distances
approx_distance_matrix(l, r)
#>          [,1]        [,2]     [,3]      [,4]      [,5]
#> [1,] 20.53721 37.29638945 31.05899  6.438624 16.561279
#> [2,] 50.63798 52.46887505 79.76332 43.295951  1.068073
#> [3,] 24.33127 21.95942727 63.96228 29.736150 24.283498
#> [4,] 13.73086 30.42585356 15.92796  6.546337 33.089933
#> [5,] 13.29732  0.05472641 23.98094 14.912519 20.834729