title: How would I organise a clustered set of 2D coordinates into groups of close together sets?
body: <p>I have a large amount of 2D sets of coordinates on a 6000x6000 plane (2116 sets), available here: <a href="http://pastebin.com/kiMQi7yu" rel="noreferrer">http://pastebin.com/kiMQi7yu</a> (the context isn't really important so I just pasted the raw data).</p>
  
  <p>I need to write an algorithm to group together coordinates that are close to each other by some threshold. The coordinates in my list are already in groups on that plane, but the order is very scattered.</p>
  
  <p>Despite this task being rather brain-melting to me at first, I didn't admit defeat instantly; this is what I tried:</p>
  
  <p>First sort the list by the Y value, then sort it by the X value. Run through the list checking the distance between the current set and the previous. If they are close enough (100 units) then add them to the same group.</p>
  
  <p>This method didn't really work out (as I expected). There are still objects that are pretty close that are in different groups, because I'm only comparing the next set in the list and the list is sorted by the X position.</p>
  
  <p>I'm out of ideas! The language I'm using is C but I suppose that's not really relevant since all I need is an idea for how the algorithm should work. Thanks!</p>