Reputation: 8424
Given a collection of points on a 2D plane, I want to find collections of X
points that are within Y
of each other. For example:
8|
7| a b
6|
5| c
4|
3| e
2| d
1|
-------------------------
1 2 3 4 5 6 7 8 9 0 1
a
, b
, c
and d
are points on the 2D plane. Given arguments of 3 for the number of points (X
) and 3 for the distance (Y
), the algorithm would return [[a, b, c]]
. Some examples:
algorithm(X = 3, Y = 3) returns [[a, b, c]]
algorithm(X = 2, Y = 3) returns [[a, b, c], [d, e]] -- [a, b, c] contains at least two points
algorithm(X = 4, Y = 3) returns [] -- no group of 4 points close enough
algorithm(X = 5, Y = 15) returns [[a, b, c, d, e]]
Constraints:
Things I've tried:
Upvotes: 2
Views: 89
Reputation: 65427
With only 800 points, you can probably just build the graph by comparing each pair, then run Bron--Kerbosch to find maximal cliques. Here's a legit-seeming Javascript implementation of that algorithm: https://github.com/SeregPie/almete.BronKerbosch
Upvotes: 1