1 ## Copyright (C) 2007-2012 John W. Eaton
3 ## This file is part of Octave.
5 ## Octave is free software; you can redistribute it and/or modify it
6 ## under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
10 ## Octave is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ## General Public License for more details.
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>.
20 ## @deftypefn {Function File} {[@var{azimuth}, @var{elevation}] =} view ()
21 ## @deftypefnx {Function File} {} view (@var{azimuth}, @var{elevation})
22 ## @deftypefnx {Function File} {} view ([@var{azimuth} @var{elevation}])
23 ## @deftypefnx {Function File} {} view ([@var{x} @var{y} @var{z}])
24 ## @deftypefnx {Function File} {} view (@var{dims})
25 ## @deftypefnx {Function File} {} view (@var{ax}, @dots{})
26 ## Query or set the viewpoint for the current axes. The parameters
27 ## @var{azimuth} and @var{elevation} can be given as two arguments or as
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 the default for 2-D graphs.
33 ## The call @code{view (3)} sets the viewpoint to @var{azimuth} = -37.5
34 ## and @var{elevation} = 30, which is the default for 3-D graphs.
35 ## If @var{ax} is given, the viewpoint is set for this axes, otherwise
36 ## it is set for the current axes.
41 function [azimuth, elevation] = view (varargin)
45 args = {get(gca (), "view")};
48 if (ishandle (ax) && strcmp (get (ax, "type"), "axes"))
49 args = varargin(2:end);
55 if (length (args) == 1)
60 elseif (length (x) == 3)
61 [az, el] = cart2sph (x(1), x(2), x(3));
74 elseif (length (args) == 2)
80 set (ax, "view", [az, el]);
84 error ("view: T = view () not implemented");
98 %! hf = figure ("visible", "off");
100 %! plot3 ([0,1], [0,1], [0,1]);
102 %! assert ([az, el], [-37.5, 30], eps);
105 %! assert ([az, el], [0, 90], eps);
108 %! assert ([az, el], [135, 0], eps);
109 %! unwind_protect_cleanup
111 %! end_unwind_protect
114 %! hf = figure ("visible", "off");
118 %! assert ([az, el], [0, 90], eps);
121 %! assert ([az, el], [-37.5, 30], eps);
122 %! unwind_protect_cleanup
124 %! end_unwind_protect