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 & HelpSyntax Questions › from parametrization to processing
Page Index Toggle Pages: 1
from parametrization to processing (Read 671 times)
from parametrization to processing
Jul 18th, 2007, 11:44am
 
Hi!

Does anybody know of a nice tutorial about how to get from parametric descriptions to programming language.

The mobius strip for instance has a nice parametrization on: http://en.wikipedia.org/wiki/M%C3%B6bius_strip

I guess every translation takes a great deal of thinking, but maybe somewhere somebody has a nice way of looking at it.

/BEnm
Re: from parametrization to processing
Reply #1 - Jul 18th, 2007, 2:09pm
 
Hi,

Ok, here's my approach. For a sketch I choose to draw lines, and not use vertices. I was wondering if I could do this with less code (more to the point).

For x, y, and z coordinates for the mobius strip wikipedia gives formulea. In those formula there are parameters v and u, and I let for-loops run through those parameters.

Here's my code:

int t;
float[] x, y, z, xPrev, yPrev, zPrev;
 
void setup() {
 size(400, 400, P3D);
}

void draw() {
 background(255);
 pushMatrix();
 translate(200, 200);
 rotateX(radians(t));
 
 //rotate mobius strip
 t = (t+1) % 360;
 
 //run through 360 degrees
 for(int u=0; u<361; u++) {
   
   //uu is radian translation of degrees
   float uu = radians(u);
   
   //arrays to store 5 points per perpendicular line on strip  
   x = new float[5];
   y = new float[5];
   z = new float[5];
   int index = 0;
   for (float v=-1; v<=1; v+=0.5) {
     //calculate coordinates, following parametrization (from wikipedia)
     float xCoord = 100*(1+(v/2)*cos(uu/2))*cos(uu);
     float yCoord = 100*(1+(v/2)*cos(uu/2))*sin(uu);
     float zCoord = 100*(v/2)*sin(uu/2);
     x[index] = xCoord;
     y[index] = yCoord;
     z[index] = zCoord;
     index++;
   }
   
   //if there is more than 1 point start drawing
   if(u>0) {
     for(int i=0; i<5; i++) {
       line(x[i], y[i], z[i], xPrev[i], yPrev[i], zPrev[i]);
       if(u%10 == 0 && i>0 ) {
         line(x[i-1], y[i-1], z[i-1], x[i], y[i], z[i]);
       }
     }
   }

   xPrev = x;
   yPrev = y;
   zPrev = z;
 }
 popMatrix();

}

Groetjes, BEnm

Re: from parametrization to processing
Reply #2 - Jul 18th, 2007, 4:30pm
 
The surfaceLib library for processing I think has a way for you to just add the maths for a surface (based on u/v parameters) and it'll handle all the fiddly stuff of subdivision and drawing.

http://www.eskimoblood.de/surfacelib/ is the library page and http://processing.org/discourse/yabb_beta/YaBB.cgi?board=LibraryProblems;action=display;num=1165228439;start=0#0 is a thread on the board with some info.
Page Index Toggle Pages: 1