Last active
June 23, 2016 23:43
-
-
Save alejandrociatti/1b0345abc281de300e4546bce0a535b0 to your computer and use it in GitHub Desktop.
Rotating "quadforce" (4 tetrahedrons forming a big one with an inverted one inside the 4)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Quadforce{ | |
Tetrahedron tetra; | |
float edgeLength; | |
Quadforce(float radius){ | |
tetra = new Tetrahedron(radius); | |
edgeLength = tetra.a; | |
} | |
void create(){ | |
tetra.create(); | |
Vector v = new Vector(1, 0, 0).setMag(tetra.a); | |
pushMatrix(); | |
v.toTranslation(); | |
tetra.create(); | |
popMatrix(); | |
pushMatrix(); | |
v = new Vector(tetra.a/2, -tetra.a/2, tetra.a/2*sqrt(2)); | |
v.toTranslation(); | |
tetra.create(); | |
v = new Vector(0, 1, 0).setMag(tetra.a); | |
v.toTranslation(); | |
tetra.create(); | |
popMatrix(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import damkjer.ocd.*; | |
float edgeLength = 100; | |
Quadforce quad = new Quadforce(edgeLength); | |
Camera camera1; | |
float cameraRot = 0; | |
float rotVal = 0.025; | |
void setup(){ | |
size(640, 480, P3D); | |
stroke(255,215,0); | |
strokeWeight(4); | |
noFill(); | |
camera1 = new Camera(this); | |
} | |
void draw(){ | |
background(0); | |
translate(-edgeLength, edgeLength/2); | |
rotateX(radians(36)); | |
quad.create(); | |
camera1.circle(rotVal); | |
cameraRot += rotVal; | |
camera1.feed(); | |
// uncomment next two lines to save every frame and quit after a complete rotation (everyone loves gifs) | |
//saveFrame("f###.gif"); | |
//if (cameraRot >= TWO_PI) exit(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Tetrahedron { | |
float a; | |
float h; | |
Vector center, top, bottom; | |
Vector[] vertices = new Vector[4]; | |
Tetrahedron(float radius){ | |
vertices[0] = new Vector(1, 0, -1/sqrt(2)).setMag(radius); | |
vertices[1] = new Vector(-1, 0, -1/sqrt(2)).setMag(radius); | |
vertices[2] = new Vector(0, 1, 1/sqrt(2)).setMag(radius); | |
vertices[3] = new Vector(0, -1, 1/sqrt(2)).setMag(radius); | |
top = vertices[2]; | |
a = PVector.dist(vertices[0], vertices[1]); | |
h = (a*sqrt(6))/3; | |
} | |
void create(){ | |
beginShape(TRIANGLES); | |
vertices[0].toVertex(); | |
vertices[1].toVertex(); | |
vertices[2].toVertex(); | |
vertices[0].toVertex(); | |
vertices[1].toVertex(); | |
vertices[3].toVertex(); | |
vertices[0].toVertex(); | |
vertices[2].toVertex(); | |
vertices[3].toVertex(); | |
endShape(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Vector extends PVector{ | |
Vector(float x, float y, float z){ | |
super(x, y, z); | |
} | |
void toVertex(){ | |
vertex(this.x, this.y, this.z); | |
} | |
void toTranslation(){ | |
translate(this.x, this.y, this.z); | |
} | |
// override | |
Vector add(Vector v){ | |
return (Vector) super.add((PVector) v); | |
} | |
// override | |
Vector setMag(float length){ | |
return (Vector) super.setMag(length); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment