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 sphere;
PVector centerPoint;
PVector sphereCenter;
float sphereRadius;
ArrayList<PVector> rawInput = new ArrayList<PVector>();

// Object used for returning centerpoint and sphere
Expand Down Expand Up @@ -49,6 +51,8 @@ void mousePressed() {
rawInput.clear();
centerPoint = null;
sphere = null;
sphereCenter = null;
sphereRadius = 0;
}
// If mouse presses calculate button
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) {
unitVector.mult(radius);
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;
}

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