3D 旋轉

3D 旋轉有三個功能:rotateX(angle)rotateY(angle)rotateZ(angle) 在各自的軸上旋轉,其中 angle 是弧度。

size(200, 200, P3D); //Starting P3D renderer
fill(255, 0, 0, 150); //transparent red
translate(width/2, height/2);//translate to centre, ie (100, 100)
rectMode(CENTER);//This makes the rectangle centre in (100, 100)
rect(0, 0, 100, 100); //first rectangle
fill(0, 0, 255, 150); //transparent blue
rotateX(PI/4); //rotate in the x-axis by PI/4 radians (45 degrees)
rect(0, 0, 100, 100); //second rectangle (same dimensions as the first one)

StackOverflow 文件

rotateY(radians(45)); //rotate in the y-axis by passing the radians conversion of 45 degrees

StackOverflow 文件

rotateZ(3*PI/4); //rotate in the z-axis by 3*PI/4 radians (270 degrees)

StackOverflow 文件

注意:轉換(例如翻譯和旋轉)會新增到上一個轉換。