NearestN:
Filter:
Classes (extension) | UGens > Analysis

NearestN : MultiOutUGen : UGen : AbstractFunction : Object
ExtensionExtension

Find the nearest-neighbours in a set of points

Description

This UGen takes an input point (such as a 2D or 3D location) and searches for the nearest few points in a dataset (by Euclidean distance).

You need the KDTree quark to generate the data for this UGen.

Class Methods

NearestN.kr(treebuf, in, gate: 1, num: 1)

Arguments:

treebuf

a Buffer containing data which MUST be in the special format created using the KDTree class and NearestN.makeBufferData

in

An array representing the input point. Num channels must match the dimensionality of the points in the dataset

gate

The unit is active while gate > 0. While <=0, no search is performed and output is held steady

num

Number of points to retrieve. NOT modulatable.

Returns:

A flat array containing (3 * num) channels, which is a ranked list of the nearest items (the very nearest coming first). For each match, this returns three channels [treeindex, distancesquared, label]

NearestN.makeBufferData(tree)

Processes a KDTree into a special format that can be loaded into a Buffer, and then searched by this UGen.

Inherited class methods

Instance Methods

Inherited instance methods

Examples

The most basic workflow is something like this:

This more complete example shows it in action: