Mercurial > octave
comparison scripts/plot/draw/private/__quiver__.m @ 17671:ddfc1600a311
Overhaul quiver/quiver3 functions.
* scripts/plot/draw/private/__quiver__.m: Scale arrowsize parameter internally
from 0.2 to 1/3 to match Matlab visual results. Assume meshgridded input for
2-D inputs. For vectors, assume a square grid with side length = sqrt (numel
(x)). Use __next_line_color__, rather than assuming 'k', if no colorspec is
given. Ignore second input to listeners with '~'. Set multiple graphic
properties at onec to reduce overhead in calling get/set.
* scripts/plot/draw/quiver.m: Update docstring. Replace 'retval' with 'h' to
match function documentation. Use common unwind_protect sequence with call
to newplot. Add titles to %!demos.
* scripts/plot/draw/quiver3.m: Update docstring. Replace 'retval' with 'h' to
match function documentation. Use common unwind_protect sequence with call
to newplot. Add titles to %!demos.
author | Rik <rik@octave.org> |
---|---|
date | Thu, 17 Oct 2013 08:58:50 -0700 |
parents | 7bb76a22cde1 |
children | d63878346099 |
comparison
equal
deleted
inserted
replaced
17670:ea9df126c9a5 | 17671:ddfc1600a311 |
---|---|
25 | 25 |
26 h = varargin{1}; | 26 h = varargin{1}; |
27 is3d = varargin{2}; | 27 is3d = varargin{2}; |
28 | 28 |
29 autoscale = 0.9; | 29 autoscale = 0.9; |
30 arrowsize = 0.2; | 30 ## Matlab uses 0.2, but Octave's algorithm produces equivalent visual |
31 | 31 ## results if arrowsize=0.33. Since this is just a non-dimensional |
32 firstnonnumeric = Inf; | 32 ## scaling factor we scale the arrowsize property value by 0.33/0.20 |
33 for i = 3:nargin | 33 ## in order to get equivalent visual results while keeping equivalent |
34 if (! isnumeric (varargin{i})) | 34 ## property values. |
35 firstnonnumeric = i; | 35 arrowsize = 0.20; |
36 break; | 36 |
37 endif | 37 firstnonnumeric = find (! cellfun ("isnumeric", varargin(3:nargin)), 1); |
38 endfor | 38 if (isempty (firstnonnumeric)) |
39 firstnonnumeric = Inf; | |
40 else | |
41 firstnonnumeric += 2; | |
42 endif | |
39 | 43 |
40 ioff = 3; | 44 ioff = 3; |
41 if (nargin < (6 + is3d) || firstnonnumeric < (6 + is3d)) | 45 if (nargin < (6 + is3d) || firstnonnumeric < (6 + is3d)) |
42 u = varargin{ioff++}; | 46 u = varargin{ioff++}; |
43 v = varargin{ioff++}; | 47 v = varargin{ioff++}; |
86 elseif ((ischar (arg) || iscellstr (arg)) | 90 elseif ((ischar (arg) || iscellstr (arg)) |
87 && ! have_line_spec) | 91 && ! have_line_spec) |
88 [linespec, valid] = __pltopt__ ("quiver", arg, false); | 92 [linespec, valid] = __pltopt__ ("quiver", arg, false); |
89 if (valid) | 93 if (valid) |
90 have_line_spec = true; | 94 have_line_spec = true; |
91 if (strcmp (linespec.linestyle, "none")) | 95 if (isempty (linespec.linestyle) || strcmp (linespec.linestyle, "none")) |
92 linespec.linestyle = "-"; | 96 linespec.linestyle = "-"; |
93 endif | 97 endif |
94 else | 98 else |
95 args {end + 1} = arg; | 99 args{end+1} = arg; |
96 if (ioff <= nargin) | 100 if (ioff <= nargin) |
97 args {end + 1} = varargin{ioff++}; | 101 args{end+1} = varargin{ioff++}; |
98 endif | 102 endif |
99 endif | 103 endif |
100 else | 104 else |
101 args {end + 1} = arg; | 105 args{end+1} = arg; |
102 if (ioff <= nargin) | 106 if (ioff <= nargin) |
103 args {end + 1} = varargin{ioff++}; | 107 args{end+1} = varargin{ioff++}; |
104 endif | 108 endif |
105 endif | 109 endif |
106 endwhile | 110 endwhile |
111 | |
112 ## Normalize 0.20 to 1/3 for plotting | |
113 arrowsize /= 0.20 * 3; | |
107 | 114 |
108 if (autoscale && numel (u) > 1) | 115 if (autoscale && numel (u) > 1) |
109 ## Scale the arrows to fit in the grid | 116 ## Scale the arrows to fit in the grid |
110 if (isvector (x)) | 117 if (isvector (x)) |
111 ny = nx = length (x); | 118 nx = ny = sqrt (length (x)); |
112 else | 119 else |
113 [nx, ny] = size (x); | 120 [ny, nx] = size (x); # assume meshgrid fmt, x in columns, y in rows |
114 endif | 121 endif |
115 dx = (max (x(:)) - min (x(:))) ./ nx; | 122 dx = (max (x(:)) - min (x(:))) / nx; |
116 dy = (max (y(:)) - min (y(:))) ./ ny; | 123 dy = (max (y(:)) - min (y(:))) / ny; |
117 if (is3d) | 124 if (is3d) |
118 dz = (max (z(:)) - min (z(:))) ./ max (size (z)); | 125 dz = (max (z(:)) - min (z(:))) / max (nx, ny); |
119 len = max (sqrt (u(:).^2 + v(:).^2 + w(:).^2)); | 126 len = max (sqrt (u(:).^2 + v(:).^2 + w(:).^2)); |
120 else | 127 else |
121 dz = 0; | 128 dz = 0; |
122 len = max (sqrt (u(:).^2 + v(:).^2)); | 129 len = max (sqrt (u(:).^2 + v(:).^2)); |
123 endif | 130 endif |
124 if (len > 0) | 131 if (len > 0) |
125 sd = sqrt (dx.^2 + dy.^2 + dz.^2) / len; | 132 sd = sqrt (dx.^2 + dy.^2 + dz.^2) / len; |
126 if (sd != 0) | 133 if (sd != 0) |
127 s = sqrt (2) * autoscale * sd; | 134 s = autoscale * sd; |
128 else # special case of identical points with multiple vectors | 135 else # special case of identical points with multiple vectors |
129 s = autoscale; | 136 s = autoscale; |
130 endif | 137 endif |
131 uu = s * u; | 138 uu = s * u; |
132 vv = s * v; | 139 vv = s * v; |
133 if (is3d) | 140 if (is3d) |
134 ww = s*w; | 141 ww = s * w; |
135 endif | 142 endif |
136 endif | 143 endif |
137 else | 144 else |
138 uu = u; | 145 uu = u; |
139 vv = v; | 146 vv = v; |
142 endif | 149 endif |
143 endif | 150 endif |
144 | 151 |
145 hstate = get (h, "nextplot"); | 152 hstate = get (h, "nextplot"); |
146 unwind_protect | 153 unwind_protect |
154 | |
155 if (have_line_spec) | |
156 ls = linespec.linestyle; | |
157 lc = linespec.color; | |
158 else | |
159 ls = "-"; | |
160 lc = __next_line_color__ (); | |
161 endif | |
162 | |
163 ## Must occur after __next_line_color__ in order to work correctly. | |
147 hg = hggroup (); | 164 hg = hggroup (); |
148 if (is3d) | 165 if (is3d) |
149 args = __add_datasource__ ("quiver3", hg, | 166 args = __add_datasource__ ("quiver3", hg, |
150 {"x", "y", "z", "u", "v", "w"}, args{:}); | 167 {"x", "y", "z", "u", "v", "w"}, args{:}); |
151 else | 168 else |
181 if (is3d) | 198 if (is3d) |
182 z = z(:); | 199 z = z(:); |
183 zend = z + ww(:); | 200 zend = z + ww(:); |
184 endif | 201 endif |
185 | 202 |
203 ## Draw arrow shaft as one line object | |
204 if (is3d) | |
205 h1 = plot3 ([x.'; xend.'; NaN(1, length (x))](:), | |
206 [y.'; yend.'; NaN(1, length (y))](:), | |
207 [z.'; zend.'; NaN(1, length (z))](:), | |
208 "linestyle", ls, "color", lc, "parent", hg); | |
209 else | |
210 h1 = plot ([x.'; xend.'; NaN(1, length (x))](:), | |
211 [y.'; yend.'; NaN(1, length (y))](:), | |
212 "linestyle", ls, "color", lc, "parent", hg); | |
213 endif | |
214 | |
215 xtmp = x + uu(:) * (1 - arrowsize); | |
216 ytmp = y + vv(:) * (1 - arrowsize); | |
217 | |
218 if (is3d) | |
219 xydist = sqrt (uu(:).^2 + vv(:).^2 + ww(:).^2) ./ ... | |
220 (sqrt (uu(:).^2 + vv(:).^2) + eps); | |
221 xarrw1 = xtmp + vv(:) .* xydist * arrowsize / 4; | |
222 xarrw2 = xtmp - vv(:) .* xydist * arrowsize / 4; | |
223 yarrw1 = ytmp - uu(:) .* xydist * arrowsize / 4; | |
224 yarrw2 = ytmp + uu(:) .* xydist * arrowsize / 4; | |
225 zarrw1 = zarrw2 = zend - ww(:) * arrowsize; | |
226 else | |
227 xarrw1 = xtmp + vv(:) * arrowsize / 3; | |
228 xarrw2 = xtmp - vv(:) * arrowsize / 3; | |
229 yarrw1 = ytmp - uu(:) * arrowsize / 3; | |
230 yarrw2 = ytmp + uu(:) * arrowsize / 3; | |
231 endif | |
232 | |
233 ## Draw arrowhead as one line object | |
186 if (have_line_spec) | 234 if (have_line_spec) |
187 if (is3d) | 235 if (! isempty (linespec.marker) && ! strcmp (linespec.marker, "none")) |
188 h1 = plot3 ([x.'; xend.'; NaN(1, length (x))](:), | 236 ls = "none"; # No arrowhead drawn when marker present |
189 [y.'; yend.'; NaN(1, length (y))](:), | 237 endif |
190 [z.'; zend.'; NaN(1, length (z))](:), | 238 endif |
191 "linestyle", linespec.linestyle, | 239 |
192 "color", linespec.color, "parent", hg); | 240 if (is3d) |
193 else | |
194 h1 = plot ([x.'; xend.'; NaN(1, length (x))](:), | |
195 [y.'; yend.'; NaN(1, length (y))](:), | |
196 "linestyle", linespec.linestyle, | |
197 "color", linespec.color, "parent", hg); | |
198 endif | |
199 else | |
200 if (is3d) | |
201 h1 = plot3 ([x.'; xend.'; NaN(1, length (x))](:), | |
202 [y.'; yend.'; NaN(1, length (y))](:), | |
203 [z.'; zend.'; NaN(1, length (z))](:), | |
204 "color", "black", "parent", hg); | |
205 else | |
206 h1 = plot ([x.'; xend.'; NaN(1, length (x))](:), | |
207 [y.'; yend.'; NaN(1, length (y))](:), | |
208 "parent", hg); | |
209 endif | |
210 endif | |
211 | |
212 xtmp = x + uu(:) .* (1 - arrowsize); | |
213 ytmp = y + vv(:) .* (1 - arrowsize); | |
214 | |
215 if (is3d) | |
216 xarrw1 = xtmp + sqrt((y - yend).^2 + (z - zend).^2) * arrowsize / 3; | |
217 xarrw2 = xtmp - sqrt((y - yend).^2 + (z - zend).^2) * arrowsize / 3; | |
218 yarrw1 = ytmp - sqrt((x - xend).^2 + (z - zend).^2) * arrowsize / 3; | |
219 yarrw2 = ytmp + sqrt((x - xend).^2 + (z - zend).^2) * arrowsize / 3; | |
220 | |
221 zarrw1 = zarrw2 = zend - ww(:) * arrowsize; | |
222 else | |
223 xarrw1 = xtmp + (y - yend) * arrowsize / 3; | |
224 xarrw2 = xtmp - (y - yend) * arrowsize / 3; | |
225 yarrw1 = ytmp - (x - xend) * arrowsize / 3; | |
226 yarrw2 = ytmp + (x - xend) * arrowsize / 3; | |
227 endif | |
228 | |
229 if (have_line_spec) | |
230 if (isfield (linespec, "marker") | |
231 && ! strcmp (linespec.marker, "none")) | |
232 if (is3d) | |
233 h2 = plot3 ([xarrw1.'; xend.'; xarrw2.'; NaN(1, length (x))](:), | |
234 [yarrw1.'; yend.'; yarrw2.'; NaN(1, length (y))](:), | |
235 [zarrw1.'; zend.'; zarrw2.'; NaN(1, length (z))](:), | |
236 "linestyle", "none", "parent", hg); | |
237 else | |
238 h2 = plot ([xarrw1.'; xend.'; xarrw2.'; NaN(1, length (x))](:), | |
239 [yarrw1.'; yend.'; yarrw2.'; NaN(1, length (y))](:), | |
240 "linestyle", "none", "parent", hg); | |
241 endif | |
242 else | |
243 if (is3d) | |
244 h2 = plot3 ([xarrw1.'; xend.'; xarrw2.'; NaN(1, length (x))](:), | |
245 [yarrw1.'; yend.'; yarrw2.'; NaN(1, length (y))](:), | |
246 [zarrw1.'; zend.'; zarrw2.'; NaN(1, length (z))](:), | |
247 "linestyle", linespec.linestyle, | |
248 "color", linespec.color, "parent", hg); | |
249 else | |
250 h2 = plot ([xarrw1.'; xend.'; xarrw2.'; NaN(1, length (x))](:), | |
251 [yarrw1.'; yend.'; yarrw2.'; NaN(1, length (y))](:), | |
252 "linestyle", linespec.linestyle, | |
253 "color", linespec.color, "parent", hg); | |
254 endif | |
255 endif | |
256 elseif (is3d) | |
257 h2 = plot3 ([xarrw1.'; xend.'; xarrw2.'; NaN(1, length (x))](:), | 241 h2 = plot3 ([xarrw1.'; xend.'; xarrw2.'; NaN(1, length (x))](:), |
258 [yarrw1.'; yend.'; yarrw2.'; NaN(1, length (y))](:), | 242 [yarrw1.'; yend.'; yarrw2.'; NaN(1, length (y))](:), |
259 [zarrw1.'; zend.'; zarrw2.'; NaN(1, length (z))](:), | 243 [zarrw1.'; zend.'; zarrw2.'; NaN(1, length (z))](:), |
260 "color", "black", "parent", hg); | 244 "linestyle", ls, "color", lc, "parent", hg); |
261 else | 245 else |
262 h2 = plot ([xarrw1.'; xend.'; xarrw2.'; NaN(1, length (x))](:), | 246 h2 = plot ([xarrw1.'; xend.'; xarrw2.'; NaN(1, length (x))](:), |
263 [yarrw1.'; yend.'; yarrw2.'; NaN(1, length (y))](:), | 247 [yarrw1.'; yend.'; yarrw2.'; NaN(1, length (y))](:), |
264 "parent", hg); | 248 "linestyle", ls, "color", lc, "parent", hg); |
265 endif | 249 endif |
266 | 250 |
267 if (! have_line_spec | 251 ## Draw arrow base marker as a third line object |
268 || (isfield (linespec, "marker") | 252 if (! have_line_spec || isempty (linespec.marker)) |
269 && strcmp (linespec.marker, "none"))) | 253 mk = "none"; |
270 if (is3d) | 254 else |
271 h3 = plot3 (x, y, z, "linestyle", "none", "marker", "none", | 255 mk = linespec.marker; |
272 "parent", hg); | 256 endif |
273 else | 257 if (is3d) |
274 h3 = plot (x, y, "linestyle", "none", "marker", "none", "parent", hg); | 258 h3 = plot3 (x, y, z, "linestyle", "none", "marker", mk, "parent", hg); |
275 endif | 259 else |
276 else | 260 h3 = plot (x, y, "linestyle", "none", "marker", mk, "parent", hg); |
277 if (is3d) | |
278 h3 = plot3 (x, y, z, "linestyle", "none", "marker", linespec.marker, | |
279 "parent", hg); | |
280 else | |
281 | |
282 h3 = plot (x, y, "linestyle", "none", "marker", linespec.marker, | |
283 "parent", hg); | |
284 endif | |
285 endif | 261 endif |
286 if (have_filled) | 262 if (have_filled) |
287 ## FIXME: gnuplot doesn't respect the markerfacecolor field | 263 ## FIXME: gnuplot doesn't respect the markerfacecolor field |
288 set (h3, "markerfacecolor", get (h1, "color")); | 264 set (h3, "markerfacecolor", get (h1, "color")); |
289 endif | 265 endif |
297 addproperty ("autoscalefactor", hg, "data", 1.0); | 273 addproperty ("autoscalefactor", hg, "data", 1.0); |
298 endif | 274 endif |
299 addlistener (hg, "autoscale", @update_data); | 275 addlistener (hg, "autoscale", @update_data); |
300 addlistener (hg, "autoscalefactor", @update_data); | 276 addlistener (hg, "autoscalefactor", @update_data); |
301 | 277 |
302 addproperty ("maxheadsize", hg, "data", arrowsize); | 278 addproperty ("maxheadsize", hg, "data", arrowsize * .20*3); |
303 addlistener (hg, "maxheadsize", @update_data); | 279 addlistener (hg, "maxheadsize", @update_data); |
304 | 280 |
305 addproperty ("showarrowhead", hg, "radio", "{on}|off", "on"); | 281 addproperty ("showarrowhead", hg, "radio", "{on}|off", "on"); |
306 addlistener (hg, "showarrowhead", @update_props); | 282 addlistener (hg, "showarrowhead", @update_props); |
307 | 283 |
308 addproperty ("color", hg, "linecolor", get (h1, "color")); | 284 addproperty ("color", hg, "linecolor", get (h1, "color")); |
285 addproperty ("linestyle", hg, "linelinestyle", get (h1, "linestyle")); | |
309 addproperty ("linewidth", hg, "linelinewidth", get (h1, "linewidth")); | 286 addproperty ("linewidth", hg, "linelinewidth", get (h1, "linewidth")); |
310 addproperty ("linestyle", hg, "linelinestyle", get (h1, "linestyle")); | |
311 addproperty ("marker", hg, "linemarker", get (h3, "marker")); | 287 addproperty ("marker", hg, "linemarker", get (h3, "marker")); |
312 addproperty ("markerfacecolor", hg, "linemarkerfacecolor", | 288 addproperty ("markerfacecolor", hg, "linemarkerfacecolor", |
313 get (h3, "markerfacecolor")); | 289 get (h3, "markerfacecolor")); |
314 addproperty ("markersize", hg, "linemarkersize", get (h3, "markersize")); | 290 addproperty ("markersize", hg, "linemarkersize", get (h3, "markersize")); |
315 | 291 |
316 addlistener (hg, "color", @update_props); | 292 addlistener (hg, "color", @update_props); |
293 addlistener (hg, "linestyle", @update_props); | |
317 addlistener (hg, "linewidth", @update_props); | 294 addlistener (hg, "linewidth", @update_props); |
318 addlistener (hg, "linestyle", @update_props); | |
319 addlistener (hg, "marker", @update_props); | 295 addlistener (hg, "marker", @update_props); |
320 addlistener (hg, "markerfacecolor", @update_props); | 296 addlistener (hg, "markerfacecolor", @update_props); |
321 addlistener (hg, "markersize", @update_props); | 297 addlistener (hg, "markersize", @update_props); |
322 | 298 |
323 ## Matlab property, although Octave does not implement it. | 299 ## Matlab property, although Octave does not implement it. |
330 set (h, "nextplot", hstate); | 306 set (h, "nextplot", hstate); |
331 end_unwind_protect | 307 end_unwind_protect |
332 | 308 |
333 endfunction | 309 endfunction |
334 | 310 |
335 function update_data (h, d) | 311 function update_data (h, ~) |
312 | |
336 x = get (h, "xdata"); | 313 x = get (h, "xdata"); |
337 y = get (h, "ydata"); | 314 y = get (h, "ydata"); |
338 z = get (h, "zdata"); | 315 z = get (h, "zdata"); |
339 | 316 |
340 u = get (h, "udata"); | 317 u = get (h, "udata"); |
341 v = get (h, "vdata"); | 318 v = get (h, "vdata"); |
342 w = get (h, "wdata"); | 319 w = get (h, "wdata"); |
343 | 320 |
344 s = get (h, "autoscalefactor"); | 321 s = get (h, "autoscalefactor"); |
345 arrowsize = get (h, "maxheadsize"); | 322 arrowsize = get (h, "maxheadsize"); |
323 arrowsize /= 0.20 * 3; | |
346 | 324 |
347 kids = get (h, "children"); | 325 kids = get (h, "children"); |
348 | 326 |
349 if (isempty (z) || isempty (w)) | 327 if (isempty (z) || isempty (w)) |
350 is3d = false; | 328 is3d = false; |
351 else | 329 else |
352 is3d = true; | 330 is3d = true; |
353 endif | 331 endif |
354 | 332 |
355 if (strcmpi (get (h, "autoscale"), "on") && s != 0) | 333 if (strcmp (get (h, "autoscale"), "on") && s != 0) |
356 ## Scale the arrows to fit in the grid | 334 ## Scale the arrows to fit in the grid |
357 if (isvector (x)) | 335 if (isvector (x)) |
358 ny = nx = length (x); | 336 nx = ny = sqrt (length (x)); |
359 else | 337 else |
360 [nx, ny] = size (x); | 338 [ny, nx] = size (x); |
361 endif | 339 endif |
362 dx = (max (x(:)) - min (x(:))) ./ nx; | 340 dx = (max (x(:)) - min (x(:))) / nx; |
363 dy = (max (y(:)) - min (y(:))) ./ ny; | 341 dy = (max (y(:)) - min (y(:))) / ny; |
364 if (is3d) | 342 if (is3d) |
365 dz = (max (z(:)) - min (z(:))) ./ max (size (z)); | 343 dz = (max (z(:)) - min (z(:))) / max (nx, ny); |
366 len = max (sqrt (u(:).^2 + v(:).^2 + w(:).^2)); | 344 len = max (sqrt (u(:).^2 + v(:).^2 + w(:).^2)); |
367 else | 345 else |
368 dz = 0; | 346 dz = 0; |
369 len = max (sqrt (u(:).^2 + v(:).^2)); | 347 len = max (sqrt (u(:).^2 + v(:).^2)); |
370 endif | 348 endif |
371 if (len > 0) | 349 if (len > 0) |
372 sd = sqrt (dx.^2 + dy.^2 + dz.^2) / len; | 350 sd = sqrt (dx.^2 + dy.^2 + dz.^2) / len; |
373 if (sd != 0) | 351 if (sd != 0) |
374 s *= sqrt (2) * sd; | 352 s *= sd; |
375 endif | 353 endif |
376 u = s * u; | 354 u = s * u; |
377 v = s * v; | 355 v = s * v; |
378 if (is3d) | 356 if (is3d) |
379 w = s*w; | 357 w = s * w; |
380 endif | 358 endif |
381 endif | 359 endif |
382 endif | 360 endif |
383 | 361 |
384 x = x(:); | 362 x = x(:); |
388 if (is3d) | 366 if (is3d) |
389 z = z(:); | 367 z = z(:); |
390 zend = z + w(:); | 368 zend = z + w(:); |
391 endif | 369 endif |
392 | 370 |
393 set (kids (3), "xdata", [x.'; xend.'; NaN(1, length (x))](:)); | 371 set (kids(3), "xdata", [x.'; xend.'; NaN(1, length (x))](:)); |
394 set (kids (3), "ydata", [y.'; yend.'; NaN(1, length (y))](:)); | 372 set (kids(3), "ydata", [y.'; yend.'; NaN(1, length (y))](:)); |
395 if (is3d) | 373 if (is3d) |
396 set (kids (3), "zdata", [z.'; zend.'; NaN(1, length (z))](:)); | 374 set (kids(3), "zdata", [z.'; zend.'; NaN(1, length (z))](:)); |
397 endif | 375 endif |
398 | 376 |
399 xtmp = x + u(:) .* (1 - arrowsize); | 377 xtmp = x + u(:) * (1 - arrowsize); |
400 ytmp = y + v(:) .* (1 - arrowsize); | 378 ytmp = y + v(:) * (1 - arrowsize); |
401 xarrw1 = xtmp + (y - yend) * arrowsize / 3; | 379 |
402 xarrw2 = xtmp - (y - yend) * arrowsize / 3; | 380 if (is3d) |
403 yarrw1 = ytmp - (x - xend) * arrowsize / 3; | 381 xydist = sqrt (u(:).^2 + v(:).^2 + w(:).^2) ./ ... |
404 yarrw2 = ytmp + (x - xend) * arrowsize / 3; | 382 (sqrt (u(:).^2 + v(:).^2) + eps); |
405 if (is3d) | 383 xarrw1 = xtmp + v(:) .* xydist * arrowsize / 4; |
384 xarrw2 = xtmp - v(:) .* xydist * arrowsize / 4; | |
385 yarrw1 = ytmp - u(:) .* xydist * arrowsize / 4; | |
386 yarrw2 = ytmp + u(:) .* xydist * arrowsize / 4; | |
406 zarrw1 = zarrw2 = zend - w(:) * arrowsize; | 387 zarrw1 = zarrw2 = zend - w(:) * arrowsize; |
407 endif | 388 else |
408 | 389 xarrw1 = xtmp + v(:) * arrowsize / 3; |
409 set (kids (2), "xdata", [x.'; xend.'; NaN(1, length (x))](:)); | 390 xarrw2 = xtmp - v(:) * arrowsize / 3; |
410 set (kids (2), "ydata", [y.'; yend.'; NaN(1, length (y))](:)); | 391 yarrw1 = ytmp - u(:) * arrowsize / 3; |
411 if (is3d) | 392 yarrw2 = ytmp + u(:) * arrowsize / 3; |
412 set (kids (2), "zdata", [z.'; zend.'; NaN(1, length (z))](:)); | 393 endif |
413 endif | 394 |
414 | 395 set (kids(2), "xdata", [x.'; xend.'; NaN(1, length (x))](:)); |
415 set (kids (2), "xdata", [xarrw1.'; xend.'; xarrw2.'; NaN(1, length (x))](:)); | 396 set (kids(2), "ydata", [y.'; yend.'; NaN(1, length (y))](:)); |
416 set (kids (2), "ydata", [yarrw1.'; yend.'; yarrw2.'; NaN(1, length (y))](:)); | 397 if (is3d) |
417 if (is3d) | 398 set (kids(2), "zdata", [z.'; zend.'; NaN(1, length (z))](:)); |
418 set (kids (2), "zdata", [zarrw1.'; zend.'; zarrw2.'; NaN(1, length (z))](:)); | 399 endif |
419 endif | 400 |
420 | 401 set (kids(2), "xdata", [xarrw1.'; xend.'; xarrw2.'; NaN(1, length (x))](:)); |
421 set (kids (1), "xdata", x); | 402 set (kids(2), "ydata", [yarrw1.'; yend.'; yarrw2.'; NaN(1, length (y))](:)); |
422 set (kids (1), "ydata", y); | 403 if (is3d) |
423 if (is3d) | 404 set (kids(2), "zdata", [zarrw1.'; zend.'; zarrw2.'; NaN(1, length (z))](:)); |
424 set (kids (1), "zdata", z); | 405 endif |
406 | |
407 set (kids(1), "xdata", x); | |
408 set (kids(1), "ydata", y); | |
409 if (is3d) | |
410 set (kids(1), "zdata", z); | |
425 endif | 411 endif |
426 | 412 |
427 endfunction | 413 endfunction |
428 | 414 |
429 function update_props (h, d) | 415 function update_props (h, ~) |
430 kids = get (h, "children"); | 416 kids = get (h, "children"); |
431 | 417 |
432 set (kids(3), "color", get (h, "color"), | 418 set (kids([3 2]), {"color", "linestyle", "linewidth"}, |
433 "linewidth", get (h, "linewidth"), | 419 get (h, {"color", "linestyle", "linewidth"})); |
434 "linestyle", get (h, "linestyle")); | 420 set (kids(2), "visible", get (h, "showarrowhead")); |
435 set (kids(2), "color", get (h, "color"), | 421 set (kids(1), {"color", "marker", "markerfacecolor", "markersize"}, |
436 "linewidth", get (h, "linewidth"), | 422 get (h, {"color", "marker", "markerfacecolor", "markersize"})); |
437 "linestyle", get (h, "linestyle")); | |
438 if (strcmpi (get (h, "showarrowhead"), "on")) | |
439 set (kids (2), "visible", "on"); | |
440 else | |
441 set (kids (2), "visible", "off"); | |
442 endif | |
443 set (kids(1), "color", get (h, "color"), | |
444 "marker", get (h, "marker"), | |
445 "markerfacecolor", get (h, "markerfacecolor"), | |
446 "markersize", get (h, "markersize")); | |
447 endfunction | 423 endfunction |
448 | 424 |