Mercurial > hg > octave-nkf
changeset 12554:4040a95a586d
Revamp quiver autoscaling algorithm (bug #32836).
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Thu, 31 Mar 2011 07:33:11 -0700 |
parents | 7c915d013b9c |
children | 422a7a7e9b6e |
files | scripts/ChangeLog scripts/plot/private/__quiver__.m |
diffstat | 2 files changed, 32 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,7 @@ +2011-03-31 Rik <octave@nomad.inbox5.com> + + * plot/private/__quiver__.m: Revamp autoscaling algorithm (bug #32836). + 2011-03-29 John W. Eaton <jwe@octave.org> * special-matrix/wilkinson.m: Update test for 'wilkinson(1)' to reflect
--- a/scripts/plot/private/__quiver__.m +++ b/scripts/plot/private/__quiver__.m @@ -107,18 +107,27 @@ if (autoscale && numel (u) > 1) ## Scale the arrows to fit in the grid - dx = (max(x(:)) - min(x(:))) ./ size (x, 2); - dy = (max(y(:)) - min(y(:))) ./ size (y, 1); + if (isvector (x)) + ny = nx = length (x); + else + [nx, ny] = size (x); + endif + dx = (max(x(:)) - min(x(:))) ./ nx; + dy = (max(y(:)) - min(y(:))) ./ ny; if (is3d) - ## What should this be divided by? The below seems right dz = (max(z(:)) - min(z(:))) ./ max (size (z)); - len = max (sqrt (u(:).^2 + dy(:).^2) + dz(:).^2); + len = max (sqrt (u(:).^2 + v(:).^2 + w(:).^2)); else - len = max (sqrt (u(:).^2 + dy(:).^2)); dz = 0; + len = max (sqrt (u(:).^2 + v(:).^2)); endif if (len > 0) - s = 2 * autoscale / sqrt (2) * sqrt (dx.^2 + dy.^2 + dz.^2) / len; + sd = sqrt (dx.^2 + dy.^2 + dz.^2) / len; + if (sd != 0) + s = sqrt(2) * autoscale * sd; + else # special case of identical points with multiple vectors + s = autoscale; + endif uu = s * u; vv = s * v; if (is3d) @@ -335,18 +344,25 @@ if (strcmpi (get (h, "autoscale"), "on") && s != 0) ## Scale the arrows to fit in the grid - dx = (max(x(:)) - min(x(:))) ./ size (x, 2); - dy = (max(y(:)) - min(y(:))) ./ size (y, 1); + if (isvector (x)) + ny = nx = length (x); + else + [nx, ny] = size (x); + endif + dx = (max(x(:)) - min(x(:))) ./ nx; + dy = (max(y(:)) - min(y(:))) ./ ny; if (is3d) - ## What should this be divided by? The below seems right dz = (max(z(:)) - min(z(:))) ./ max (size (z)); - len = max (sqrt (u(:).^2 + dy(:).^2) + dz(:).^2); + len = max (sqrt (u(:).^2 + v(:).^2 + w(:).^2)); else - len = max (sqrt (u(:).^2 + dy(:).^2)); dz = 0; + len = max (sqrt (u(:).^2 + v(:).^2)); endif if (len > 0) - s = 2 * s / sqrt (2) * sqrt (dx.^2 + dy.^2 + dz.^2) / len; + sd = sqrt (dx.^2 + dy.^2 + dz.^2) / len; + if (sd != 0) + s *= sqrt(2) * sd; + endif u = s * u; v = s * v; if (is3d)