Skip to content

k-nearest neighbors search (KNN) for RBush-3D

License

Notifications You must be signed in to change notification settings

ion9/rbush-3d-knn

 
 

Repository files navigation

rbush-3d-knn

k-nearest neighbors search for RBush-3D. Implements a simple depth-first kNN search algorithm using a priority queue.

var RBush = require('rbush-3d');
var knn = require('rbush-knn');

var tree = new RBush(); // create RBush tree
tree.load(data); // bulk insert
var neighbors = knn(tree, 40, 40, 40, 10); // return 10 nearest items around point [40, 40, 40]

You can optionally pass a filter function to find k neighbors that satisfy a certain condition:

var neighbors = knn(tree, 40, 40, 40, 10, function (item) {
    return item.foo === 'bar';
});

API

knn(tree, x, y, z, [k, filterFn, maxDistance])

  • tree: an RBush tree
  • x, y, z: query coordinates
  • k: number of neighbors to search for (Infinity by default)
  • filterFn: optional filter function; k nearest items where filterFn(item) === true will be returned.
  • maxDistance (optional): maximum distance between neighbors and the query coordinates (Infinity by default)

Changelog

0.0.1 (Nov 12, 2020)
  • Rework rbush-knn to work with rbush-3d

About

k-nearest neighbors search (KNN) for RBush-3D

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%