Skip to content
Permalink
Browse files

Almost done. Just need to fix a radius calculation.

  • Loading branch information
Andrew Lawson Andrew Lawson
Andrew Lawson authored and Andrew Lawson committed Dec 10, 2014
1 parent f908d16 commit 6e0c0b2dda1f2178ae226a1827e2405dc919e188
Showing with 25 additions and 4 deletions.
  1. +25 −4 geometric_separators.pde
@@ -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
@@ -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)) &&
@@ -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>>();
@@ -336,6 +342,7 @@ void draw() {
// Draw separator sphere projected to 2D
if (sphere != null) {
strokeWeight(6);
ellipseMode(RADIUS);
shape(sphere);
}
shape(reset);
@@ -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.
You can’t perform that action at this time.