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.
IndexProgramming Questions & HelpOpenGL and 3D Libraries › HowTo draw spiral ribbon
Page Index Toggle Pages: 1
HowTo draw spiral ribbon? (Read 1770 times)
HowTo draw spiral ribbon?
Oct 3rd, 2008, 11:05pm
 
I've explored a little bit Java3D. But I didn't like it very much.
Please, tell me, where can I find some samples with complicated 3D objects? I want to draw thing like that (link to sample image):
http://picasaweb.google.ru/lh/photo/AiQvfWL0M8v2hpzxvUbYhA
But I don't know how.
Please, help me with the link

Re: HowTo draw spiral ribbon?
Reply #1 - Oct 3rd, 2008, 11:36pm
 
Try the shell surface from surfaceLib:
http://eskimoblood.de/surfacelib/shell_class_shell.htm
Re: HowTo draw spiral ribbon?
Reply #2 - Oct 4th, 2008, 10:12am
 
Wow, this library is really cool.
The only problem is that I can set custom parameters only to all spiral, but to the one of the coils of the spiral.

My Aim is to create spiral ribbon. Each coil (circle?) of it will have custom look.

Each coil will have fragments with diffenent colours.

Also the "shell" is a tube, but I need ribbon, plain figure, which has length and width.

I can' create integral parameters for all spiral, I know only start point, end point and end radious of the spiral, I need to custom every coil in this spiral.

Is there any possibibity to do that: Construct spiral ribbon by drawing coil by coil?



Re: HowTo draw spiral ribbon?
Reply #3 - Oct 4th, 2008, 7:44pm
 
hi.
to create a shape like that you could use sines and cosines.

you could create an array of points (you could use toxi's Vec3D or some other class like that).
you can make a loop where the position of each point can be determined like this

Code:

 float numberOfLoops = 5;
 float radius = 50;
 for(int i=0; i<numberOfPoints; i++){
   myPoints[i].x = width/2;
   myPoints[i].y = i*10;
   myPoints[i].z = sin((float)i/(numberOfPoints-1)*TWO_PI*numberOfLoops)*radius;
}


that's just from the top of my head so it can be wrong, but basically it is creating a spiral of points, with the x value centered at the middle of the canvas, the y value is starting at 0 and increasing by 10 pixels on each point.
the z value is the one spiraling by increasing the value in the sin and multiplying by the radius.
this will simply give the coordinates where each coil is.
but i hope it can be a starting point.

rui
Re: HowTo draw spiral ribbon?
Reply #4 - Oct 7th, 2008, 3:56am
 
I think it might be easiest to create a flat strip and then add a radial offset, with some sort of fall-off. This way you could add random jitter and different degrees of coil tension. (Wish I had time to code this properly-would be a great example for hacks).

Here's a real quick example:
Code:

int num = 150;
Vector[] vecs = new Vector[num];
float ribW = 60, ribH;
float ribY;
float margin = 25;
void setup(){
 size(400, 400, P3D);
 calcStrip();
 calcRibbon();
}

void draw(){
 background(200);
 lights();
translate(width/2, height/2);
 rotateX(frameCount*PI/220);
 rotateY(frameCount*PI/240);
 rotateZ(frameCount*PI/270);
 drawRibbon();
}

void calcStrip(){
 ribH = (height-margin*2)/num;
 ribY = -ribH*num/2;
 for (int i=0; i<num; i++){
   vecs[i] = new Vector(0, -ribH*100/2, 0);
   if (i%2==0){
     vecs[i].vx += ribW/2;
     vecs[i].vy = ribY;
   }
   else {
     vecs[i].vx -=ribW/2;
     vecs[i].vy = ribY;
     ribY+=ribH*2;
   }
 }
}


void calcRibbon(){
 float theta1 = 0;
 float theta2 = 0;
 Vector[] tempVecs = new Vector[num];
 for (int i=0; i<num; i++){
   float x = vecs[i].vz*sin(theta1) + vecs[i].vx*cos(theta1);
   float y = vecs[i].vy;
   float z = vecs[i].vz*cos(theta1) - vecs[i].vx*sin(theta1);
   tempVecs[i] = new Vector(x, y, z);
   theta1 = sin(theta2)*1.1;
   theta2 += random(PI/180, PI/30);
 }
 vecs = tempVecs;
}


void drawRibbon(){
 beginShape(QUAD_STRIP);
 for (int i=0; i<num; i++){
   vertex(vecs[i].vx, vecs[i].vy, vecs[i].vz);
 }
 endShape(CLOSE);
}

class Vector{
 float vx, vy, vz;

  // default constructor
  Vector() {
 }
 
 Vector(float vx, float vy, float vz) {
   this.vx = vx;
   this.vy = vy;
   this.vz = vz;
 }
}
Page Index Toggle Pages: 1