comparison scripts/plot/view.m @ 11344:cac58372d547

Make view more compatible
author Kai Habel <kai.habel@gmx.de>
date Sun, 12 Dec 2010 16:44:29 +0100
parents be55736a0783
children 488f07b65b1d
comparison
equal deleted inserted replaced
11343:5e5c513ea4c5 11344:cac58372d547
16 ## along with Octave; see the file COPYING. If not, see 16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>. 17 ## <http://www.gnu.org/licenses/>.
18 18
19 ## -*- texinfo -*- 19 ## -*- texinfo -*-
20 ## @deftypefn {Function File} {} view (@var{azimuth}, @var{elevation}) 20 ## @deftypefn {Function File} {} view (@var{azimuth}, @var{elevation})
21 ## @deftypefnx {Function File} {} view ([@var{azimuth}, @var{elevation}])
22 ## @deftypefnx {Function File} {} view ([@var{x}, @var{y}, @var{z}])
21 ## @deftypefnx {Function File} {} view (@var{dims}) 23 ## @deftypefnx {Function File} {} view (@var{dims})
24 ## @deftypefnx {Function File} {} view (@var{ax}, @dots{})
22 ## @deftypefnx {Function File} {[@var{azimuth}, @var{elevation}] =} view () 25 ## @deftypefnx {Function File} {[@var{azimuth}, @var{elevation}] =} view ()
23 ## Set or get the viewpoint for the current axes. 26 ## Set or get the viewpoint for the current axes. The parameters
27 ## @var{azimuth} and @var{elevation} can be given as two arguments or as
28 ## 2-element vector.
29 ## The viewpoint can also be given with cartesian coordinates @var{x},
30 ## @var{y}, and @var{z}.
31 ## The call @code{view (2)} sets the viewpoint to @var{azimuth} = 0
32 ## and @var{elevation} = 90, which is default for 2d graphs.
33 ## The call @code{view (3)} sets the viewpoint to @var{azimuth} = -37.5
34 ## and @var{elevation} = 30, which is default for 3d graphs.
35 ## If @var{ax} is given, the viewpoint is set for this axes, otherwise
36 ## it is set for the current axes.
24 ## @end deftypefn 37 ## @end deftypefn
25 38
26 ## Author: jwe 39 ## Author: jwe
27 40
28 function [azimuth, elevation] = view (x, y, z) 41 function [azimuth, elevation] = view (varargin)
29 42
30 if (nargin < 4) 43 if (nargin < 3)
44
31 if (nargin == 0) 45 if (nargin == 0)
32 tmp = get (gca (), "view"); 46 tmp = get (gca (), "view");
33 az = tmp(1); 47 az = tmp(1);
34 el = tmp(2); 48 el = tmp(2);
35 elseif (nargin == 1) 49 else
36 if (x == 2) 50 ax = varargin{1};
51 if (ishandle (ax) && strcmp (get (ax, "type"), "axes"))
52 args = varargin{2:end};
53 else
54 ax = gca;
55 args = varargin;
56 endif
57 endif
58
59 if (nargin == 1)
60 x = args{1};
61 if (length (x) == 2)
62 az = x(1);
63 el = x(2);
64 elseif (length (x) == 3)
65 [az, el] = cart2sph (x(1), x(2), x(3));
66 az *= 180/pi;
67 az += 90;
68 el *= 180/pi;
69 elseif (x == 2)
37 az = 0; 70 az = 0;
38 el = 90; 71 el = 90;
39 elseif (x == 3) 72 elseif (x == 3)
40 az = -37.5; 73 az = -37.5;
41 el = 30; 74 el = 30;
42 else 75 else
43 error ("view: expecting single argument to be 2 or 3"); 76 print_usage ();
44 endif 77 endif
45 elseif (nargin == 2) 78 elseif (nargin == 2)
46 az = x; 79 az = args{1};
47 el = y; 80 el = args{2};
48 elseif (nargin == 3)
49 error ("view: view (x, y, z) not implemented");
50 endif 81 endif
51 82
52 if (nargin > 0) 83 if (nargin > 0)
53 set (gca (), "view", [az, el]); 84 set (ax, "view", [az, el]);
54 endif 85 endif
55 86
56 if (nargout == 1) 87 if (nargout == 1)
57 error ("view: T = view () not implemented"); 88 error ("view: T = view () not implemented");
58 endif 89 endif