function orbite3d(tn,un)
% Uso: orbite3d(tn,un)
%
% Input: tn: vettore dei tempi, dimensione (N,1)
%        un: array contenente le tre componenti del vettore spostamento
%            dimension(N,3)
% Visualizza le traiettorie del punto
% materiale vincolato ad una sfera e soggetto ad una 
% forza esterna. 
%

xmin=-1.2;xmax=1.2;ymin=-1.2;ymax=1.2;zmin=-1.2;zmax=1.2;

    figNumber=figure( ...
        'Name','Traiettorie del sistema', ...
        'Visible','on');
    %colordef(figNumber,'white');
    axes('Units','normalized', ...
        'Position',[0.1 0.10 0.85 0.85], ...
        'Visible','on');

    set(gca, ...
        'XLim',[xmin xmax],'YLim',[ymin ymax],'ZLim',[zmin zmax], ...
        'XTickMode','auto','YTickMode','auto','ZTickMode','auto', ...
        'XGrid','on','YGrid','on','ZGrid','on', ...
        'Drawmode','fast', ...
        'Visible','on', ...
        'NextPlot','add', ...
        'View',[37.5,18]);
    xlabel('X');
    ylabel('Y');
    zlabel('Z');
%    title(titolo);

[X,Y,Z]=sphere(40);
s1=mesh(X,Y,Z);hold on
set(s1,'FaceAlpha',0.3)

    L = 10;
    y=un(1,:)';
    Y = y*ones(1,L);

    body = line( ...
        'color','r', ...
        'LineStyle','-', ...
        'LineWidth',2,...
        'erase','none', ...
        'xdata',[],'ydata',[],'zdata',[]);
    tail=line( ...
        'color','k', ...
        'LineStyle','-', ...
        'LineWidth',2,...
        'erase','none', ...
        'xdata',[],'ydata',[],'zdata',[]);
l=length(tn);

for j=1:l
y=un(j,:)';
% Update the plot
Y = [y Y(:,1:L-1)];
 set(body,'xdata',Y(1,1:2),'ydata',Y(2,1:2),'zdata',Y(3,1:2))
 set(tail,'xdata',Y(1,L-1:L),'ydata',Y(2,L-1:L),'zdata',Y(3,L-1:L))
 drawnow;
end
p3=plot3(un(:,1),un(:,2),un(:,3));
set(p3,'Linewidth',2,'color','k')
hold off
