home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l460 / 3.ddi / DEMOS.DI$ / SUPERQUA.M < prev    next >
Encoding:
Text File  |  1993-03-07  |  1.1 KB  |  39 lines

  1. function [xx,yy,zz] = superquad(n,e,m);
  2. %SUPERQUAD Barr's "superquadrics" ellipsoid.
  3. %    [x,y,z] = SUPERQUAD(n,e,m) is a generalized ellipsoid with
  4. %    n = vertical roundness, e = horizontal roundness and m facets.
  5. %    If values of n and e are not given, random values are supplied.
  6. %    The default value of m is 24.
  7. %
  8. %    SUPERQUAD(...) , with no output arguments, does a SURF plot.
  9. %
  10. %    Ref: A. H. Barr, IEEE Computer Graphics and Applications, 1981,
  11. %         or, Graphics Gems III, David Kirk, editor, 1992.
  12. %
  13. %    See also: SQDEMO.
  14.  
  15. %    Copyright (c) 1984-93 by The MathWorks, Inc.
  16.  
  17. if nargin < 3, m = 24; end
  18. if nargin < 2, e = max(0,1+randn); end
  19. if nargin < 1, n = max(0,1+randn); end
  20.  
  21. u = (-m:2:m)/m*pi;
  22. v = u'/2;
  23.  
  24. cosv = cos(v); sinv = sin(v);
  25. cosu = cos(u); sinu = sin(u);
  26. cosv(1) = 0; cosv(m+1) = 0;
  27. sinu(1) = 0; sinu(m+1) = 0;
  28.  
  29. t = sign(cosv) .* abs(cosv).^n ;
  30. x = t * (sign(cosu) .* abs(cosu).^e );
  31. y = t * (sign(sinu) .* abs(sinu).^e );
  32. z = (sign(sinv) .* abs(sinv).^n ) *  ones(size(u));
  33.  
  34. if nargout == 0
  35.    surf(x,y,z)
  36. else
  37.    xx = x; yy = y; zz = z;
  38. end
  39.