From 4719dae45924e0fea4d135a87abda4b412a20383 Mon Sep 17 00:00:00 2001 From: Andrew Lawson Date: Thu, 11 Dec 2014 02:39:11 -0500 Subject: [PATCH] Pretty much finished. --- geometric_separators.pde | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/geometric_separators.pde b/geometric_separators.pde index 8254749..69e8470 100644 --- a/geometric_separators.pde +++ b/geometric_separators.pde @@ -71,7 +71,6 @@ void mousePressed() { PVector point = new PVector(x, y, 0); PVector pointLifted = new PVector(point.x, point.y, (float)Math.pow(point.mag(), 2)); rawInput.add(pointLifted); - System.out.println(rawInput.size()); } } // If mouse presses calculate button @@ -81,8 +80,7 @@ void mousePressed() { System.out.println("You need at least 5 points!"); return; } - else if ((Math.log10((double)rawInput.size()) / Math.log10(5)) % 1 > 0.00000001) { - System.out.println((Math.log10(rawInput.size()) / Math.log10(5) % 1)); + else if ((Math.log(rawInput.size()) / Math.log(5)) % 1 > 0.001) { System.out.println("You don't have a power of 5!"); return; } @@ -105,12 +103,10 @@ PVector getRadonPoint(ArrayList points) { PVector radonPoint = null; radonPoint = inTetrahedron(points); if (radonPoint == null) { - System.out.println("TRIANGLE"); radonPoint = intersectTri(points); return radonPoint; } else { - System.out.println("TETRA"); return radonPoint; } } @@ -290,10 +286,19 @@ double[][] toDoubleArray(float[][] array) { // Get geometric separator CenterAndSphere getSeparator(ArrayList input) { PVector centerPoint = approxCenterpoint(input); + // Fix for centerPoint coming back null - not sure why this happens. + while (centerPoint == null) { + centerPoint = approxCenterpoint(input); + } PVector unitVector = PVector.random3D(); - unitVector.x = Math.abs(unitVector.x); - unitVector.y = Math.abs(unitVector.y); - unitVector.z = Math.abs(unitVector.z); + // Prevent the unit vector from being too small - radius becomes way too big. + while (unitVector.z < 0.5) { + unitVector = PVector.random3D(); + unitVector.x = Math.abs(unitVector.x); + unitVector.y = Math.abs(unitVector.y); + unitVector.z = Math.abs(unitVector.z); + } + System.out.println(unitVector.z); float radius = getRadius(centerPoint, unitVector); float[] sphereAttributes = getSphereAttr(centerPoint, unitVector, radius); PShape separator = createShape(ELLIPSE, sphereAttributes); @@ -326,7 +331,7 @@ ArrayList> samplePoints(ArrayList input) { // While there are still points, split into sets while (inputCopy.size() > 0) { double rnd = new Random().nextDouble(); - int index = (int)(rnd * 10) % inputCopy.size(); + int index = (int)(rnd * inputCopy.size()); // Add to set pointList.add(inputCopy.get(index)); inputCopy.remove(index); @@ -350,6 +355,9 @@ PVector approxCenterpoint(ArrayList input) { ArrayList radonList = new ArrayList(); for (ArrayList list : setList) { PVector radonPoint = getRadonPoint(list); + if (radonPoint == null) { + return null; + } radonList.add(radonPoint); } input = radonList;