First we define the coordinates of a 3D cube, centered at the origin. Note that you will need to enter a few points more than one to get a complete cube: don’t forget to enter these points to the “cube” list.

cube={{1,-1,1},{1,1,1},{-1,1,1},{-1,-1,1},{1,-1,1},
              {1,-1,-1},{1,1,-1},{-1,1,-1},{-1,-1,-1},{1,-1,-1}}

Let’s draw the cube we have defined so far by connecting the points with a line from point to point, using the Graphics3D function to show the image of the line. We use the option “Boxed -> False” to remove the default bounding box that the Graphics3D command uses.

Graphics3D[Line[cube],Boxed->False]

As you can see, our cube is not yet complete - make sure *your* cube will be complete when you turn in your assignment!

Now we define the three matrixes to rotate around the x, y, and z axis, resspectively. We define all three matrices in one command, surpressing any intermediate output.

Rx[t_]:={{1,0,0},{0,Cos[t],Sin[t]},{0,-Sin[t],Cos[t]}};
Ry[t_] :={{Cos[t],0,-Sin[t]},{0,1,0},{Sin[t],0,Cos[t]}};
Rz[t_]:={{Cos[t],Sin[t],0},{-Sin[t],Cos[t],0},{0,0,1}};

Finally we define the complete 3D rotational matrix by applying the rotation around x first, then around y, and finally around z:

R[x_,y_,z_] := Rz[z] . Ry[y] . Rx[x];
R[x,y,z] // MatrixForm

Now we are defining a function to rotate a single vector v around x, y, and z axes

RotateVector3D[x_,y_,z_,v_]:=R[x,y,z].v

Let’s check this function by rotating the vector {1,1,1} by Pi/4 around each axes:

RotateVector3D[Pi/4,Pi/4,Pi/4,{1,1,1}]

Finally we rotate the entire cube by mapping the above function over our list defining the original cube. Note that the function RotateVector3D that I want to map over my list has four inputs. Thus, I need to specify which input should be used by the elements of the list, by using a # in place of that input and an & after the input list. We could store the rotated cube in a list called cube2, for example.

cube2:=Map[RotateVector3D[Pi/4,Pi/4,Pi/4,#] &, cube]

We can verify that the cube is indeed rotated by using the Graphics3D command and the Line command, just as we showed the original cube above.

Graphics3D[Line[cube2],Boxed->False]

Now I need to generate a whole list of these cubes, each one rotated by a small angle. I can use the Do command for that, in a similar way that we generate the list of 2D stars in our previous program with the Do cimmand. Don’t forget to initialize the list first, just as you do in that previous program and use the AppendTo command o append each new rotated cube to the list of existing ones. You could use a list of rotations of angles from 0 to 2 Pi in steps of 0.5, and use the angle in place of x, y, and z when you rotate the cube, then adjust the step size to get a smooth animation.

list={}
Do[AppendTo[list,insert_rotated_cube_by_t_t_t_here],{t,0,2Pi,0.5}]

Finally, feed that list into the ListAnimate command to see the animation..

ListAnimate[list]