Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Almost done. Just need to fix a radius calculation.
  • Loading branch information
Andrew Lawson authored and Andrew Lawson committed Dec 10, 2014
1 parent f908d16 commit 6e0c0b2
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions geometric_separators.pde
Expand Up @@ -19,6 +19,8 @@ PShape reset;
PShape calculate; PShape calculate;
PShape sphere; PShape sphere;
PVector centerPoint; PVector centerPoint;
PVector sphereCenter;
float sphereRadius;
ArrayList<PVector> rawInput = new ArrayList<PVector>(); ArrayList<PVector> rawInput = new ArrayList<PVector>();


// Object used for returning centerpoint and sphere // Object used for returning centerpoint and sphere
Expand Down Expand Up @@ -49,6 +51,8 @@ void mousePressed() {
rawInput.clear(); rawInput.clear();
centerPoint = null; centerPoint = null;
sphere = null; sphere = null;
sphereCenter = null;
sphereRadius = 0;
} }
// 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)) &&
Expand Down Expand Up @@ -271,11 +275,13 @@ float getRadius(PVector centerPoint, PVector unitVector) {
float[] getSphereAttr(PVector centerPoint, PVector unitVector, float radius) { float[] getSphereAttr(PVector centerPoint, PVector unitVector, float radius) {
unitVector.mult(radius); unitVector.mult(radius);
centerPoint.sub(unitVector); centerPoint.sub(unitVector);
float[] attributes = {centerPoint.x, centerPoint.y, 2 * radius, 2 * radius}; sphereCenter = new PVector(centerPoint.x, centerPoint.y, centerPoint.z);
sphereRadius = radius;
float[] attributes = {centerPoint.x, centerPoint.y, radius, radius};
return attributes; return attributes;
} }


// Sample input points into sets of 4 // Sample input points into sets of 5
ArrayList<ArrayList<PVector>> samplePoints(ArrayList<PVector> input) { ArrayList<ArrayList<PVector>> samplePoints(ArrayList<PVector> input) {
ArrayList<PVector> inputCopy = new ArrayList<PVector>(input); ArrayList<PVector> inputCopy = new ArrayList<PVector>(input);
ArrayList<ArrayList<PVector>> setList = new ArrayList<ArrayList<PVector>>(); ArrayList<ArrayList<PVector>> setList = new ArrayList<ArrayList<PVector>>();
Expand Down Expand Up @@ -336,6 +342,7 @@ void draw() {
// Draw separator sphere projected to 2D // Draw separator sphere projected to 2D
if (sphere != null) { if (sphere != null) {
strokeWeight(6); strokeWeight(6);
ellipseMode(RADIUS);
shape(sphere); shape(sphere);
} }
shape(reset); shape(reset);
Expand All @@ -349,7 +356,21 @@ void draw() {
// Draw input // Draw input
for (PVector point : rawInput) { for (PVector point : rawInput) {
strokeWeight(8); strokeWeight(8);
point(point.x, point.y); if (sphereCenter != null) {
strokeWeight(2); stroke(0, 0, 255);
point(sphereCenter.x, sphereCenter.y);
stroke(0);
if (point.x >= sphereCenter.x - sphereRadius && point.x <= sphereCenter.x + sphereRadius) {
if (point.y >= sphereCenter.y - sphereRadius && point.y <= sphereCenter.y + sphereRadius) {
stroke(0, 255, 0);
}
}
point(point.x, point.y);
}
else {
stroke(0);
point(point.x, point.y);
strokeWeight(2);
}
} }
} }

0 comments on commit 6e0c0b2

Please sign in to comment.