views:

78

answers:

1

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

+1  A: 

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.

msw
for now I have more problems with covering points by rectangles :) let's say that I know all sets of points which have to be grouped, how to "put" rectangles on them the way that all rectangles does not intersect each other in result...
Maxym
I'm pushing the limits of my knowledge of space partitioning algorithms, but it appears that kd-trees are designed to ease the O(n^2) pain of searching for overlaps. Indeed, if you use kd-trees to partition the original set of points, non-overlapping rectangles will be an invariant property of the result. http://en.wikipedia.org/wiki/Kd_tree
msw
maybe, maybe... but I'm afraid then when we have more data than in the example from wiki, and taking into account size of rectangle which I use to cover them, then it won't work. I have to think about it more. Yes, the decomposition cares about overlapping, but in general decomposition does not care about size of rectangles - that's why I'm not sure. But it worth to think about. thank you for pointing
Maxym