繁体   English   中英

处理3D弧形圆柱

[英]Processing 3D Arced Cylinder

我对所有人都有一个棘手的问题。 我正在尝试使用Processing绘制3维,并且遇到了障碍。 我想绘制一个沿给定的innerRadius弧形的圆柱体。 我最终希望能够旋转它或在圆弧的不同点处启动它,但是一旦绘制圆弧,我就能弄清楚这一点。 我的弧代码:

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM