This article was inactive for a long time, but I ran into this problem and solved this problem quite well, so I will publish it so that others do not have to do the same head scratches.
You can consider the immediate problem of the nearest environment as searching for the nearest neighbor of a 3d point in the kd or octree tree. Define the distance between the two circles A and B as
D(A,B) = sqrt( (xA - xB)^2 + (yA - yB)^2 ) - rA - rB
This is a negative value if the circles overlap. For this discussion, I'll take an octet, but the kd tree with k = 3 is similar.
Save the triple (x, y, r) in an octet for each circle.
To find the closest neighbor to the target circle T, use the standard algorithm:
def search(node, T, nst) if node is a leaf update nst with node (x,y,r) nearest to T else for each cuboid C subdividing node (there are 8 of them) if C contains any point nearer to T than nst search(C, T, nst) end end
Here nst is a link to the closest circle to T found so far. It is initially null.
It's a little tricky to determine if C contains any point nearer to T than nst . To do this, it is enough to consider a single point (x, y, r) inside C, which is Euclidean, closest to T in x and y and has the maximum value of the range r contained in the cuboid. In other words, a cuboid is a set of circles with centers located above a rectangular area in x and y and with a range of radii. The point you want to check is a point representing a circle with the center closest to T and with the largest radius.
Note that the radius T does not play any role in the algorithm. You only agree with how far the center of T. is located inside any other circle (I would like it to be as obvious in the beginning as it seems now ...)