# Extending an Animated Vector Flow from Two to Three Dimensions

I found some code for animating a two-dimensional vector flow on stackexchange. Unfortunately, I can't find the original post so I can't credit the author. I have modified the code for my purposes below.

In any case, I would like to take this code and extend it up to an animation of a three-dimensional vector flow. In others words, I’d like to make the same animation but with a 3D vector field.

I think this would be great to share with my multivariable calculus students.

Manipulate[

Graphics[{Thickness[0.005], CapForm["Round"], lines[i]},
Background -> White, PlotRange -> 10],
{{i, 1, ""}, 1, Infinity, 1, ControlType -> Trigger,
AppearanceElements -> {"TriggerButton", "PauseButton"}},

Initialization :> (
plot =
StreamPlot[{-y, Sin[x] x}, {x, -10, 10}, {y, -10, 10},
StreamPoints -> 12];
splines = Cases[plot, Arrow[data_] :> BSplineFunction[data], -1];
r = Range[0, 1, 0.09];
cols = Opacity[#, Blue] & /@ r;
lines[i_] :=
Map[Line[# /@ r, VertexColors -> RotateRight[cols, i]] &,
splines];), Paneled -> False]


A visual is shown below.

I am having a hard time rotating the vertex colors in 3D, perhaps because I'm having a hard time understanding splines in 3D? Any ideas? I would like to be able to rotate the 3d graphic while it’s flowing.

For example, how would I create the same animated effect for

StreamPlot3D[{-y, Sin[x] x, x}, {x, -10, 10}, {y, -10, 10}, {z, -10,
10}]


while preserving the ability to rotate the 3D graphic without causing the animation to stop or hesitate.

• Please post a 3D version of the static stream plot. Commented Dec 3, 2023 at 1:02
• @cvgmt Updated. This is more of a general-purpose tool, but edited the post to provide an example. Commented Dec 3, 2023 at 1:08

• Dynamic change the position of Arrowheads.
Manipulate[
StreamPlot3D[{-y, Sin[x] x, x}, {x, -10, 10}, {y, -10, 10}, {z, -10,
10}, StreamMarkers -> "Arrow"] /.
Arrow[b_] -> {Arrowheads[{{.025, t}}], Arrow[b]}, {t, 0, 1}]


• We can also rewrite the original 2D case to 3D case.
• Add StreamMarkers -> "Arrow".
Clear["Global*"];
plot = StreamPlot3D[{-y, Sin[x] x, x}, {x, -10, 10}, {y, -10,
10}, {z, -10, 10}, StreamMarkers -> "Arrow", StreamPoints -> 12];
splines = Cases[plot, Arrow[data_] :> BSplineFunction[data], -1];
r = Range[0, 1, 0.09];
cols = Opacity[#, Blue] & /@ r;
lines[i_] :=
Map[Line[# /@ r, VertexColors -> RotateRight[cols, i]] &, splines];
Manipulate[
Graphics3D[{Thickness[0.005], CapForm["Round"], lines[i]},
Background -> White, PlotRange -> 10], {{i, 1, ""}, 1, Infinity, 1,
ControlType -> Trigger,
AppearanceElements -> {"TriggerButton", "PauseButton"}},
Paneled -> False]
`