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

  1. function [ret1, ret2] = view(arg1, arg2)
  2. % VIEW    3-D graph viewpoint specification. 
  3. %     VIEW(AZ,EL) and VIEW([AZ,EL]) set the angle of the view from which an
  4. %    observer sees the current 3-D plot.  AZ is the azimuth or horizontal 
  5. %    rotation and EL is the vertical elevation (both in degrees). Azimuth 
  6. %    revolves about the z-axis, with positive values indicating counter-
  7. %    clockwise rotation of the viewpoint. Positive values of elevation 
  8. %    correspond to moving above the object; negative values move below.
  9. %    VIEW([X Y Z]) sets the view angle in cartesian coordinates. The
  10. %    magnitude of vector X,Y,Z is ignored.
  11. %     Here are some examples:
  12. %     AZ = -37.5, EL = 30 is the default 3-D view.
  13. %     AZ = 0, EL = 90 is directly overhead and the default 2-D view.
  14. %     AZ = EL = 0 looks directly up the first column of the matrix.
  15. %     AZ = 180 is behind the matrix.
  16. %
  17. %    VIEW(2) sets the default 2-D view, AZ = 0, EL = 90.
  18. %    VIEW(3) sets the default 3-D view, AZ = -37.5, EL = 30.
  19. %
  20. %     [AZ,EL] = VIEW returns the current azimuth and elevation.
  21. %     VIEW(T) accepts a 4-by-4 transformation matrix, such as 
  22. %     the perspective transformations generated by VIEWMTX.
  23. %
  24. %     T = VIEW returns the current general 4-by-4 transformation matrix.
  25. %
  26. %    See also VIEWMTX, the AXES properties View, Xform.
  27.  
  28. %    Copyright (c) 1984-93 by The MathWorks, Inc.
  29.  
  30. fig = gcf;
  31. ax = gca;
  32. err = 0;
  33. if (nargin == 0)
  34.     if(nargout < 2)
  35.         ret1 = get(ax,'xform');
  36.     else
  37.         v = get(ax,'View');
  38.         ret1  = v(1); ret2 = v(2);
  39.     end
  40. elseif (nargin == 1)
  41.     [r,c] = size(arg1);
  42.     if (r == 1) & (c == 2)
  43.         set(ax,'View',arg1);
  44.     elseif ((r==1) & (c == 1))
  45.         if arg1 == 2
  46.             view(0,90);
  47.         elseif arg1 == 3 
  48.             view(-37.5,30);
  49.         else
  50.             error('Single scalar argument must be 2 or 3');
  51.         end
  52.     elseif ((r == 4) & (c == 4))
  53.         set(ax,'xform',arg1);
  54.     elseif r*c == 3    % it's a direction vector
  55.         unit = arg1/norm(arg1);
  56.         az = atan2(unit(2),unit(1))*180/pi;
  57.         el = atan2(unit(3),sqrt(unit(1)^2+unit(2)^2))*180/pi;
  58.         set(ax,'View',[az el]);
  59.     else
  60.         error('Argument must be scalar, two-vector, or 4-by-4 matrix');
  61.     end
  62. else
  63.     [r,c] = size(arg1);
  64.     [r2,c2] = size(arg2);
  65.     if ((r == 1) & (c == 1) & (r2 == 1) & (c2 == 1))
  66.         set(ax,'View',[arg1 arg2]);
  67.     else
  68.         error('Arguments must be scalars');
  69.     end
  70. end
  71.  
  72.