You need an algorithm that does this, starting with a set of points.
- If there are no points in the set, then stop.
- Make a new set (the current object), and choose any point out of the original set to be the first point in the new set.
- Remove the chosen point from the set and add it to the current object.
- Check each of the chosen point's eight neighbours to see if any are in the original set.
- For any point thus found, run this algorithm starting from step 3 (use recursion for this).
- If none of the neighbours were in the original set, go back to step 1.