adds 3d quiver if z component is present.

This commit is contained in:
Ronny Bergmann 2020-11-10 11:24:24 +01:00
parent 092c7376c8
commit d3f2a55b59

View File

@ -1197,35 +1197,51 @@ function quiver_using_arrows(plotattributes::AKW)
if !isa(plotattributes[:arrow], Arrow) if !isa(plotattributes[:arrow], Arrow)
plotattributes[:arrow] = arrow() plotattributes[:arrow] = arrow()
end end
is_3d = haskey(plotattributes,:z)
velocity = error_zipit(plotattributes[:quiver]) velocity = error_zipit(plotattributes[:quiver])
xorig, yorig = plotattributes[:x], plotattributes[:y] xorig, yorig = plotattributes[:x], plotattributes[:y]
zorig = is_3d ? plotattributes[:z] : []
# for each point, we create an arrow of velocity vi, translated to the x/y coordinates # for each point, we create an arrow of velocity vi, translated to the x/y coordinates
x, y = zeros(0), zeros(0) x, y = zeros(0), zeros(0)
for i = 1:max(length(xorig), length(yorig)) is_3d && ( z = zeros(0))
for i = 1:max(length(xorig), length(yorig), length(zorig))
# get the starting position # get the starting position
xi = _cycle(xorig, i) xi = _cycle(xorig, i)
yi = _cycle(yorig, i) yi = _cycle(yorig, i)
zi = is_3d ? _cycle(zorig, i) : 0
# get the velocity # get the velocity
vi = _cycle(velocity, i) vi = _cycle(velocity, i)
vx, vy = if istuple(vi) if is_3d
first(vi), last(vi) vx, vy, vz = if istuple(vi)
elseif isscalar(vi) vi[1], vi[2], vi[3]
vi, vi elseif isscalar(vi)
elseif isa(vi, Function) vi, vi, vi
vi(xi, yi) elseif isa(vi, Function)
else vi(xi, yi, zi)
error("unexpected vi type $(typeof(vi)) for quiver: $vi") else
error("unexpected vi type $(typeof(vi)) for quiver: $vi")
end
else # 2D quiver
vx, vy = if istuple(vi)
first(vi), last(vi)
elseif isscalar(vi)
vi, vi
elseif isa(vi, Function)
vi(xi, yi)
else
error("unexpected vi type $(typeof(vi)) for quiver: $vi")
end
end end
# add the points # add the points
nanappend!(x, [xi, xi + vx, NaN]) nanappend!(x, [xi, xi + vx, NaN])
nanappend!(y, [yi, yi + vy, NaN]) nanappend!(y, [yi, yi + vy, NaN])
is_3d && nanappend!(z, [zi, zi + vz, NaN])
end end
plotattributes[:x], plotattributes[:y] = x, y plotattributes[:x], plotattributes[:y] = x, y
if is_3d
plotattributes[:z] = z
end
# KW[plotattributes] # KW[plotattributes]
end end