clf; clear all

% exemples de graphiques 3D
set(gcf,'PaperPositionMode','auto'); count=1;
doprint=0


    
    

    % champs de vecteurs
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
n=15;
x=linspace(0,2*pi,n);
y=linspace(0,2*pi,n);
[X,Y]=meshgrid(x,y);

m=100;
tvec=linspace(0,pi,m);

for ind=1:m
t=tvec(ind);

u=sin(X-t).*cos(Y);
v=-cos(X-t).*sin(Y);
phi=sin(X-t).*sin(Y);


quiver(X,Y,u,v);
hold on
contour(X,Y,phi,4);
hold off

xlim([0,2*pi]);
ylim([0,2*pi]);
title('champ de vecteur')
drawnow
if doprint; print('-djpeg',['im' num2str(count)]); count=count+1; end
end







    % mesh
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

n=30;
x=linspace(-3,3,n);
y=linspace(-3,3,n);

[X,Y]=meshgrid(x,y);

m=100;
tvec=linspace(-4,4,m);
for ind=1:m
    t=tvec(ind);
    f=exp(-(X+t).^2-Y.^2).*sin(4*(X-t));
    %f=exp(-(X-t).^2-Y.^2);
    %f=sin(4*(X-t));
    
    surf(x,y,f);    
    shading interp
    colormap jet
    %view(2)
    
    xlim([-3,3]); ylim([-3,3]); zlim([-1,1]); caxis([-1,1]);
    xlabel('x'); ylabel('y'); zlabel('z');
    title('mesh')
    drawnow
if doprint;    print('-djpeg',['im' num2str(count)]); count=count+1; end
end




  % trajectoire du lance de baton
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%




vx=1;
vy=-1;
vz=3;
g=10;

n=200;
tvec=linspace(0,1,n);
x=vx*tvec;
y=vy*tvec;
z=vz*tvec-g*tvec.^2/2;

l=0.2;
%l=linspace(0,0.5,n);

phi=pi/2;
theta=linspace(0,5*pi,n);
xp=l.*sin(phi).*cos(theta);
yp=l.*sin(phi).*sin(theta);
zp=l.*cos(phi);

x1=x+xp; x2=x-xp;
y1=y+yp; y2=y-yp;
z1=z+zp; z2=z-zp;


for ind=1:n
sel=1:ind;    
plot3(x(sel),y(sel),z(sel),'k')
hold on
plot3(x(ind),y(ind),z(ind),'ro')

plot3(x1(sel),y1(sel),z1(sel),'r','linewidth',2)
plot3(x2(sel),y2(sel),z2(sel),'b','linewidth',2)

% le baton
plot3([x1(ind) x2(ind)], ...
    [y1(ind) y2(ind)], ...
    [z1(ind) z2(ind)],'k','linewidth',4);

hold off

grid on; box on
xlim([-0.1,1.1]); ylim([-1.1,0.1]); zlim([-2,0.5]);
xlabel('x'); ylabel('y'); zlabel('z');

%camorbit(6*theta(ind),0)
drawnow
title('lance de baton')
if doprint; print('-djpeg',['im' num2str(count)]); count=count+1; end


end










% plot3: spirale logarithmique
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

a=1;
b=1.2;
theta=linspace(0,20,300);

n=200;
tvec=linspace(0,4*pi,n);

for ind=1:n
t=tvec(ind);

r=a*b.^theta;
x=r.*cos(theta+t);
y=r.*sin(theta+t);

%plot(x,y,'k');

z=r;
plot3(x,y,z,'b','linewidth',2);
grid on
box on
hold on
plot3(2*x,2*y,z,'k','linewidth',2);
plot3(x,y,0*z,'r');
xlabel('x');
ylabel('y');
zlabel('z');

xlim(50*[-1,1])
ylim(50*[-1,1])
zlim(40*[0,1])
title('spirale logarithmique')

hold off
drawnow
if doprint; print('-djpeg',['im' num2str(count)]); count=count+1; end
end







