We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexDiscussionExhibition › Platonic solids - 3d Cartesian coordinates
Page Index Toggle Pages: 1
Platonic solids - 3d Cartesian coordinates (Read 2296 times)
Platonic solids - 3d Cartesian coordinates
Apr 23rd, 2010, 4:08pm
 
Hi. Here is a gift of the five platonic solid's cartesian coordinates

Code:
PVector[] tetrahedron = {
new PVector( 1, 1, 1 ),
new PVector(-1, -1, 1 ),
new PVector(-1, 1,-1 ),
new PVector( 1, -1, -1 )
};


Code:
PVector[] octahedron = {
new PVector( 1, 0, 0 ),
new PVector( 0, 1, 0 ),
new PVector( 0, 0, 1 ),
new PVector( -1, 0, 0 ),
new PVector( 0, -1, 0 ),
new PVector( 0, 0, -1 )
};


Code:
PVector[] hexahedron = {
new PVector( 1, 1, 1 ),
new PVector( -1, 1, 1 ),
new PVector( -1, -1, 1 ),
new PVector( 1, -1, 1 ),
new PVector( 1, 1, -1 ),
new PVector( -1, 1, -1 ),
new PVector( -1, -1, -1 ),
new PVector( 1, -1, -1 )
};


Code:
float _ = 0.525731;
float __ = 0.850650;
PVector[] icosahedron = {
new PVector(-_, 0, __),
new PVector(_, 0, __),
new PVector(-_, 0, -__),
new PVector(_, 0, -__),
new PVector(0, __, _),
new PVector(0, __, -_),
new PVector(0, -__, _),
new PVector(0, -__, -_),
new PVector(__, _, 0),
new PVector(-__, _, 0),
new PVector(__, -_, 0),
new PVector(-__, -_, 0)
};


Code:
float _ = 1.618033; //golden mean
float __ = 0.618033;
PVector[] dodecahedron = {
new PVector(0, __, _),
new PVector(0, __, -_),
new PVector(0, -__, _),
new PVector(0, -__, -_),
new PVector(_, 0, __),
new PVector(_, 0, -__),
new PVector(-_, 0, __),
new PVector(-_, 0, -__),
new PVector(__, _, 0),
new PVector(__, -_, 0),
new PVector(-__, _, 0),
new PVector(-__, -_, 0),
new PVector(1, 1, 1),
new PVector(1, 1, -1),
new PVector(1, -1, 1),
new PVector(1, -1, -1),
new PVector(-1, 1, 1),
new PVector(-1, 1, -1),
new PVector(-1, -1, 1),
new PVector(-1, -1, -1)
};
Re: Platonic solids - 3d Cartesian coordinates
Reply #1 - Apr 24th, 2010, 12:01am
 
thank you very much, can i have a little help on how to use these?

i am trying something like this but without success:

float x;
void setup(){
 
 size(700,700,P3D);
 
}

void draw(){
   background(0);
 rotateY(x);
 x = x + 0.1;
stroke(255);

float _ = 1.618033; //golden mean
   float __ = 0.618033;
   PVector[] dodecahedron = {
     new PVector(0, __, _),
     new PVector(0, __, -_),
     new PVector(0, -__, _),
     new PVector(0, -__, -_),
     new PVector(_, 0, __),
     new PVector(_, 0, -__),
     new PVector(-_, 0, __),
     new PVector(-_, 0, -__),
     new PVector(__, _, 0),
     new PVector(__, -_, 0),
     new PVector(-__, _, 0),
     new PVector(-__, -_, 0),
     new PVector(1, 1, 1),
     new PVector(1, 1, -1),
     new PVector(1, -1, 1),
     new PVector(1, -1, -1),
     new PVector(-1, 1, 1),
     new PVector(-1, 1, -1),
     new PVector(-1, -1, 1),
     new PVector(-1, -1, -1)
     };
float p = 1;
for(int i=1;i<dodecahedron.length-1;i++){

line(dodecahedron[i].x*p,dodecahedron[i].y*p,dodecahedron[i].z*p,dodecahedron[i+1].x*p,dodecahedron[i+1].y*p,dodecahedron[i+1].z*p);

}
camera(10,0,0,0,0,0,0, 1, 0);
}

Re: Platonic solids - 3d Cartesian coordinates
Reply #2 - Apr 25th, 2010, 2:16am
 
To draw any of the platonic shapes (either wire frame or solid) it is not enough to just know the vertex coordinates but also which vertices are used for each face of the shape.

Perhaps Bloom can provide that info as well.

Sad
Re: Platonic solids - 3d Cartesian coordinates
Reply #3 - Apr 25th, 2010, 3:06am
 
as it happens i was playing around with (stellated) dodecahedra in february:

Code:

private static final int FACES = 12;
private static final int VERTICES = 5;  // per face
private static final float A = 1.618033989; // (1 * sqr(5) / 2) - wikipedia
private static final float B = 0.618033989; // 1 / (1 * sqr(5) / 2) - wikipedia
private PVector[] vert = null; // list of vertices
private int[][] faces = null;  // list of faces (joining vertices)


Code:

vert = new PVector[20];
vert[ 0] = new PVector(1, 1, 1);
vert[ 1] = new PVector(1, 1, -1);
vert[ 2] = new PVector(1, -1, 1);
vert[ 3] = new PVector(1, -1, -1);
vert[ 4] = new PVector(-1, 1, 1);
vert[ 5] = new PVector(-1, 1, -1);
vert[ 6] = new PVector(-1, -1, 1);
vert[ 7] = new PVector(-1, -1, -1);

vert[ 8] = new PVector(0, B, A);
vert[ 9] = new PVector(0, B, -A);
vert[10] = new PVector(0, -B, A);
vert[11] = new PVector(0, -B, -A);

vert[12] = new PVector(B, A, 0);
vert[13] = new PVector(B, -A, 0);
vert[14] = new PVector(-B, A, 0);
vert[15] = new PVector(-B, -A, 0);

vert[16] = new PVector(A, 0, B);
vert[17] = new PVector(A, 0, -B);
vert[18] = new PVector(-A, 0, B);
vert[19] = new PVector(-A, 0, -B);
   
faces = new int[FACES][VERTICES];
faces[ 0] = new int[] {0, 16, 2, 10, 8};
faces[ 1] = new int[] {0, 8, 4, 14, 12};
faces[ 2] = new int[] {16, 17, 1, 12, 0};
faces[ 3] = new int[] {1, 9, 11, 3, 17};
faces[ 4] = new int[] {1, 12, 14, 5, 9};
faces[ 5] = new int[] {2, 13, 15, 6, 10};
faces[ 6] = new int[] {13, 3, 17, 16, 2};
faces[ 7] = new int[] {3, 11, 7, 15, 13};
faces[ 8] = new int[] {4, 8, 10, 6, 18};
faces[ 9] = new int[] {14, 5, 19, 18, 4};
faces[10] = new int[] {5, 19, 7, 11, 9};
faces[11] = new int[] {15, 7, 19, 18, 6};


if you're using opengl then all the platonic solids (and more) are available via glut anyway.

http://www.cs.duke.edu/courses/fall09/cps124/resources/jogldoc/com/sun/opengl/util/gl2/GLUT.html
Re: Platonic solids - 3d Cartesian coordinates
Reply #4 - Apr 25th, 2010, 9:18am
 

I can now diplay the first and the last solid.

Chrisir     Wink





// if you're using opengl then all the platonic solids (and more)
// are available via glut anyway.
// http://www.cs.duke.edu/courses/fall09/cps124/resources/jogldoc/com/sun/opengl/util/gl2/GLUT.html

// read http://en.wikipedia.org/wiki/Tetrahedron and related

float x;
float y;

color colRed = color(255, 0,0);
color colGreen = color(0, 255, 0);
color colBlue = color(0,0,255);
color colWhite = color(255,255,255);
color colBlack = color(0,0,0);
color colYellow = color(255,255,0);

/*
float _ = 1.618033;
float __ = 0.618033;

PVector[] dodecahedron = {
new PVector(0, __, _),
new PVector(0, __, -_),
new PVector(0, -__, _),
new PVector(0, -__, -_),
new PVector(_, 0, __),
new PVector(_, 0, -__),
new PVector(-_, 0, __),
new PVector(-_, 0, -__),
new PVector(__, _, 0),
new PVector(__, -_, 0),
new PVector(-__, _, 0),
new PVector(-__, -_, 0),
new PVector(1, 1, 1),
new PVector(1, 1, -1),
new PVector(1, -1, 1),
new PVector(1, -1, -1),
new PVector(-1, 1, 1),
new PVector(-1, 1, -1),
new PVector(-1, -1, 1),
new PVector(-1, -1, -1)
};
*/

//  tetrahedron  
PVector[] tetrahedron = {      
 new PVector( 1, 1, 1 ),      
 new PVector(-1, -1, 1 ),      
 new PVector(-1, 1,-1 ),      
 new PVector( 1, -1, -1 ) };

final int FACES = 12;     // number of faces
final int VERTICES = 5;   // VERTICES per face
final float A = 1.618033989; // (1 * sqr(5) / 2) - wikipedia
final float B = 0.618033989; // 1 / (1 * sqr(5) / 2) - wikipedia

PVector[] vert = new PVector[20]; // list of vertices
int[][] faces =  new int[FACES][VERTICES];  // list of faces (joining vertices)

// ==================================================

void setup(){
 size(1000,700,P3D);
 camera(0,0,10,
 0,0,0,
 0, 1, 0);

 vert[ 0] = new PVector(1, 1, 1);
 vert[ 1] = new PVector(1, 1, -1);
 vert[ 2] = new PVector(1, -1, 1);
 vert[ 3] = new PVector(1, -1, -1);
 vert[ 4] = new PVector(-1, 1, 1);
 vert[ 5] = new PVector(-1, 1, -1);
 vert[ 6] = new PVector(-1, -1, 1);
 vert[ 7] = new PVector(-1, -1, -1);

 vert[ 8] = new PVector(0, B, A);
 vert[ 9] = new PVector(0, B, -A);
 vert[10] = new PVector(0, -B, A);
 vert[11] = new PVector(0, -B, -A);

 vert[12] = new PVector(B, A, 0);
 vert[13] = new PVector(B, -A, 0);
 vert[14] = new PVector(-B, A, 0);
 vert[15] = new PVector(-B, -A, 0);

 vert[16] = new PVector(A, 0, B);
 vert[17] = new PVector(A, 0, -B);
 vert[18] = new PVector(-A, 0, B);
 vert[19] = new PVector(-A, 0, -B);

 faces[ 0] = new int[] {  
   0, 16, 2, 10, 8     };
 faces[ 1] = new int[] {  
   0, 8, 4, 14, 12     };
 faces[ 2] = new int[] {  
   16, 17, 1, 12, 0    };
 faces[ 3] = new int[] {  
   1, 9, 11, 3, 17     };
 faces[ 4] = new int[] {  
   1, 12, 14, 5, 9     };
 faces[ 5] = new int[] {  
   2, 13, 15, 6, 10    };
 faces[ 6] = new int[] {  
   13, 3, 17, 16, 2    };
 faces[ 7] = new int[] {  
   3, 11, 7, 15, 13    };
 faces[ 8] = new int[] {  
   4, 8, 10, 6, 18     };
 faces[ 9] = new int[] {  
   14, 5, 19, 18, 4    };
 faces[10] = new int[] {  
   5, 19, 7, 11, 9     };
 faces[11] = new int[] {  
   15, 7, 19, 18, 6    };

}

void draw(){
 background(0);
 stroke(255);
 tetrahedron () ;
 dodecahedron ();
}

void tetrahedron () {

 pushMatrix();

 translate (5.5,0,0);

 x  = map (mouseX,0,width,0,2*PI);  
 rotateY(x);

 y  = map (mouseY,0,height,0,2*PI);
 rotateX(y);

 fill(colRed);
 ShapeManager(0,1,2);

 fill(colGreen);
 ShapeManager(1,2,3);  

 fill(colBlue);
 ShapeManager(2,3,0);  

 fill(colYellow);
 ShapeManager(1,3,0);  

 popMatrix();
}

void ShapeManager (int A, int B, int C) {
 float p = 1.1;
 int i = 0;

 beginShape(); // QUAD
 i=A;
 vertex(tetrahedron[i].x*p,tetrahedron[i].y*p,tetrahedron[i].z*p);  
 i=B;
 vertex(tetrahedron[i].x*p,tetrahedron[i].y*p,tetrahedron[i].z*p);  
 i=C;
 vertex(tetrahedron[i].x*p,tetrahedron[i].y*p,tetrahedron[i].z*p);  
 endShape(CLOSE);  // CLOSE

}

void dodecahedron () {
 pushMatrix();
 x  = map (mouseX,0,width,0,2*PI);  
 rotateY(x);

 y  = map (mouseY,0,height,0,2*PI);
 rotateX(y);

 for (int i = 0; i < FACES; i = i+1) {

   fill(map(i,0,FACES,0,255));

   beginShape();
   for (int i2 = 0; i2 < VERTICES; i2 = i2+1) {
     vertex(vert[faces[i][i2]].x,vert[faces[i][i2]].y,vert[faces[i][i2]].z);
   } // for
   endShape(CLOSE);
 } // for
 popMatrix();

} // func

Re: Platonic solids - 3d Cartesian coordinates
Reply #5 - Apr 25th, 2010, 11:19am
 
Octahedron

Code:
import processing.opengl.*;

PVector[] octahedron = {
 new PVector( 0, 1, 0 ),
 new PVector( 0, -1, 0 ),
 new PVector( 1, 0, 0 ),
new PVector( 0, 0, 1 ),
new PVector( -1, 0, 0 ),
new PVector( 0, 0, -1 )
};

void setup(){
 size(300,300,OPENGL);
}

void draw(){
 background(0);
 translate(width*0.5, height*0.5, 0);
 lights();
 
 pushMatrix();  
 rotateX(mouseX/100.);
 rotateY(mouseY/100.);
   
 scale(30); //octahedron size
 
 beginShape(TRIANGLE_FAN);    
 vertex(octahedron[1].x, octahedron[1].y, octahedron[1].z);

 vertex(octahedron[2].x, octahedron[2].y, octahedron[2].z);
 vertex(octahedron[3].x, octahedron[3].y, octahedron[3].z);
 vertex(octahedron[4].x, octahedron[4].y, octahedron[4].z);
 vertex(octahedron[5].x, octahedron[5].y, octahedron[5].z);
 vertex(octahedron[2].x, octahedron[2].y, octahedron[2].z);//loop vertex
 endShape();

 beginShape(TRIANGLE_FAN);    
 vertex(octahedron[0].x, octahedron[0].y, octahedron[0].z);

 vertex(octahedron[2].x, octahedron[2].y, octahedron[2].z);
 vertex(octahedron[3].x, octahedron[3].y, octahedron[3].z);
 vertex(octahedron[4].x, octahedron[4].y, octahedron[4].z);
 vertex(octahedron[5].x, octahedron[5].y, octahedron[5].z);
 vertex(octahedron[2].x, octahedron[2].y, octahedron[2].z);//loop vertex
 endShape();
 
 popMatrix();
}



Cube (hexahedron)
Code:
import processing.opengl.*;

PVector[] hexahedron = {
 new PVector( -1, -1, 1 ),
 new PVector( 1, -1, 1 ),
 new PVector( 1, 1, 1 ),
 new PVector( -1, 1, 1 ),
 new PVector( 1, -1, -1 ),
 new PVector( -1, -1, -1 ),
 new PVector( -1, 1, -1 ),
 new PVector( 1, 1, -1 )
 };

 void setup(){
   size(300,300,OPENGL);
 }

void draw(){
 background(0);
 translate(width*0.5, height*0.5, 0);
 lights();

 pushMatrix();  
 rotateX(mouseX/100.);
 rotateY(mouseY/100.);

 scale(30); //hexahedron size

 beginShape(QUADS);    
 //front z
 vertex(hexahedron[0].x, hexahedron[0].y, hexahedron[0].z);
 vertex(hexahedron[1].x, hexahedron[1].y, hexahedron[1].z);
 vertex(hexahedron[2].x, hexahedron[2].y, hexahedron[2].z);
 vertex(hexahedron[3].x, hexahedron[3].y, hexahedron[3].z);
 //back z
 vertex(hexahedron[4].x, hexahedron[4].y, hexahedron[4].z);
 vertex(hexahedron[5].x, hexahedron[5].y, hexahedron[5].z);
 vertex(hexahedron[6].x, hexahedron[6].y, hexahedron[6].z);
 vertex(hexahedron[7].x, hexahedron[7].y, hexahedron[7].z);
 //bottom y
 vertex(hexahedron[3].x, hexahedron[3].y, hexahedron[3].z);
 vertex(hexahedron[2].x, hexahedron[2].y, hexahedron[2].z);
 vertex(hexahedron[7].x, hexahedron[7].y, hexahedron[7].z);
 vertex(hexahedron[6].x, hexahedron[6].y, hexahedron[6].z);
 //top y
 vertex(hexahedron[5].x, hexahedron[5].y, hexahedron[5].z);
 vertex(hexahedron[4].x, hexahedron[4].y, hexahedron[4].z);
 vertex(hexahedron[1].x, hexahedron[1].y, hexahedron[1].z);
 vertex(hexahedron[0].x, hexahedron[0].y, hexahedron[0].z);
 //right x
 vertex(hexahedron[1].x, hexahedron[1].y, hexahedron[1].z);
 vertex(hexahedron[4].x, hexahedron[4].y, hexahedron[4].z);
 vertex(hexahedron[7].x, hexahedron[7].y, hexahedron[7].z);
 vertex(hexahedron[2].x, hexahedron[2].y, hexahedron[2].z);
 //left x
 vertex(hexahedron[5].x, hexahedron[5].y, hexahedron[5].z);
 vertex(hexahedron[0].x, hexahedron[0].y, hexahedron[0].z);
 vertex(hexahedron[3].x, hexahedron[3].y, hexahedron[3].z);
 vertex(hexahedron[6].x, hexahedron[6].y, hexahedron[6].z);
 endShape();

 popMatrix();
}


For the icosahedron u got that on processing http://processing.org/learning/3d/icosahedra.html
Page Index Toggle Pages: 1