6
$\begingroup$

I want to plot a 2D vector function such as $F(x,y) = (a(x,y),\,b(x,y))$ in a 3D graph so that the vectors are embedded in the xy plane. I tried to do the following:

First I defined a piecewise function like this

g[z_] := Piecewise[{{1, z == 0}}, 0]

Then I converted the 2D vector function to a 3D one by setting the 3rd component to zero and multiplying 1st and 2nd components by g[z] so that the x and y components are null when z != 0:

f[x_, y_, z_] := {x g[z], y g[z], 0};

Plot the function:

VectorPlot3D[{x g[z], y g[z],0}, {x, -5, 5}, {y, -5, 5}, {z, -5, 5}]

The issue with this solution is that VectorPlot3D won't evaluate the function in the relevant points, The above example shows an empty graph, because Mathematica jumps from z = -1 to z = 1 without evaluating z = 0.

I tried with RegionFunction (which would've rendered the definition of the above-mentioned piecewise function useless), but that only accepts inequalities, and I want to evaluate the function at any coordinate {x ,y, 0}.

I could feed it a list of vectors via VectorPoints -> { {a, b, 0}, {c, d, 0}, ...}, but that's not an elegant solution at all. Are there other ways to do this?

$\endgroup$
2

2 Answers 2

8
$\begingroup$
VectorPlot3D[{x, y, 0}, {x, -2, 2}, {y, -2, 2}, {z, -2, 2},
 RegionFunction -> ((-.1 < #3 < .1) &),
 VectorPoints -> {8, 8, 3},
 VectorStyle -> "Arrow3D",
 VectorColorFunction -> "Rainbow",
 VectorScale -> Scaled[0.15]]

enter image description here

$\endgroup$
2
  • $\begingroup$ It works fine, although I don't fully understand the syntax. What does #3 mean? Does it represent the third argument of the function? And what does the & operator do? $\endgroup$
    – DvD
    Commented Apr 2, 2013 at 23:24
  • $\begingroup$ @DvD #3 represents vertical coordinate z. If I wouldn't put limitation with RegionFunction, you would see many parallel identical planes. I limited plotting to a narrow region around a single plane with a constraint in z-coordinate (-.1 < #3 < .1) &. $\endgroup$ Commented Apr 2, 2013 at 23:28
6
$\begingroup$
Graphics3D[
  VectorPlot[{x, y}, {x, -1, 1}, {y, -1, 1}][[1, 2]] /. 
    Arrow[{{x1_, y1_}, {x2_, y2_}}] :> Arrow[{{x1, y1, 0}, {x2, y2, 0}}
  ]
]

Mathematica graphics

$\endgroup$
3
  • $\begingroup$ Combining this result with some other graphs (such as a scalar function) is a bit troubling, but it's helpful to know nevertheless! $\endgroup$
    – DvD
    Commented Apr 2, 2013 at 23:20
  • 1
    $\begingroup$ @DvD This figure should combine with other graphics just fine. Have you tried Show? $\endgroup$ Commented Apr 3, 2013 at 5:22
  • $\begingroup$ Um, back when I formulated my comment, it just showed some huge arrows for some reason. I tried it again and it works now. I can't tell what I did differently this time. $\endgroup$
    – DvD
    Commented Apr 3, 2013 at 10:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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