home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l460 / 2.ddi / PLOTXYZ.DI$ / COMET3.M < prev    next >
Encoding:
Text File  |  1993-03-07  |  1.8 KB  |  65 lines

  1. function comet3(x,y,z,p)
  2. %COMET3    3-D Comet plot.
  3. %    COMET3(Z) displays an animated three dimensional plot of the vector Z.
  4. %    COMET3(X,Y,Z) displays an animated comet plot of the curve through the
  5. %    points [X(i),Y(i),Z(i)].
  6. %    COMET3(X,Y,Z,p) uses a comet of length p*length(Z). Default is p = 0.1.
  7. %    COMET3, by itself, is self demonstrating.
  8. %    Example:
  9. %        t = -pi:pi/500:pi;
  10. %        comet3(sin(5*t),cos(3*t),t)
  11. %    See also QUAKEDEMO, COMET.
  12.  
  13. %    Charles R. Denham, MathWorks, 1989.
  14. %    Revised 2-9-92, LS and DTP; 8-18-92, 11-30-92 CBM.
  15. %    Copyright (c) 1984-93 by The MathWorks, Inc.
  16.  
  17. if nargin == 0,
  18.    z = -pi:pi/500:pi;
  19.    y = cos(3*z);
  20.    x = sin(5*z);
  21.    p = 0.1;
  22. else
  23.   if nargin < 3, z = x; x = 1:length(z); y = 1:length(z); end
  24.   if nargin < 4, p = 0.10; end
  25. end
  26.  
  27. clf
  28. axis([min(x) max(x) min(y) max(y) min(z) max(z)])
  29.  
  30. % Cyan circle head, yellow line body, and magenta line tail.
  31. head = line('color','c','linestyle','o','erase','xor','xdata',x(1),'ydata',y(1), ...
  32.        'zdata',z(1));
  33. body = line('color','y','linestyle','-','erase','none','xdata',[],'ydata',[], ...
  34.        'zdata',[]);
  35. tail = line('color','m','linestyle','-','erase','none','xdata',[],'ydata',[], ...
  36.        'zdata',[]);
  37.  
  38. m = length(z);
  39. k = round(p*m);
  40.  
  41. % Grow the body
  42. for i = 2:k+1
  43.    j = i-1:i;
  44.    set(head,'xdata',x(i),'ydata',y(i),'zdata',z(i))
  45.    set(body,'xdata',x(j),'ydata',y(j),'zdata',z(j))
  46.    drawnow
  47. end
  48.  
  49. % Primary loop
  50. m = length(x);
  51. for i = k+2:m
  52.    j = i-1:i;
  53.    set(head,'xdata',x(i),'ydata',y(i),'zdata',z(i))
  54.    set(body,'xdata',x(j),'ydata',y(j),'zdata',z(j))
  55.    set(tail,'xdata',x(j-k),'ydata',y(j-k),'zdata',z(j-k))
  56.    drawnow
  57. end
  58.  
  59. % Clean up the tail
  60. for i = m+1:m+k
  61.    j = i-1:i;
  62.    set(tail,'xdata',x(j-k),'ydata',y(j-k),'zdata',z(j-k))
  63.    drawnow
  64. end
  65.