php/Math   
Recreational Mathematics   
   home  |  library  |  contact
 Math Notes
 Math Programming [25]
 Regression [3]
 Data Mining [17]
 Notation [6]
 Linear Algebra [9]
 Stats & Prob [15]
 Math Cognition [5]
 Space & Physics [6]
 Formulas [5]
 Fun & Games [2]
 Haskell [1]
 Bayes Theory [1]
 Site News [0]
 Math Projects [5]
 Polynomials [1]
 Calculus [9]
 Number Theory [3]
 Optimization [2]
 Financial [1]

 Math Links
 PHP/ir
 Andrew Gelman
 Chance Wiki
 Daniel Lemire
 KD Knuggets
 Social Stats
 MySQL Performance
 Hunch.net
 Matthew Hurst
 JMLR
 JSS
 Hal Daume III
 Math Notes >> Permanent Link

Build your own tetrahedron [Regression
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

Permalink 

No comments entered ...

 Archive 
 

php/Math Project
© 2011. All rights reserved.