grouping points when they are close to each other
I have 2d-points (x,y) with float coordinates, when I draw them, I need to group points if they are close to each other, and they should be grouped iwith help of rectangle with fixed size. And the problem is that these rectangles should not intersect, and all points-neighbours should be grouped.
If you have a paper nearby, you can draw a big rectangle, for instance 4*5cm - area where all points are located. Now randomly put points, and let's say, if there are points whose distance is 1 cm - they should be grouped in rectangle 2*3.I can't find algorithm how to make it, and performance matters too... I looked for nesting, clusteri开发者_开发技巧ng but what I need is a little bit different. And by the way, if some grouping rectangles have to be out of common area to fit conditions, let it be, it is not a problem. E.g. you have area 4*5, and points
(1,0), (2,1), (4,1), (4,3), (2,4)
then result should like rectangles (0,0 - 3,2) & (3,1 - 6,3) and one point left (2,4)
because all other point were grouped and this point does not have any neighbours now.
P.S. for now number of groups/points in result does not matter, e.i. another allowed result for example above could be (1,0-4,2) and (2,2-5,4) rectangles, and no points left
The general problem is the "nearest neighbor" search. Solutions are computationally hard (time complexity). That which is a pretty easy task for humans isn't so easy computationally.
精彩评论