【问题标题】:Processing 3D Arced Cylinder加工 3D 圆弧圆柱体
【发布时间】:2014-10-29 20:14:43
【问题描述】:

我为大家准备了一个棘手的问题。我正在尝试使用 Processing 绘制 3 个维度并且遇到了障碍。我想绘制一个沿给定内半径弧形的圆柱体。我最终希望能够旋转它或在圆弧中的不同点启动它,但是一旦我可以画出圆弧,我就能弄清楚这一点。我的圆弧代码:

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);
}

渲染得相当好,只是弧线沿一侧倾斜。你能帮我画一个完美的圆弧吗?

编辑:我已经更新了我的代码。它工作得更好,但它并没有完成一个完整的循环。相反,它看起来像这样在顶部和底部受到挤压: https://drive.google.com/file/d/0B7A0w7ZdcEuQUmIzQkFlYzBBUkk/view?usp=sharing

【问题讨论】:

  • 如果您愿意,您可以发布您的解决方案作为此问题的答案。见stackoverflow.com/help/self-answer
  • 请从标题和问题中删除“已解决”,并将其作为正确答案发布。

标签: 3d processing cylindrical


【解决方案1】:

OP 找到的答案:

事实证明,我把它复杂化了太多。供将来参考,如果有人想要可以生成 3-D 弧的代码,这里是代码!

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);
}

【讨论】:

    猜你喜欢
    • 2019-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多