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.
Page Index Toggle Pages: 1
3d diamond (Read 1134 times)
3d diamond
Jun 22nd, 2009, 8:47am
 
Hello,
I would like to draw a 3d diamond, but I have no idea how to start it, can anyone help me?
Re: 3d diamond
Reply #1 - Jun 22nd, 2009, 10:14am
 
you need to work out what the coordinates of the points of your diamond are and which points connect to which other points... 2 square-based pyramids should do it, 6 points in total...

then have one array containing the points and another with the edges

iterate through the edge list drawing a line between the pairs of points...

http://en.wikipedia.org/wiki/Octahedron
Re: 3d diamond
Reply #2 - Jun 22nd, 2009, 11:20am
 
Thanks, but... I cannot see how I can cut the second pyramid, ill show what i have.

for now is just based in another code:

void setup() {
 size(800, 600, P3D);
 smooth();
}

void draw() {
 background(0);
 lights();
 translate(width / 2, height / 2);
 rotateY(map(mouseX, 0, width, 0, PI));
 rotateZ(map(mouseY, 0, height, 0, -PI));
 rotateX(map(mouseX-mouseY, 0, width, 0, PI*2));
 noStroke();
 noFill();
 stroke(255);
 strokeWeight(1);
 translate(0, -40, 0);
 drawCylinder(0, 150, 150, 8); // Draw a pyramid
}

void drawCylinder(float topRadius, float bottomRadius, float tall, int sides) {
 float angle = 0;
 float angleIncrement = TWO_PI / sides;
 beginShape(QUAD_STRIP);
 for (int i = 0; i < sides + 1; ++i) {
   vertex(topRadius*cos(angle), 0, topRadius*sin(angle));
   vertex(bottomRadius*cos(angle), tall, bottomRadius*sin(angle));
   angle += angleIncrement;
 }
 endShape();

 // If it is not a cone, draw the circular top cap
//  if (topRadius != 0) {
   angle = 0;
   beginShape(TRIANGLE_FAN);

   // Center point
   vertex(0, 0, 0);
   for (int i = 0; i < sides + 1; i++) {
     vertex(topRadius * cos(angle), 0, topRadius * sin(angle));
     angle += angleIncrement;
   }
   endShape();
//  }

 // If it is not a cone, draw the circular bottom cap
 if (bottomRadius != 0) {
   angle = 0;
   beginShape(TRIANGLE_FAN);

   // Center point
   vertex(0, tall+150, 0);
   for (int i = 0; i < sides + 1; i++) {
     vertex(bottomRadius * cos(angle), tall, bottomRadius * sin(angle));
     angle += angleIncrement;
   }
   endShape();
 }
}

Re: 3d diamond
Reply #3 - Jun 22nd, 2009, 11:23am
 
get it. thanks
Page Index Toggle Pages: 1