This project can be used as a framework, or you can just drag KDTree.h, KDTree.m, KDNode.h, KDNode.m, KDLeaf.h, and KDLeaf.m into your existing project. To use it, just instantiate a KDTree object and pass it a 2-Dimensional array with the method -(id)initWithArray:(NSArray*)array. The 2D array should be an array of arrays that contain any number of points (your coordinates) and the final element must be metadata (it can be any type of object: NSString, NSArray, or your own custom object). So for a 3D tree the array would look like: {{1, 2, 3, metadata}, {3, 6, 7, metadata}, {4, 1, 7, metadata}, ... }. The tree can then be searched with the method -(KDLeaf*)findApproximateNearestNeighbor:(NSArray*)coordinates, or -(KDLeaf*)findNearestNeighbor:(NSArray*)coordinates. Each method takes an NSArray of numbers (e.g., for a 3D tree {3, 4, 1}) and will return the KDLeaf with the nearest coordinates, you can then get the coordinates of the KDLeaf (it is an NSArray called: points) and the metadata (it is an id: metadata). findApproximateNearestNeighbor will be incredibly fast, but not always accurate. findNearestNeighbor is accurate, but can be anywhere from a little bit to much slower.
-
Notifications
You must be signed in to change notification settings - Fork 1
An easy to use implementation of k-dimensional tree creation and searching in objective-c for cocoa
License
Bronson-Brown-deVost/KDTree
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
An easy to use implementation of k-dimensional tree creation and searching in objective-c for cocoa
Resources
License
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published