//sketch_3D_Z_SqPipe角パイプ void setup() { size(400, 400, P3D); } void draw() { background(255, 255, 255); lights(); ortho(-width/2, width/2, -height/2, height/2); // Same as ortho() translate(width / 2, height / 2); rotateY(map(mouseX, 0, width, -PI/1, PI/1)); rotateX(map(mouseY, 0, height, PI/1, -PI/1)); //noStroke(); strokeWeight(0.5); fill(255, 255, 255); scale(1, 1,1); Z_SqPipe(50,44,100);//角パイプ } void Z_SqPipe(float Wo,float Wi,float L)//角パイプ { float Ro=Wo/sqrt(2); float Ri=Wi/sqrt(2); pushMatrix(); rotateZ(45*PI/180); Z_SqCylinder(Ro,L); Z_SqCylinder(Ri,L); translate(0,0,-L/2); Z_SqRing_2D(Ro,Ri); translate(0,0,L); Z_SqRing_2D(Ro,Ri); popMatrix(); } void Z_SqCylinder(float r,float L)//角筒 { int sides=4;//分割数 int i; beginShape(QUAD_STRIP); for (i = 0; i < sides + 1; ++i) { float angle = i*TWO_PI/sides; vertex(r*cos(angle), r*sin(angle), -L/2); vertex(r*cos(angle), r*sin(angle), L/2); } endShape(CLOSE); } void Z_SqRing_2D(float Ro,float Ri) { int sides=4;//分割数 int i; beginShape(); for (i = 0; i < sides + 1; ++i) { float angle = i*TWO_PI/sides; vertex(Ro*cos(angle), Ro*sin(angle),0); } beginContour(); for (i = 0; i < sides + 1; ++i) { float angle = -i*TWO_PI/sides; vertex(Ri*cos(angle), Ri*sin(angle),0); } endContour(); endShape(CLOSE); }