# HG changeset patch # User Rik # Date 1301581991 25200 # Node ID 4040a95a586d0361ae16b9e914b61145f436bc37 # Parent 7c915d013b9c75dc183d79b3534bccd8ede63a80 Revamp quiver autoscaling algorithm (bug #32836). diff -r 7c915d013b9c -r 4040a95a586d scripts/ChangeLog --- a/scripts/ChangeLog Thu Mar 31 07:13:33 2011 -0700 +++ b/scripts/ChangeLog Thu Mar 31 07:33:11 2011 -0700 @@ -1,3 +1,7 @@ +2011-03-31 Rik + + * plot/private/__quiver__.m: Revamp autoscaling algorithm (bug #32836). + 2011-03-29 John W. Eaton * special-matrix/wilkinson.m: Update test for 'wilkinson(1)' to reflect diff -r 7c915d013b9c -r 4040a95a586d scripts/plot/private/__quiver__.m --- a/scripts/plot/private/__quiver__.m Thu Mar 31 07:13:33 2011 -0700 +++ b/scripts/plot/private/__quiver__.m Thu Mar 31 07:33:11 2011 -0700 @@ -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)