Standing a Cube on its Corner

Hi all, I have a question that sounds incredibly simple, but is proving very challenging, and I think it would be educational for me to learn where I’m going wrong.

All I’m trying to do is make a cube and stand it on its corner.

My initial snippet of code looks like this:

void draw() {
  background(2);
  translate(width/2, height/2);
  pushMatrix();
    rotateX(PI/4);
    rotateY(PI/4);
    box(width/2);
  popMatrix();

I soon learned two things that caused my problem: First, the angle to rotate the cube once it’s on its side is not 45 degrees (that is, pi/4 radians). Second, Processing rotates the whole coordinate system, so when you start doing rotations, all the rest of the rotations are relative to all the previous ones! Both of these factors are making it extremely difficult to get the geometry right to stand the cube on its corner.

How can I get the geometry to work?

1 Like

Maybe instead of rotateY use rotateZ