1.0.1 • Published 10 months ago

copper3d-tree v1.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
10 months ago

kdtree

==============

Aim

  • For more easier to develop vue app.

Original

static-kdtree

Example

//Import library
import createKDTree from "copper3d-tree";

//Create a bunch of points
var points = [
  [0, 1, 100],
  [-5, 0.11, Math.PI],
  [0, 10, -13],

  // ...

  [4, 3, 1],
];

//Create the tree
var tree = createKDTree(points);

//Iterate over all points in the bounding box
tree.range([-1, -1, -1], [10, 1, 2], function (idx) {
  console.log("visit:", idx); //idx = index of point in points array
});

//Can also search in spheres
tree.rnn([0, 0, 0], 10, function (idx) {
  console.log("point " + idx + " is in sphere at origin with radius=10");
});

//Nearest neighbor queries
console.log("index of closest point to [0,1,2] is ", tree.nn([0, 1, 2]));

//And k-nearest neighbor queries
console.log(
  "index of 10 closest points to [0,1,2] are ",
  tree.knn([0, 1, 2], 10)
);

//For performance, be sure to delete tree when you are done with it
tree.dispose();

Install

npm install copper3d-tree

API

import createKDTree from "copper3d-tree";

By convention, let n denote the number of points and d denote the dimension of the kdtree.

Constructor

Mikola Lysenko