Mercurial > hg > octave-lyh
annotate scripts/plot/__quiver__.m @ 7768:a2d9f325b65a
Use isschar instead of deprecated isstr
author | Rafael Laboissiere <rafael@debian.org> |
---|---|
date | Sat, 03 May 2008 11:47:54 +0200 |
parents | aa5208636bea |
children | 9a6f4713f765 |
rev | line source |
---|---|
7189 | 1 ## Copyright (C) 2007 David Bateman |
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 | |
7 ## the Free Software Foundation; either version 3 of the License, or (at | |
8 ## your option) any later version. | |
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 | |
16 ## along with Octave; see the file COPYING. If not, see | |
17 ## <http://www.gnu.org/licenses/>. | |
18 | |
19 ## Undocumented internal function | |
20 | |
21 function hlist = __quiver__ (varargin) | |
7191 | 22 |
23 h = varargin{1}; | |
24 is3d = varargin{2}; | |
7189 | 25 |
26 s = 1; | |
27 arrowsize = 0.33; | |
28 | |
29 firstnonnumeric = Inf; | |
30 for i = 3:nargin | |
7191 | 31 if (! isnumeric (varargin{i})) |
7189 | 32 firstnonnumeric = i; |
33 break; | |
34 endif | |
35 endfor | |
36 | |
37 ioff = 3; | |
38 if (nargin < (6 + is3d) || firstnonnumeric < (6 + is3d)) | |
39 u = varargin{ioff++}; | |
40 v = varargin{ioff++}; | |
41 if (is3d) | |
42 w = varargin{ioff++} | |
43 [x, y, z] = meshgrid (1:size(u,1), 1:size(u,2), 1:max(size(w))); | |
44 else | |
45 [x, y] = meshgrid (1:size(u,1), 1:size(u,2)); | |
46 endif | |
7191 | 47 if (nargin >= ioff && isnumeric (varargin{ioff}) |
48 && isscalar (varargin{ioff})) | |
7189 | 49 s = varargin{ioff++}; |
50 endif | |
51 else | |
52 x = varargin{ioff++}; | |
53 y = varargin{ioff++}; | |
54 if (is3d) | |
55 z = varargin{ioff++}; | |
56 endif | |
57 u = varargin{ioff++}; | |
58 v = varargin{ioff++}; | |
59 if (is3d) | |
60 w = varargin{ioff++}; | |
7191 | 61 if (isvector (x) && isvector (y) && isvector (z) |
62 && (! isvector (u) || ! isvector (v) || ! isvector(w))) | |
7189 | 63 [x, y, z] = meshgrid (x, y, z); |
64 endif | |
65 else | |
7191 | 66 if (isvector (x) && isvector (y) && (! isvector (u) || ! isvector (v))) |
7189 | 67 [x, y] = meshgrid (x, y); |
68 endif | |
69 endif | |
7191 | 70 if (nargin >= ioff && isnumeric (varargin{ioff}) |
71 && isscalar (varargin{ioff})) | |
7189 | 72 s = varargin{ioff++}; |
73 endif | |
74 endif | |
75 | |
76 have_filled = false; | |
77 have_line_spec = false; | |
78 while (ioff <= nargin) | |
7191 | 79 arg = varargin{ioff++}; |
7189 | 80 if (ischar (arg) && strncmp (tolower (arg), "filled", 6)) |
81 have_filled = true; | |
7768
a2d9f325b65a
Use isschar instead of deprecated isstr
Rafael Laboissiere <rafael@debian.org>
parents:
7475
diff
changeset
|
82 elseif ((ischar (arg) || iscell (arg)) |
7189 | 83 && ! have_line_spec) |
84 [linespec, valid] = __pltopt__ ("quiver", arg, false); | |
85 if (valid) | |
86 have_line_spec = true; | |
87 if (strncmp (linespec.linestyle, "none", 4)) | |
88 linespec.linestyle = "-"; | |
89 endif | |
90 else | |
91 error ("quiver: invalid linespec"); | |
92 endif | |
93 else | |
94 error ("quiver: unrecognized argument"); | |
95 endif | |
96 endwhile | |
97 | |
98 if (s) | |
99 ## Scale the arrows to fit in the grid | |
100 dx = (max(x(:)) - min(x(:))) ./ size (x, 2); | |
101 dy = (max(y(:)) - min(y(:))) ./ size (y, 1); | |
102 if (is3d) | |
103 ## What should this be divided by? The below seems right | |
104 dz = (max(z(:)) - min(z(:))) ./ max (size (z)); | |
105 len = max (sqrt (u(:).^2 + dy(:).^2) + dz(:).^2); | |
106 else | |
107 len = max (sqrt (u(:).^2 + dy(:).^2)); | |
108 dz = 0; | |
109 endif | |
110 if (len > 0) | |
111 s = s / sqrt (2) * sqrt (dx.^2 + dy.^2 + dz.^2) / len; | |
112 u = s * u; | |
113 v = s * v; | |
114 if (is3d) | |
115 w = s*w; | |
116 endif | |
117 endif | |
118 endif | |
119 | |
120 x = x(:); | |
121 y = y(:); | |
122 xend = x + u(:); | |
123 yend = y + v(:); | |
124 if (is3d) | |
125 z = z(:); | |
126 zend = z + w(:); | |
127 endif | |
128 | |
129 hstate = get (h, "nextplot"); | |
130 unwind_protect | |
131 if (have_line_spec) | |
132 if (is3d) | |
133 h1 = plot3 ([x.'; xend.'; NaN(1, length (x))](:), | |
134 [y.'; yend.'; NaN(1, length (y))](:), | |
135 [z.'; zend.'; NaN(1, length (z))](:), | |
7475 | 136 "linestyle", linespec.linestyle, |
137 "color", linespec.color); | |
7189 | 138 else |
139 h1 = plot ([x.'; xend.'; NaN(1, length (x))](:), | |
140 [y.'; yend.'; NaN(1, length (y))](:), | |
7475 | 141 "linestyle", linespec.linestyle, |
142 "color", linespec.color); | |
7189 | 143 endif |
144 else | |
145 if (is3d) | |
146 h1 = plot3 ([x.'; xend.'; NaN(1, length (x))](:), | |
147 [y.'; yend.'; NaN(1, length (y))](:), | |
148 [z.'; zend.'; NaN(1, length (z))](:)); | |
149 else | |
150 h1 = plot ([x.'; xend.'; NaN(1, length (x))](:), | |
151 [y.'; yend.'; NaN(1, length (y))](:)); | |
152 endif | |
153 endif | |
154 hold on; | |
155 | |
156 xtmp = x + u(:) .* (1 - arrowsize); | |
157 ytmp = y + v(:) .* (1 - arrowsize); | |
158 xarrw1 = xtmp + (y - yend) * arrowsize / 3; | |
159 xarrw2 = xtmp - (y - yend) * arrowsize / 3; | |
160 yarrw1 = ytmp - (x - xend) * arrowsize / 3; | |
161 yarrw2 = ytmp + (x - xend) * arrowsize / 3; | |
162 if (is3d) | |
7475 | 163 zarrw1 = zarrw2 = zend - w(:) * arrowsize; |
7189 | 164 endif |
165 | |
166 if (have_line_spec) | |
167 if (isfield (linespec, "marker") && | |
168 ! strncmp (linespec.marker, "none", 4)) | |
169 if (is3d) | |
170 h2 = plot3 ([xarrw1.'; xend.'; xarrw2.'; NaN(1, length (x))](:), | |
171 [yarrw1.'; yend.'; yarrw2.'; NaN(1, length (y))](:), | |
172 [zarrw1.'; zend.'; zarrw2.'; NaN(1, length (z))](:), | |
173 "linestyle", "none"); | |
174 else | |
175 h2 = plot ([xarrw1.'; xend.'; xarrw2.'; NaN(1, length (x))](:), | |
176 [yarrw1.'; yend.'; yarrw2.'; NaN(1, length (y))](:), | |
177 "linestyle", "none"); | |
178 endif | |
179 else | |
180 if (is3d) | |
181 h2 = plot3 ([xarrw1.'; xend.'; xarrw2.'; NaN(1, length (x))](:), | |
182 [yarrw1.'; yend.'; yarrw2.'; NaN(1, length (y))](:), | |
183 [zarrw1.'; zend.'; zarrw2.'; NaN(1, length (z))](:), | |
7475 | 184 "linestyle", linespec.linestyle, |
185 "color", linespec.color); | |
7189 | 186 else |
187 h2 = plot ([xarrw1.'; xend.'; xarrw2.'; NaN(1, length (x))](:), | |
188 [yarrw1.'; yend.'; yarrw2.'; NaN(1, length (y))](:), | |
7475 | 189 "linestyle", linespec.linestyle, |
190 "color", linespec.color); | |
7189 | 191 endif |
192 endif | |
193 elseif (is3d) | |
194 h2 = plot3 ([xarrw1.'; xend.'; xarrw2.'; NaN(1, length (x))](:), | |
195 [yarrw1.'; yend.'; yarrw2.'; NaN(1, length (y))](:), | |
196 [zarrw1.'; zend.'; zarrw2.'; NaN(1, length (z))](:)); | |
197 else | |
198 h2 = plot ([xarrw1.'; xend.'; xarrw2.'; NaN(1, length (x))](:), | |
199 [yarrw1.'; yend.'; yarrw2.'; NaN(1, length (y))](:)); | |
200 endif | |
201 | |
7191 | 202 if (! have_line_spec |
203 || (isfield (linespec, "marker") | |
204 && strncmp (linespec.marker, "none", 4))) | |
7189 | 205 if (is3d) |
206 h3 = plot3 (x, y, z, "linestyle", "none", "marker", "none"); | |
207 else | |
208 h3 = plot (x, y, "linestyle", "none", "marker", "none"); | |
209 endif | |
210 else | |
211 if (is3d) | |
212 h3 = plot3 (x, y, z, "linestyle", "none", "marker", linespec.marker); | |
213 else | |
214 | |
215 h3 = plot (x, y, "linestyle", "none", "marker", linespec.marker); | |
216 endif | |
217 endif | |
218 if (have_filled) | |
219 ## FIXME gnuplot doesn't respect the markerfacecolor field | |
7191 | 220 set (h3, "markerfacecolor", get (h1, "color")); |
7189 | 221 endif |
222 unwind_protect_cleanup | |
223 set (h, "nextplot", hstate); | |
224 end_unwind_protect | |
225 | |
226 hlist = [h1; h2; h3]; | |
227 | |
228 endfunction |