Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added random button.
  • Loading branch information
Andrew Lawson authored and Andrew Lawson committed Dec 11, 2014
1 parent ed22d97 commit ae84960
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions geometric_separators.pde
Expand Up @@ -2,22 +2,26 @@ import java.util.*;
import java.util.Map.*; import java.util.Map.*;
import java.lang.Boolean; import java.lang.Boolean;
import java.util.Random; import java.util.Random;
import org.jblas.*;
import org.apache.commons.math3.linear.*; import org.apache.commons.math3.linear.*;
import org.apache.commons.math3.linear.LUDecomposition; import org.apache.commons.math3.linear.LUDecomposition;


int reset_x = 140; int reset_x = 90;
int reset_y = 460; int reset_y = 460;
int reset_w = 100; int reset_w = 100;
int reset_h = 25; int reset_h = 25;
int calc_x = 250; int calc_x = 200;
int calc_y = 460; int calc_y = 460;
int calc_w = 100; int calc_w = 100;
int calc_h = 25; int calc_h = 25;
int rand_x = 310;
int rand_y = 460;
int rand_w = 100;
int rand_h = 25;


PShape reset; PShape reset;
PShape calculate; PShape calculate;
PShape sphere; PShape sphere;
PShape random;
PVector centerPoint; PVector centerPoint;
PVector sphereCenter; PVector sphereCenter;
float sphereRadius; float sphereRadius;
Expand All @@ -39,6 +43,7 @@ void setup() {
size(500,500,P2D); size(500,500,P2D);
reset = createShape(RECT, reset_x, reset_y, reset_w, reset_h); reset = createShape(RECT, reset_x, reset_y, reset_w, reset_h);
calculate = createShape(RECT, calc_x, calc_y, calc_w, calc_h); calculate = createShape(RECT, calc_x, calc_y, calc_w, calc_h);
random = createShape(RECT, rand_x, rand_y, rand_w, rand_h);
noLoop(); noLoop();
} }


Expand All @@ -54,6 +59,20 @@ void mousePressed() {
sphereCenter = null; sphereCenter = null;
sphereRadius = 0; sphereRadius = 0;
} }
// If mouse presses random button
else if ((mouseX >= rand_x && mouseX <= (rand_x + rand_w)) &&
(mouseY >= rand_y && mouseY <= (rand_y + rand_h))) {
for (int i = 0; i < 25; i++) {
double rnd = new Random().nextDouble();
int x = (int)(rnd * 500);
rnd = new Random().nextDouble();
int y = (int)(rnd * 500);
// Create new 2D point from random generator
PVector point = new PVector(x, y, 0);
PVector pointLifted = new PVector(point.x, point.y, (float)Math.pow(point.mag(), 2));
rawInput.add(pointLifted);
}
}
// If mouse presses calculate button // If mouse presses calculate button
else if ((mouseX >= calc_x && mouseX <= (calc_x + calc_w)) && else if ((mouseX >= calc_x && mouseX <= (calc_x + calc_w)) &&
(mouseY >= calc_y && mouseY <= (calc_y + calc_h))) { (mouseY >= calc_y && mouseY <= (calc_y + calc_h))) {
Expand Down Expand Up @@ -272,14 +291,8 @@ CenterAndSphere getSeparator(ArrayList<PVector> input) {


// Get radius for our separator // Get radius for our separator
float getRadius(PVector centerPoint, PVector unitVector) { float getRadius(PVector centerPoint, PVector unitVector) {
System.out.println("Centerpoint");
System.out.println(centerPoint);
System.out.println("Centerpoint2D");
PVector centerPoint2D = new PVector(centerPoint.x, centerPoint.y); PVector centerPoint2D = new PVector(centerPoint.x, centerPoint.y);
System.out.println(centerPoint2D);
System.out.println("Numerator.");
float numerator = (float)Math.sqrt(Math.abs(centerPoint.z - Math.pow(centerPoint2D.mag(), 2))); float numerator = (float)Math.sqrt(Math.abs(centerPoint.z - Math.pow(centerPoint2D.mag(), 2)));
System.out.println(numerator);
return numerator / Math.abs(unitVector.z); return numerator / Math.abs(unitVector.z);
} }


Expand Down Expand Up @@ -350,12 +363,14 @@ void draw() {
} }
shape(reset); shape(reset);
shape(calculate); shape(calculate);
shape(random);
fill(50); fill(50);
textSize(20); textSize(20);
text("Geometric Separators", 140, 20); text("Geometric Separators", 140, 20);
textSize(12); textSize(12);
text("Reset.", reset_x + 30, reset_y + 15); text("Reset.", reset_x + 30, reset_y + 15);
text("Calculate.", calc_x + 25, calc_y + 15); text("Calculate.", calc_x + 25, calc_y + 15);
text("Random.", rand_x + 25, rand_y + 15);
// Draw input // Draw input
for (PVector point : rawInput) { for (PVector point : rawInput) {
strokeWeight(8); strokeWeight(8);
Expand Down

0 comments on commit ae84960

Please sign in to comment.