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

  1. function [xx,yy,zz] = cylinder(r,n)
  2. %CYLINDER Generate cylinder.
  3. %    [X,Y,Z] = CYLINDER(R,N) forms the unit cylinder based on the generator
  4. %    curve in the vector R. Vector R contains the radius at equally
  5. %    spaced points along the unit height of the cylinder. The cylinder
  6. %      has N points around the circumference. SURF(X,Y,Z) displays the
  7. %      cylinder.
  8. %
  9. %      [X,Y,Z] = CYLINDER(R), and [X,Y,Z] = CYLINDER default to N = 20
  10. %      and R = [1 1].
  11. %
  12. %      Omitting output arguments causes the cylinder to be displayed with
  13. %      a SURF command and no outputs to be returned.
  14. %
  15. %      See also SPHERE.
  16.  
  17. %    Clay M. Thompson 4-24-91, CBM 8-21-92.
  18. %    Copyright (c) 1984-93 by The MathWorks, Inc.
  19.  
  20. if nargin < 2, n = 20; end
  21. if nargin < 1, r = [1 1]'; end
  22. r = r(:); % Make sure r is a vector.
  23. m = length(r);
  24. theta = (0:n)/n*2*pi;
  25. sintheta = sin(theta); sintheta(n+1) = 0;
  26.  
  27. x = r * cos(theta);
  28. y = r * sintheta;
  29. z = (0:m-1)'/(m-1) * ones(1,n+1);
  30.  
  31. if nargout == 0
  32.     surf(x,y,z)
  33. else
  34.     xx = x; yy = y; zz = z;
  35. end
  36.