function rotation3D_movie()
% This function makes a movie of a rotating cube
% 

cubeVerts = 1*([0 0 0; 1 0 0; 1 1 0; 0 1 0; 0 0 1; 1 0 1; 1 1 1; 0 1 1] - 0.5);
faces = [1 2 6 5; 2 3 7 6; 3 4 8 7; 4 1 5 8; 1 2 3 4; 5 6 7 8];
cubeVerts=cubeVerts';


%Rotation about axis 3 (direction cosine matrix)
dcmRot3 = @(theta) [  cos(theta)  -sin(theta)  0;
                      sin(theta)   cos(theta)  0;
                           0           0       1];

%Rotation about axis 2 (direction cosine matrix)
dcmRot2 = @(theta) [ cos(theta)  0  sin(theta);
                         0       1       0;
                    -sin(theta)  0   cos(theta)];

%Rotation about axis 1 (direction cosine matrix)
dcmRot1 = @(theta) [ 1       0          0;
                     0   cos(theta) -sin(theta);
                     0   sin(theta)  cos(theta)];
                
 
% 3D rotation matrix             
Mat  = @(A,B,C) dcmRot1(A)*dcmRot2(B)*dcmRot3(C);


t1=linspace(0,4*pi,300);
t2=linspace(0,4*pi,300);
t3=linspace(0,4*pi,300);

for ii=1:length(t1)
    
% Rotated cube
figure(2)
clf
patch('Vertices',(Mat(sin(t1(ii)),exp(sin(t2(ii))),cos(t3(ii)))*cubeVerts)','Faces',faces, 'FaceVertexCData',hsv(6),'FaceColor', 'flat');
view(120, 30);
axis equal
axis([-2 2 -2 2 -2 2]);
grid on;
M(ii)=getframe;

end


movie(M);
