EARTH 801
Computation and Visualization in the Earth Sciences

Lesson 6: 3D Rotations without Animation

PrintPrint

It is also useful to take advantage of the 3D renderer if you want to do the equivalent of "flipping" a shape over the x or y axis, which is easier than trying to recalculate the vertices in your head.

void setup(){
  size(200,200,P3D);
  noStroke();
  noLoop();
}       

void draw(){
  fill(0);
  capitalE(width/2,height/2);
  
  fill(255);
  pushMatrix();
  translate(width/2,height/2,0);
  rotate(PI);
  capitalE(0,0);
  popMatrix();
  
  fill(255,0,0);
  pushMatrix();
  translate(width/2,height/2,0);
  rotateY(PI);
  capitalE(0,0);
  popMatrix();
  
}

void capitalE(int x, int y) {
  beginShape();
  vertex(x,y);
  vertex(x,y+100);
  vertex(x+40,y+100);
  vertex(x+40,y+90);
  vertex(x+10,y+90);
  vertex(x+10,y+55);
  vertex(x+29,y+55);
  vertex(x+29,y+45);
  vertex(x+10,y+45);
  vertex(x+10,y+10);
  vertex(x+33,y+10);
  vertex(x+33,y);
  endShape(CLOSE);
}
screenshot of program output in which a shape is flipped over the x / y axes, see image caption
Screenshot of the output of the program above. The black capital E is rotated by 180 around the z axis and plotted in white. It is flipped over the y axis and plotted in red, so to make a mirror image.
program by E. Richardson in Processing