Mercurial > hg > octave-lyh
annotate scripts/plot/view.m @ 17173:bb60b1bb47cf
view.m: Fix args undefined error when calling with two arguments
author | Max Brister <max@2bass.com> |
---|---|
date | Sat, 03 Aug 2013 17:23:44 -0600 |
parents | 5fd07aa232cf |
children |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
1 ## Copyright (C) 2007-2012 John W. Eaton |
6257 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
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 | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
6257 | 9 ## |
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. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
6257 | 18 |
19 ## -*- texinfo -*- | |
17126
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
16356
diff
changeset
|
20 ## @deftypefn {Function File} {} view (@var{azimuth}, @var{elevation}) |
12642
f96b9b9f141b
doc: Periodic grammarcheck and spellcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
21 ## @deftypefnx {Function File} {} view ([@var{azimuth} @var{elevation}]) |
f96b9b9f141b
doc: Periodic grammarcheck and spellcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
22 ## @deftypefnx {Function File} {} view ([@var{x} @var{y} @var{z}]) |
16356 | 23 ## @deftypefnx {Function File} {} view (2) |
24 ## @deftypefnx {Function File} {} view (3) | |
17126
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
16356
diff
changeset
|
25 ## @deftypefnx {Function File} {} view (@var{hax}, @dots{}) |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
16356
diff
changeset
|
26 ## @deftypefnx {Function File} {[@var{azimuth}, @var{elevation}] =} view () |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
16356
diff
changeset
|
27 ## Query or set the viewpoint for the current axes. |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
16356
diff
changeset
|
28 ## |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
16356
diff
changeset
|
29 ## The parameters @var{azimuth} and @var{elevation} can be given as two |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
16356
diff
changeset
|
30 ## arguments or as 2-element vector. The viewpoint can also be specified with |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
16356
diff
changeset
|
31 ## Cartesian coordinates @var{x}, @var{y}, and @var{z}. |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
16356
diff
changeset
|
32 ## |
17165
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17129
diff
changeset
|
33 ## The call @code{view (2)} sets the viewpoint to @w{@var{azimuth} = 0} |
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17129
diff
changeset
|
34 ## and @w{@var{elevation} = 90}, which is the default for 2-D graphs. |
17126
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
16356
diff
changeset
|
35 ## |
17165
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17129
diff
changeset
|
36 ## The call @code{view (3)} sets the viewpoint to @w{@var{azimuth} = -37.5} |
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17129
diff
changeset
|
37 ## and @w{@var{elevation} = 30}, which is the default for 3-D graphs. |
17126
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
16356
diff
changeset
|
38 ## |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
16356
diff
changeset
|
39 ## If the first argument @var{hax} is an axes handle, then operate on |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
16356
diff
changeset
|
40 ## this axis rather than the current axes returned by @code{gca}. |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
16356
diff
changeset
|
41 ## |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
16356
diff
changeset
|
42 ## If no inputs are given, return the current @var{azimuth} and @var{elevation}. |
6257 | 43 ## @end deftypefn |
44 | |
45 ## Author: jwe | |
46 | |
11344 | 47 function [azimuth, elevation] = view (varargin) |
6257 | 48 |
17165
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17129
diff
changeset
|
49 [hax, varargin, nargin] = __plt_get_axis_arg__ ("view", varargin{:}); |
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17129
diff
changeset
|
50 if (isempty (hax)) |
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17129
diff
changeset
|
51 hax = gca (); |
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17129
diff
changeset
|
52 endif |
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17129
diff
changeset
|
53 |
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17129
diff
changeset
|
54 if (nargin > 3) |
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17129
diff
changeset
|
55 print_usage (); |
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17129
diff
changeset
|
56 endif |
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17129
diff
changeset
|
57 |
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17129
diff
changeset
|
58 if (nargin == 0) |
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17129
diff
changeset
|
59 x = get (hax, "view"); |
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17129
diff
changeset
|
60 az = x(1); |
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17129
diff
changeset
|
61 el = x(2); |
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17129
diff
changeset
|
62 elseif (length (varargin) == 1) |
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17129
diff
changeset
|
63 x = varargin{1}; |
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17129
diff
changeset
|
64 if (length (x) == 2) |
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17129
diff
changeset
|
65 az = x(1); |
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17129
diff
changeset
|
66 el = x(2); |
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17129
diff
changeset
|
67 elseif (length (x) == 3) |
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17129
diff
changeset
|
68 [az, el] = cart2sph (x(1), x(2), x(3)); |
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17129
diff
changeset
|
69 az *= 180/pi; |
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17129
diff
changeset
|
70 az += 90; |
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17129
diff
changeset
|
71 el *= 180/pi; |
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17129
diff
changeset
|
72 elseif (x == 2) |
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17129
diff
changeset
|
73 az = 0; |
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17129
diff
changeset
|
74 el = 90; |
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17129
diff
changeset
|
75 elseif (x == 3) |
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17129
diff
changeset
|
76 az = -37.5; |
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17129
diff
changeset
|
77 el = 30; |
11344 | 78 else |
17165
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17129
diff
changeset
|
79 print_usage (); |
11344 | 80 endif |
17165
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17129
diff
changeset
|
81 elseif (length (varargin) == 2) |
17173
bb60b1bb47cf
view.m: Fix args undefined error when calling with two arguments
Max Brister <max@2bass.com>
parents:
17165
diff
changeset
|
82 az = varargin{1}; |
bb60b1bb47cf
view.m: Fix args undefined error when calling with two arguments
Max Brister <max@2bass.com>
parents:
17165
diff
changeset
|
83 el = varargin{2}; |
17165
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17129
diff
changeset
|
84 endif |
6257 | 85 |
17165
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17129
diff
changeset
|
86 if (nargin > 0) |
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17129
diff
changeset
|
87 set (hax, "view", [az, el]); |
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17129
diff
changeset
|
88 else |
6257 | 89 if (nargout == 1) |
17165
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17129
diff
changeset
|
90 azimuth = [az, el]; |
5fd07aa232cf
view.m: Overhaul function. Implement return value for 1 argument.
Rik <rik@octave.org>
parents:
17129
diff
changeset
|
91 elseif (nargout == 2) |
6257 | 92 azimuth = az; |
93 elevation = el; | |
94 endif | |
95 endif | |
96 | |
97 endfunction | |
13096 | 98 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
99 |
13096 | 100 %!test |
13124
2ea1658ad049
Don't use explicit figure number for tests to avoid interference with any figures opened by user.
Kai Habel <kai.habel@gmx.de>
parents:
13096
diff
changeset
|
101 %! hf = figure ("visible", "off"); |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
13124
diff
changeset
|
102 %! unwind_protect |
13096 | 103 %! plot3 ([0,1], [0,1], [0,1]); |
104 %! [az, el] = view; | |
105 %! assert ([az, el], [-37.5, 30], eps); | |
106 %! view (2); | |
107 %! [az, el] = view; | |
108 %! assert ([az, el], [0, 90], eps); | |
109 %! view ([1 1 0]); | |
110 %! [az, el] = view; | |
111 %! assert ([az, el], [135, 0], eps); | |
112 %! unwind_protect_cleanup | |
113 %! close (hf); | |
114 %! end_unwind_protect | |
115 | |
116 %!test | |
13124
2ea1658ad049
Don't use explicit figure number for tests to avoid interference with any figures opened by user.
Kai Habel <kai.habel@gmx.de>
parents:
13096
diff
changeset
|
117 %! hf = figure ("visible", "off"); |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
13124
diff
changeset
|
118 %! unwind_protect |
13096 | 119 %! line; |
120 %! [az, el] = view; | |
121 %! assert ([az, el], [0, 90], eps); | |
122 %! view (3); | |
123 %! [az, el] = view; | |
124 %! assert ([az, el], [-37.5, 30], eps); | |
125 %! unwind_protect_cleanup | |
126 %! close (hf); | |
127 %! end_unwind_protect | |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
128 |