1

I have a tricky one for all of you. I am attempting to draw in 3 dimensions using Processing and have run in to a snag. I want to draw a cylinder that arcs along a given innerRadius. I eventually want to be able to rotate it or start it at a different point in the arc, but I will be able to figure that out once I can draw the arc. My code for the arc:

void drawCurvedVessel(int sides, float r, float l, float x, float y, float z, float     innerRadius, float degrees)
{
  float angle = 360 / sides;
  // draw top shape
  float start = innerRadius*degrees;
  translate(x,y,z);
  for (int n = 0; n < l; n++){
    float theta0 = n/innerRadius;
    float theta1 = (n+1)/innerRadius;
    float dx0 = innerRadius*cos(theta0);
    float dy0 = innerRadius*sin(theta0);
    float dx1 = innerRadius*cos(theta1);
    float dy1 = innerRadius*sin(theta1);
    beginShape(TRIANGLE_STRIP);
    for (int i = 0; i < sides + 3; i++) {
      x = cos( radians( i * angle ) ) * r;
      y = sin( radians( i * angle ) ) * r;
      float vertexZ1 = sin(theta1)*(innerRadius+sqrt((x+dx1)*(x+dx1)+y*y));
      vertex( x+dx1, y, vertexZ1);
      float vertexZ0 = sin(theta0)*(innerRadius+sqrt((x+dx0)*(x+dx0)+y*y));
      vertex( x+dx0, y, vertexZ0);
    }
    endShape(TRIANGLE_STRIP);
  }
  translate(-x,-y,-z);
}

renders fairly well, except that the arc gets skewed along one side. Would you be able to help me draw an arc that is perfectly circular throughout?

EDIT: I have updated my code. It's working better, but it is not performing a full circle. Instead, it looks pinched at top and bottom like this: https://drive.google.com/file/d/0B7A0w7ZdcEuQUmIzQkFlYzBBUkk/view?usp=sharing

Jongware
  • 22,200
  • 8
  • 54
  • 100
  • 1
    If you like, you could post your solution as an answer to this question. See http://stackoverflow.com/help/self-answer – kevinsa5 Nov 05 '14 at 15:58
  • Please remove "Solved" from the title and question, and post it as a proper answer. – Jongware Nov 08 '15 at 01:05

1 Answers1

0

Answer as found by OP:

As it turns out, I was complicating it far too much. For future reference, if anyone would like a code that can generate a 3-D arc, here is the code!

void drawCurvedVessel(int sides, float r, float l, float x, float y, float z, float innerRadius, float degrees)
{
  float angle = 360 / sides;
  int start = int(innerRadius*radians(degrees));
  translate(x,y,z);
  for (int n = start; n < l+start; n++){
    float theta0 = n/innerRadius;
    float theta1 = (n+1)/innerRadius;
    beginShape(TRIANGLE_STRIP);
    for (int i = 0; i < sides + 3; i++) {
      float vy = sin( radians( i * angle ) ) * r;
      float vx0 = (innerRadius-r*cos( radians( i * angle ) ))*cos(theta0);
      float vx1 = (innerRadius-r*cos( radians( i * angle ) ))*cos(theta1);
      float vertexZ1 = sin(theta1)*(innerRadius-cos( radians( i * angle ) ) * r);
      vertex( vx1, vy, vertexZ1);
      float vertexZ0 = sin(theta0)*(innerRadius-cos( radians( i * angle ) ) * r);
      vertex( vx0, vy, vertexZ0);
    }
    endShape(TRIANGLE_STRIP);
  }
  translate(-x,-y,-z);
}
Jongware
  • 22,200
  • 8
  • 54
  • 100