2014-10-29 125 views
1

對於大家來說,我有一個棘手的問題。我正在嘗試使用Processing處理3個維度,並且遇到了一個障礙。我想繪製一個沿給定innerRadius的圓弧。我最終希望能夠旋轉它或者在弧線的不同位置啓動它,但是一旦我可以繪製弧線,我就能夠計算出它。我的弧代碼:處理3D弧形圓柱體

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

+1

如果你願意,你可以發佈您的解決方案作爲這個問題的答案。請參閱http://stackoverflow.com/help/self-answer – kevinsa5 2014-11-05 15:58:52

+0

請刪除標題和問題中的「已解決」,並將其作爲正確答案發布。 – usr2564301 2015-11-08 01:05:43

回答

0

答案,發現OP:

事實證明,我被它的複雜太多。爲了將來的參考,如果有人想要一個可以生成三維弧的代碼,這裏是代碼!

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