Tree Search Algorithm
'kd tree' search algorithm - nearest neighbour problems

This script implements a ‘kd tree’ search algorithm. Two functions are included:
MakeTree – this function creates the kd tree structure. It has two input arguments: The function returns a tree structure object containing the flagged nodes of the given model. CheckTree – this function traverses the tree and finds the node nearest a given point. It has two input arguements: CheckTree does not return a value, instead it adds two properties to the input point: Additionally three search functions and a ‘distance between two nodes’ function is included (and referenced by the core functions). KD trees are very efficient when the likely distance between point and neighbour is unknown (making a BucketSearch more difficult). For large problems the time overhead is mostly in the MakeTree functions, checking the tree is typically very fast. In this example, the user selects nodes on one part and the nearest node on the neighbouring part is then sketched. A timer is included for interest. |