Cedric
Re: Trace a bezierpoint in 3D
Reply #6 - Nov 29th , 2009, 10:41pm
so this is what you want : Creates a 3D polygon mesh by rotating a 2D path. ? maybe this helps : // MeshFrom2DPath.pde // Marius Watz - http://workshop.evolutionzone.com // // Creates a 3D polygon mesh by rotating a 2D path. import processing.opengl.*; int numrot; float px[],py[],mesh[][][]; void setup() { size(700,700, OPENGL); // To create a mesh, first create two arrays to hold the // X and Y coordinates of the path you will use to create it px=new float[20]; py=new float[20]; float t=0; for(int i=0; i< px.length; i++) { px[i]=bezierPoint(0,130, 130, 0, t); py[i]=bezierPoint(450,350,150,50, t); t+=(1.0/(float)(px.length-1)); } // use createMesh to create the mesh. createMesh takes three parameters: // num == number of rotations // startDeg == start degree of rotation // endDeg == end degree of rotation mesh=createMesh(px,py,20, -60,60); } void draw() { translate(width/2,height/2); pushMatrix(); background(0); lights(); rotateY(radians(frameCount)); rotateX(radians(frameCount)/2); stroke(255); noStroke(); fill(255,120,0); translate(0,0); for(int i=0; i< 6; i++) { rotateZ(radians(60)); pushMatrix(); rotateX(radians(-60)); // to draw the mesh, use drawMesh and pass your mesh variable to it drawMesh(mesh); popMatrix(); } popMatrix(); } float [][][] createMesh(float px[],float py[],int numrot, float startDeg,float endDeg) { float deg,x,z; double cosval,sinval,tmp1,tmp2; float [][][] mesh=new float[numrot][px.length][3]; endDeg-=startDeg; int meshindex=0; for(int i=0; i< numrot; i++) { deg=radians(startDeg+(endDeg/(float)(numrot-1))*(float)i); for(int j=0; j< px.length; j++) { x=px[j]; z=0; cosval=Math.cos(deg); sinval=Math.sin(deg); tmp1=x*cosval - z*sinval; tmp2=x*sinval + z*cosval; mesh[i][j][0]=(float)tmp1; mesh[i][j][1]=py[j]; mesh[i][j][2]=(float)tmp2; } } return mesh; } void drawMesh(float mesh[][][]) { println(mesh.length+" "+mesh[0].length+" "+mesh[0][0].length); for(int i=0; i< mesh.length-1; i++) { beginShape(QUAD_STRIP); for(int j=0; j< mesh[0].length; j++) { vertex(mesh[i][j][0],mesh[i][j][1],mesh[i][j][2]); vertex(mesh[i+1][j][0],mesh[i+1][j][1],mesh[i+1][j][2]); } endShape(); } }