|
Posted on October 22, 2012 @ 04:30:35 PM by Paul Meagher
Credits: http://geoite.com/msu/albums/userpics/10002/Tetrahedron-cutout.jpg
To render a 3D tetrahedron, you can download the latest version of Processing (2.0 beta 4 as of this writing) and load this code into it:
# Jennie Meyer # http://faculty.purchase.edu/jeanine.meyer/processing/tetrahedron/applet/tetrahedron.pde
float side = 100; float rad60=60*PI/180;
float rotx = PI/4; float roty = PI/4;
void setup() { size(800,600,P3D); } void draw() { background(0); translate(width/2.0, height/2.0, -100); rotateX(rotx); rotateY(roty); drawtetrahedron(); } void drawtetrahedron() { beginShape(TRIANGLES); vertex(-side/2,0,0); vertex(0,sin(rad60)*(-side),0); vertex(side/2,0,0); endShape(); beginShape(TRIANGLES); vertex(-side/2,0,0); vertex(0,sin(rad60)*(-side)*.5,sin(rad60)*(side)); vertex(side/2,0,0); endShape(); beginShape(TRIANGLES); vertex(-side/2,0,0); vertex(0,sin(rad60)*(-side)*.5,sin(rad60)*(side)); vertex(0,sin(rad60)*(-side),0); endShape(); beginShape(TRIANGLES); vertex(0,sin(rad60)*(-side),0); vertex(0,sin(rad60)*(-side)*.5,sin(rad60)*(side)); vertex(side/2,0,0); endShape(); } void mouseDragged() { float rate = 0.01; rotx += (pmouseY-mouseY) * rate; roty += (mouseX-pmouseX) * rate; //println("rot x is "+rotx*180/PI+"degrees and roty is "+roty*180/PI); }
There is a javascript-based implementation of the Processing language started by John Resig (JQuery founder) and now carried by other developers. The Java version is ahead of the Javascript version of the language in terms of featureset right now. Would be interesting to see the javascript version move more towards parity with the Java version.
My inspiration for learning more about tetrahedrons was a picture of Alexander Graham Bell reclining in an outdoor shack in the shape of a tetrahedron, a shape he considered to be structural perfection.
Credits: Maria McGowan, http://therightcoastnovascotia.blogspot.ca/2009/08/visit-to-alexander-graham-bell-national.html
|