%initial conditions
I1 = 1;
I2 = 2;
I3 = 3;

w1 = 1;
w2 = 0;
w3 = 0;

w1n = 0;
w2n = 0;
w3n = 0;

%current time
t = 0;
%timestep
dt = 0.01;
%total time
totalt = 10000;

%time array
T = zeros(totalt,1);

%rotation velocity array to plot
V1 = zeros(totalt,1);
V2 = zeros(totalt,1);
V3 = zeros(totalt,1);

%euler equations
for i = 1:totalt
    w1n = (((I2-I3)/(I1))*w2*w3*dt) + w1;
    w2n = (((I3-I1)/(I2))*w1*w3*dt) + w2;
    w3n = (((I1-I2)/(I1))*w1*w2*dt) + w3;
    
    T(i) = i;
    V1(i) = w1;
    V2(i) = w2;
    V3(i) = w3;
    
    w1 = w1n;
    w2 = w2n;
    w3 = w3n;
    
end

%plot(T,V1,T,V2,T,V3);

Z(1:10,1:20) = 0;


figure
h = surf(Z);
set(h,'FaceColor','green')
axis([-5,22,-5,22,-10,10]);
axis off
f = 0;


for i=1:totalt
    rotate(h,[1 0 0],V1(i),[10.5,5.5,0]);
    rotate(h,[0 1 0],V2(i),[10.5,5.5,0]);
    rotate(h,[0 0 1],V3(i),[10.5,5.5,0]);
    pause(0.01);
    
    
    %make gif
    if i ==1
        f=f+1;
        saveas(gcf, ['rotate3_',sprintf('%03d',f),'.png'])
    end
    
    
    
end


