diff --git a/geometric_separators.pde b/geometric_separators.pde index b79ba99..2759947 100644 --- a/geometric_separators.pde +++ b/geometric_separators.pde @@ -120,6 +120,7 @@ void mousePressed() { // Get geometric median PVector getGeometricMedian(ArrayList input) { + System.out.println("Geometric median..."); if (input.size() == 0) { return null; } @@ -135,24 +136,25 @@ PVector getGeometricMedian(ArrayList input) { } // Sample input points into sets of 4 -ArrayList> samplePoints(ArrayList input) { - ArrayList setList = new ArrayList>(); - Set pointSet = new Set(); +ArrayList> samplePoints(ArrayList input) { + ArrayList> setList = new ArrayList>(); + HashSet pointSet = new HashSet(); // While there are still points, split into sets - while (input.size() > 0) { - int rnd = new Random().nextInt(); - int index = (rnd * (input.size())); + while (input.size() > 1) { + System.out.println("Sampling..."); + double rnd = new Random().nextDouble(); + int index = (int)(rnd * 10) % input.size(); // Add to set pointSet.add(input.get(index)); // Create new set on max size if (pointSet.size() == 4) { setList.add(pointSet); - pointSet = new Set(); + pointSet = new HashSet(); } } // Add most recent unempty set to list if (pointSet.size() > 0) { - setList.add(pointSet) + setList.add(pointSet); } return setList; } @@ -161,23 +163,22 @@ ArrayList> samplePoints(ArrayList input) { PVector approxCenterpoint(ArrayList input) { if (input.size() == 0) { System.out.println("You don't have any input points!"); + return null; } else { // Algorithm // Repeat 1 - 3 until one point remains and return that point - while (input.size > 1) { + while (input.size() > 1) { // 1. Sample points into groups of 4 - ArrayList> setList = samplePoints(input); + ArrayList> setList = samplePoints(input); // 2. Compute radon point of each group (geometric median) ArrayList radonList = new ArrayList(); - for (Set set : setList) { + for (HashSet set : setList) { PVector radonPoint = getGeometricMedian(input); - else { - radonList.add(radonPoint); - } + radonList.add(radonPoint); // 3. Set input to be new radon points - input = radonList; } + input = radonList; } return input.get(0); }