Closest distance between two Euclidian grids

Did you check NearestNeighbors.jl?

Including herein a MWE, that hopefully is correct:

using NearestNeighbors, Random, Printf

# create input data:
Random.seed!(1);    A = rand(3, 1_500_000)
Random.seed!(1234); B = rand(3, 1_500)

kdtree = KDTree(A)
idxs, dists = nn(kdtree, B)  # convenience function for k=1
ixb = argmin(dists)
ixa = idxs[ixb]
@printf("Minimum distance = %.5f, at:", dists[ixb])
@printf("A[:,%i] = (%.4f, %.4f, %.4f)\n", ixa, A[:,ixa]...)   # splatted values supported
@printf("B[:,%i] = (%.4f, %.4f, %.4f)\n", ixb, B[:,ixb]...)   #

# Printed results:
Minimum distance = 0.00045, at:
A[:,1080399] = (0.3572, 0.1117, 0.4786)
B[:,1136] = (0.3571, 0.1119, 0.4790)

# QC solution:
using LinearAlgebra
julia> dists[ixb] ≈ norm(A[:,ixa] -  B[:,ixb])
true
4 Likes