2
$\begingroup$

The following graph shows the vector plot. How can I plot the solid lines which represents how the vectors are spatially varying and both on the same graph (vector plot and stream field)?

SliceVectorPlot3D[
Evaluate[Grad[{z - Sin[2 \[Pi] y] Cos[\[Pi] x]}, {x, y, 
 z}]], {"XStackedPlanes", 2}, {x, -1/2, 1/2}, {y, 0, 2}, {z, 0, 1}]
$\endgroup$
6
$\begingroup$

Here are the streamlines using the centers of the arrows in the vector plot as initial conditions:

svp = SliceVectorPlot3D[
  Evaluate[Grad[{z - Sin[2 π y] Cos[π x]}, {x, y, z}]],
    {"XStackedPlanes", 2}, {x, -1/2, 1/2}, {y, 0, 2}, {z, 0, 1}]

streamline[point_] :=
  Line@Transpose@
    NDSolveValue[{{x'[t], y'[t], z'[t]} == 
       First@(Grad[{z - Sin[2 π y] Cos[π x]}, {x, y, z}] /. 
          v : x | y | z :> v[t]), {x[0], y[0], z[0]} == point,
      WhenEvent[Abs[x[t]] > 1/2, "StopIntegration"],
      WhenEvent[Abs[y[t] - 1] > 1, "StopIntegration"],
      WhenEvent[Abs[z[t] - 1/2] > 1/2, "StopIntegration"]},
     Through[{x, y, z}["ValuesOnGrid"]], {t, -10, 10}];

points = Cases[svp, Arrow[a_] :> Mean[a], Infinity];

Show[svp,
 Graphics3D[{Red, streamline /@ points}]
 ]

There's no StreamPlot for 3D, so manual construction is needed. You can use Arrow instead of Line in the definition of streamline. You can also use Arrowheads to put multiple arrows on them.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.