ekdtree implements Erlang interface to CGAL k-d tree and k-NN search algorithm.
ekdtree:new/1 constructs tree from points which are 4-tuples of integer Id, and float XYZ coordinates:
Points = [{0, 10.0, 10.0, 10.0}, {1, 10.0, 10.0, -10.0}, {2, 10.0,-10.0, 10.0}],
{ok, Tree} = ekdtree:new(Points).
ekdtree:size/1 returns a number of points:
3 = ekdtree:size(Tree).
ekdtree:search/3 returns an ordered list of K nearest neighbors along with a transformed (squared) distance(s):
Knn = ekdtree:search(Tree, {5.0, 5.0, 10.0}, 2),
[{0, 50.0}, {2, 250.0}])] = Knn.