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.
Pages: 1 2 
3d arcs? (Read 4869 times)
3d arcs?
Sep 14th, 2009, 8:02am
 
I was wondering if anyone had any suggestions as to how I would go about creating a 3d arc, along the lines of this old flight404 piece: flight404 dot com/blog/?p=36  I'm just shooting for a single 3d arc, none of the sweet fill colors or anything.  Just trying to wrap my head around making complex 3d shapes.  Thanks!
Re: 3d arcs?
Reply #1 - Sep 14th, 2009, 9:58am
 
how would you create a 2d arc?
Re: 3d arcs?
Reply #2 - Sep 14th, 2009, 10:34am
 
those can be created by a head particle. that is shot from the origin point with a specified speed and direction. then add gravity to the particle and it will create the arc.

the mesh is created based on the path that particle travels.


try something like:

gravity = vector( 0, -.5, 0 );
velocity = vector( random(-1,1), 2, random(-1,1) );
pos = vector( 0, 0, 0 );


pos += velocity;
pos += gravity;


of you can play with trig sin/cos to get the path aswell. divide a circle in N steps and shoot a particle for each of those directions.
Re: 3d arcs?
Reply #3 - Sep 14th, 2009, 10:55am
 
koogy wrote on Sep 14th, 2009, 9:58am:
how would you create a 2d arc


I've managed to create a 2d arc in a few different ways but I can't seem to translate any of them to 3d.  There is built in arc & curve functions as well as using a parabolic equation.

Quote:
the mesh is created based on the path that particle travels.


Actually the gravity and general movement of that piece isn't what I am after.  I am having trouble figuring out how to generate a static 3d arc.  The "mesh" is what I can't seem to create.  Any ideas
Re: 3d arcs?
Reply #4 - Sep 14th, 2009, 3:05pm
 
what's a 3d arc other than two adjacent 2s arcs with spars joining them?

(um, this is easier with a picture)

yes, you'd have to do it yourself rather than just using the arc functions but it's just a centre and a radius and sin and cos.

those in that picture are slightly tougher as the upper and lower arcs use different radii and centres so that the two arcs are thinner towards the ends. the sides of the arc are also tapered - they aren't square in cross section. but i'd start with something easier.

an arc, with a thickness, is just sweeping a line through space. one with thickness and a width width is sweeping a square (or a quad) through space. does that make sense?
Re: 3d arcs?
Reply #5 - Sep 14th, 2009, 3:13pm
 
actually, i thought the particles explanation above sounded a bit dubious but looking at flight404's flickr stream bought up this:

http://www.flickr.com/photos/flight404/302255794/in/set-72057594065151925/

which suggests there's more going on there than just circles and this:

http://www.flickr.com/photos/flight404/302608934/in/set-72057594065151925/

where he basically says it's a particle engine and shows you the particles.
Re: 3d arcs?
Reply #6 - Sep 15th, 2009, 1:52am
 
ok, so you have your path and you can't build the mesh around the path.
check this out: http://www.pixelnerve.com/downloads/processing/RibbonCylinder.pde

look into renderTailCylinder. it builds a cylinder around a path. should be easy to convert it to 4-corner mesh like on those images.

have fun
Re: 3d arcs?
Reply #7 - Sep 15th, 2009, 11:40pm
 
ok, put this together last night using the parabolic method mentioned above.

it cheats a bit by drawing the arc along x axis and then applying a global rotate and also by only drawing the new section, not the whole arc every time.

Code:

// acd 2009
Arc arc;

void setup() {
size(600, 600, P3D);
arc = new Arc();
}

void draw() {
camera(500, 100, 500, 0, 0, 0, 0, -1, 0);
if (arc.draw() == false) {
// new arc
arc = new Arc();
}
// axes for debugging
stroke(255, 0, 0);
line(-500, 0, 0, 500, 0, 0);
stroke(0, 255, 0);
line(0, -500, 0, 0, 500, 0);
stroke(0, 0, 255);
line(0, 0, -500, 0, 0, 500);
}

// Parabolic Arc
// this is really only the nose of the arc, the entire thing builds up onscreen
class Arc {
float direction;
// float angle2; // twist
float elevation;
float gravity = -1; // a guess
float power;
float vx, vy, vz; // velocities
float x, y, z; // position
color col;

public Arc() {
col = color(random(128, 255), random(128, 255), random(128, 255));
x = y = z = 0;
power = random(10, 15);
//println("Power: " + power);
direction = random(TWO_PI); // left right
elevation = radians(60 + random(-15, 15)); // up down
// draw arc along x axis
vx = power;
vy = power * sin(elevation);
vz = 0;
//println("Velocity: " + vx + "," + vy + "," + vz);
}

public boolean draw() {
// add gravity
vy += gravity;
// update positions
float oldx = x;
float oldy = y;
float oldz = z;
float olds = oldy * .25;
x += vx;
y += vy;
z += vz;
// size of square varies with height
float s = y * .25;
if (y < 0) {
// hit floor again - we have finished
return false;
}
lights();
noStroke();
fill(col);
pushMatrix();
rotateY(direction);
// draw 4 quads in a square joining old position to new position
// could (should) be a quadstrip with a bit of thought
beginShape(QUADS);
// left
vertex(oldx, oldy - olds, oldz - olds);
vertex(x, y - s, z - s);
vertex(x, y + s, z - s);
vertex(oldx, oldy + olds, oldz - olds);
// top
vertex(oldx, oldy + olds, oldz - olds);
vertex(x, y + s, z - s);
vertex(x, y + s, z + s);
vertex(oldx, oldy + olds, oldz + olds);
// right
vertex(oldx, oldy + olds, oldz + olds);
vertex(x, y + s, z + s);
vertex(x, y - s, z + s);
vertex(oldx, oldy - olds, oldz + olds);
// bottom
vertex(oldx, oldy - olds, oldz + olds);
vertex(x, y - s, z + s);
vertex(x, y - s, z - s);
vertex(oldx, oldy - olds, oldz - olds);
endShape();
popMatrix();
// we will continue
return true;
}
}
Re: 3d arcs?
Reply #8 - Sep 17th, 2009, 11:33am
 
Awesome!  This has been a big help and I've learned more about parametric equations the past two days than I ever thought I would heh.  Here is an arc based on a few different sources, the toroid example, the example provided by koogy, and some of my own research.  It allows you to change the number of vertices as well as the radius to height ratio.  To use this in a flight404 type simulation you would need to "cheat" as koogy said, and use matrix rotations as it assumes that the arc is drawn on the x-y axis.

Quote:
float theta = 0;
boolean rY = false;
Arc a;
void setup() {
  size(700, 600, P3D);
  PVector gravity = new PVector(0, 2);
  PVector velocity = new PVector(9, -30);
  a = new Arc(22, 10, velocity, gravity);
}

void draw() {
  background(208);
  translate(width/2, height/2);
  lights();
  rotateY(theta);
  theta += 0.01;
  translate(-170, 150);
  a.draw();
  a.points = int(map(sin(theta), -1, 1, 20, 90));
  a.ratio = map(-sin(theta), -1, 1, 0.7, 20);
}

class Arc {
  PVector g, n, u, v;
  PVector [] verts;
  PVector [] coords;
  PVector vel;
  int step, steps, points;
  float ratio;

  Arc(int points, float ratio, PVector vel, PVector g) {
    this.points = points;
    this.g = g;
    this.vel = vel;
    this.ratio = ratio;
    n = new PVector(1, 0);
    u = new PVector(0, 1);
    v = n.cross(u);
    steps = step = 0;
    coords = new PVector[1000];
    coords[0] = new PVector(0, 0);
    generate();

  }

  void generate() {
    while(coords[steps].y <= 0) {
      coords[steps + 1] = PVector.add(coords[steps], vel);
      vel.add(g);
      steps++;
    }
  }

  void draw() {
    verts = new PVector[points + 1];
    draw_strips();
    if (step < steps) {
      step++;
    }
  }

  void draw_strips() {
    noStroke();
    fill(200);
    for(int i = 0; i < step; i++) {
      beginShape(QUAD_STRIP);
      float angle = 45;
      float radius = coords[i].y/ratio;
      for(int j = 0; j <= points; j++) {
        if(i > 0) {
          vertex(verts[j].x, verts[j].y, verts[j].z);
        }
        PVector tu = PVector.mult(u, cos(radians(angle)));
        PVector tv = PVector.mult(v, sin(radians(angle)));
        PVector tutv = PVector.add(tu, tv);
        PVector rtutv = PVector.mult(tutv, radius);  
        PVector p = PVector.add(coords[i], rtutv);
        verts[j] = new PVector(p.x, p.y, p.z);
        vertex(verts[j].x, verts[j].y, verts[j].z);
        angle += 360.0/points;
      }
      endShape();
    }
  }
}

Re: 3d arcs?
Reply #9 - Sep 17th, 2009, 2:29pm
 
I put the arcs into an array, moved the rotation handling into thr arc itself, and added a floor.

Quote:
int count = 50;
float theta = 0;
Arc [] arcs;

void setup() {
  size(700, 600, P3D);
  PVector gravity = new PVector(0, 1);
  arcs = new Arc[count];
  for(int i = 0; i < count; i++) {
    float rot = random(0, 360);
    float vx = random(10, 20);
    float vy = -vx;
    PVector vel = new PVector(vx, vy);
    arcs[i] = new Arc(4, 10, rot, vel, gravity);
  }
}

void draw() {
  camera(1000, -200, 500, width/2, height/2, 0, 0, 1, 0);
  background(208);
  translate(width/2, height/2);

  lights();
  rotateY(theta);
  theta += 0.01;
  draw_floor();
  for(int i = 0; i < count; i++) {
    arcs[i].draw();
  } 
}

void draw_floor() {
  pushMatrix();
  rotateX(radians(90));
  rectMode(CENTER);
  fill(100);
  rect(0, 0, 800, 800);
  popMatrix();
}

class Arc {
  PVector g, n, u, v;
  PVector [] verts;
  PVector [] coords;
  PVector vel;
  int step, steps, points;
  float ratio, rot;

  Arc(int points, float ratio, float rot, PVector vel, PVector g) {
    this.points = points;
    this.g = g;
    this.vel = vel;
    this.ratio = ratio;
    this.rot = rot;
    n = new PVector(1, 0);
    u = new PVector(0, 1);
    v = new PVector(0, 0, 1);
    steps = step = 0;
    coords = new PVector[1000];
    coords[0] = new PVector(0, 0);
    generate();

  }

  void generate() {
    while(coords[steps].y <= 0) {
      coords[steps + 1] = PVector.add(coords[steps], vel);
      vel.add(g);
      steps++;
    }
  }

  void draw() {
    verts = new PVector[points + 1];
    draw_strips();
    if (step < steps) {
      step++;
    }
  }

  void draw_strips() {
    noStroke();
    fill(200);
    pushMatrix();
    rotateY(radians(rot));
    for(int i = 0; i < step; i++) {
      beginShape(QUAD_STRIP);
      float angle = 45;
      float radius = coords[i].y/ratio;
      for(int j = 0; j <= points; j++) {
        if(i > 0) {
          vertex(verts[j].x, verts[j].y, verts[j].z);
        }
        PVector tu = PVector.mult(u, cos(radians(angle)));
        PVector tv = PVector.mult(v, sin(radians(angle)));
        PVector tutv = PVector.add(tu, tv);
        PVector rtutv = PVector.mult(tutv, radius);  
        PVector p = PVector.add(coords[i], rtutv);
        verts[j] = new PVector(p.x, p.y, p.z);
        vertex(verts[j].x, verts[j].y, verts[j].z);
        angle += 360.0/points;
      }
      endShape();
    }
    popMatrix();
  }
}

Re: 3d arcs?
Reply #10 - Sep 18th, 2009, 4:53am
 
here's my implementation: http://vimeo.com/6639683
uses the particle shooting method + ribbons for mesh-generation
Re: 3d arcs?
Reply #11 - Sep 18th, 2009, 5:59am
 
really nice. i am always impressed how you make your sketches look so much better than the average ones using sub-scatter lighting, planar shadows, and all the stuff you mentioned.
Re: 3d arcs?
Reply #12 - Sep 18th, 2009, 6:03am
 
nice.  I need to learn me some opengl lighting, that glossy texture is pretty cool.  What parameter are you using to determine the radius of the cylinder? Oh also, are you going to make the code for that sketch available?
Re: 3d arcs?
Reply #13 - Sep 18th, 2009, 7:48am
 
thanks cedric =)

ascii, i've just been playing with it some more. implemented some more goodies i found interesting. i will post sourcecode at my website later today or tomorrow.
Re: 3d arcs?
Reply #14 - Sep 18th, 2009, 1:02pm
 
it would appear that i've lost this contest.

still, bronze medal, can't complain 8)
Pages: 1 2