Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

grouping points when they are close to each other

Tags:

algorithm

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, clustering 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.
My points' coordinates are not integer but float, and count of points can be few hundred (up to 500). And I don't want to break area on the same rectangles and just calculate how many point are there, I mean for example above I could make reactangles (0,0 - 3,2), (3,0 - 6,2), (0,3 - 3,6), (3,3 - 6,6) and just summarize points 2 for first rect, 1(!) for second what means leave it as it is, 1 for third and 1 for 4th => one rect will be drawn and all other points => wrong result according to the task. Any ideas? At least which algorithms can be helpful, where to look for...

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

like image 765
Maxym Avatar asked Mar 03 '10 18:03

Maxym


1 Answers

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.

like image 118
msw Avatar answered Nov 09 '22 21:11

msw