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 arcs (Read 1536 times)
3d arcs
Oct 11th, 2009, 4:45pm
 
Does anybody have a code for creating 3d arcs like this :
http://www.flickr.com/photos/watz/308908247/in/set-72157594387603246/

or can me tell how to do so?
i was able to do it 2d using arcs() but thats not possible to turn 3d i guess..
Thank you!
Re: 3d arcs
Reply #1 - Oct 12th, 2009, 10:14am
 
This example in the tutorial section almost looks like what you want :
http://processing.org/learning/3d/texture3.html

A good start, maybe?
Re: 3d arcs
Reply #2 - Oct 12th, 2009, 11:09am
 
Here is a fork in a more object-oriented programming style :

Code:
class Arc3D {
 
 int tubeRes = 32;
 float[] tubeX;
 float[] tubeY;
 float angleStart, angleWidth;
 float radius, thickness, elevation;
 color fillColor;
 
 public Arc3D(float angleStart, float angleWidth, float radius, float thickness, float elevation, color fillColor) {
   this.angleStart = angleStart;
   this.angleWidth = angleWidth;
   this.radius = radius;
   this.thickness = thickness;
   this.elevation = elevation;
   this.fillColor = fillColor;
   this.tubeX = new float[this.tubeRes];
   this.tubeY = new float[this.tubeRes];
   float angle = this.angleWidth / (this.tubeRes - 1);
   for (int i = 0; i < this.tubeRes; i++) {
     this.tubeX[i] = cos(i * angle);
     this.tubeY[i] = sin(i * angle);
   }
 }
 
 void display() {
   fill(this.fillColor);
   pushMatrix();
   rotateY(this.angleStart);
   // outside
   beginShape(QUAD_STRIP);
   for (int i = 0; i < this.tubeRes; i++) {
     float x = this.tubeX[i] * (this.radius + this.thickness/2);
     float z = this.tubeY[i] * (this.radius + this.thickness/2);
     vertex(x, 0, z);
     vertex(x, this.elevation, z);
   }
   endShape();
   // inside
   beginShape(QUAD_STRIP);
   for (int i = 0; i < this.tubeRes; i++) {
     float x = this.tubeX[i] * (this.radius - this.thickness/2);
     float z = this.tubeY[i] * (this.radius - this.thickness/2);
     vertex(x, 0, z);
     vertex(x, this.elevation, z);
   }
   endShape();
   // start
   beginShape(QUAD_STRIP);
   vertex(this.tubeX[0] * (this.radius + this.thickness/2), 0,         this.tubeY[0] * (this.radius + this.thickness/2));
   vertex(this.tubeX[0] * (this.radius + this.thickness/2), elevation, this.tubeY[0] * (this.radius + this.thickness/2));
   vertex(this.tubeX[0] * (this.radius - this.thickness/2), 0,         this.tubeY[0] * (this.radius - this.thickness/2));
   vertex(this.tubeX[0] * (this.radius - this.thickness/2), elevation, this.tubeY[0] * (this.radius - this.thickness/2));
   endShape();
   // end
   beginShape(QUAD_STRIP);
   vertex(this.tubeX[this.tubeRes - 1] * (this.radius + this.thickness/2), 0,         this.tubeY[this.tubeRes - 1] * (this.radius + this.thickness/2));
   vertex(this.tubeX[this.tubeRes - 1] * (this.radius + this.thickness/2), elevation, this.tubeY[this.tubeRes - 1] * (this.radius + this.thickness/2));
   vertex(this.tubeX[this.tubeRes - 1] * (this.radius - this.thickness/2), 0,         this.tubeY[this.tubeRes - 1] * (this.radius - this.thickness/2));
   vertex(this.tubeX[this.tubeRes - 1] * (this.radius - this.thickness/2), elevation, this.tubeY[this.tubeRes - 1] * (this.radius - this.thickness/2));
   endShape();
   // up
   beginShape(QUAD_STRIP);
   for (int i = 0; i < this.tubeRes; i++) {
     float x = this.tubeX[i] * (this.radius - this.thickness/2);
     float z = this.tubeY[i] * (this.radius - this.thickness/2);
     vertex(x, this.elevation, z);
     x = this.tubeX[i] * (this.radius + this.thickness/2);
     z = this.tubeY[i] * (this.radius + this.thickness/2);
     vertex(x, this.elevation, z);
   }
   endShape();
   // bottom
   beginShape(QUAD_STRIP);
   for (int i = 0; i < this.tubeRes; i++) {
     float x = this.tubeX[i] * (this.radius - this.thickness/2);
     float z = this.tubeY[i] * (this.radius - this.thickness/2);
     vertex(x, 0, z);
     x = this.tubeX[i] * (this.radius + this.thickness/2);
     z = this.tubeY[i] * (this.radius + this.thickness/2);
     vertex(x, 0, z);
   }
   endShape();
   
   popMatrix();
 }
 
}

Arc3D[] arcs;

void setup() {
 size(640, 360, P3D);
 arcs = new Arc3D[3];
 arcs[0] = new Arc3D(TWO_PI*0.00, TWO_PI*0.90, 100, 20, 50, #8c5418);
 arcs[1] = new Arc3D(TWO_PI*0.10, TWO_PI*0.60,  60,  5, 30, #fb8b00);
 arcs[2] = new Arc3D(TWO_PI*0.20, TWO_PI*0.40,  50,  5, 20, #d40404);
 noStroke();
}

void draw() {
 background(51);
 lights();
 translate(width / 2, height / 2);
 rotateX(map(mouseY, 0, height, -PI, PI));
 rotateY(map(mouseX, 0, width, -PI, PI));
 for (int i = 0; i < arcs.length; i++) {
   arcs[i].display();
 }
}
Re: 3d arcs
Reply #3 - Oct 12th, 2009, 2:32pm
 
Ohh that is really cool. Thank you antiplastik!
Re: 3d arcs
Reply #4 - Oct 24th, 2009, 10:09am
 
I uploaded an improved version of the code and a click-and-drag demo on OpenProcessing :
http://www.openprocessing.org/visuals/?visualID=5452
Re: 3d arcs
Reply #5 - Oct 24th, 2009, 4:12pm
 
Thx, that a nice example for the 3d picking that was discussed lately....
Re: 3d arcs
Reply #6 - Oct 25th, 2009, 1:52am
 
For the record (cross references are good!), there is a similar thread (with nearly same subject!) discussed at 3d arcs.
Page Index Toggle Pages: 1