As you know, KDTREE is an algorithm that efficiently sorts large amounts of data, and KNN (KNN) is the ability to search for a specific range of data using KD Tree.
This is an example code, which uses a recursive function to sort the data. We also leverage the Eucladian distance to run KNN.
$> cd KD-Tree_and_KNN
$> mkdir build && cd build
$> cmake .. && make
$> ./kdtree
_
▶ 1. You must choose Width and Height for Point Area [Width, Height]
▶ 2. Write the number of Points to create
▶ 3. Write the Root position [x, y] for find nearest point
▶ 4. Write K Point whatever you want. This is the number of Near position data of Root position
_
▶ 1. Write the Root position [x, y] for find nearest point
▶ 2. Write K Point whatever you want. This is the number of Near position data of Root position