# Plotting a 3D vector field on 2D plane

I want to visualize vector field that is of the form $(v_1(x,y), v_2(x,y), v_3(x,y))$, i.e. there is a three component vector that depends on only two coordinates $x$ and $y$ in the real plane. There are Mathematica functions VectorPlot[] and VectorPlot3D[] but both of them assume that the dimensionality of the space is the same as the number of vector components. In the latest version of Mathematica there also seems to be something called SliceVectorPlot3D[], but I don't have this in my Mathematica so I would prefer to use some other way. Furthermore, if it matters at all, the vectors are normalized so that I only care about the direction of the vector at a given point on the plane.

How do I do this?

EDIT: Here's an example of something I would like to get:

• ...shouldn't you be using ParametricPlot3D[] for this instead? – J. M. will be back soon Mar 18 '16 at 11:59
• Ah, so you want the normal vectors of a surface, then? – J. M. will be back soon Mar 18 '16 at 13:45
• Not normals. The surface is just a regular 2D plane (i.e. normals would be all point up), but for every point of the plane is attached one 3D vector that I would like to visualize. – Echows Mar 18 '16 at 14:01
• This may be a little late. I would like to mention that new versions of Mathematica has a function "SliceVectorPlot3D" just for this. The second example in the help documentation is very similar to the task at hand here. But I cauting, this function seems to be a little buggy. I am struggling to use it with complex surfaces. I. Konuk – I. Konuk Nov 13 '16 at 14:15

You can just do this with graphics primitives:

v = Flatten[
Table[ { x , y  , { Sin[x ] , Cos[ y] , 2} } , {x, -Pi,
Pi, .5} , {y, -Pi, Pi, .5}], 1];
Graphics3D[{Red,
Arrow[Tube[{{#[[1]], #[[2]],
0}, {#[[1]] + #[[3, 1]], #[[2]] + #[[3, 2]], #[[3,
3]]}}]]} & /@ v, Axes -> True]


• Thanks! This is exactly what I wanted. – Echows Mar 18 '16 at 15:53

Another take, using ListPointPlot3D:

Define vector field on the x-y plane:

f[x_, y_] = {.3 Sin[x], .3 Cos[y], 1}


Define grid on the x-y plane where the vector tails will be placed:

data = Flatten[Table[{x, y, 0}, {x, -Pi, Pi, Pi/4}, {y, -Pi, Pi, Pi/4}], 1]


Plot with ListPointPlot3D using a replacement rule to convert points to vectors:

ListPointPlot3D[data] /. Point[a_] :> (Arrow[Tube[{#, # + f @@ Most@#}, .05]] & /@ a)


Easily extendable to arbitrary surfaces (just add some z[x,y] instead of 0 in the data specification.

z[x_, y_] = .3 Sin[x] + .3 Cos[y];
data = Flatten[Table[{x, y, z[x, y]}, {x, -Pi, Pi, Pi/4}, {y, -Pi, Pi, Pi/4}], 1];
ListPointPlot3D[data] /. {Point[a_] :> (Arrow[Tube[{#, # + f @@ Most@#}]] & /@ a)};
ListPlot3D[data];
Show[{%, %%}, PlotRangePadding -> {.3, .3, {.1, .9}}]


@J.M. is right. Define each vector as a function (eg v1[x_,y_]:=x+y) and then use ParametricPlot3D[] parametrized for x and y.

Example:

v1[x_, y_] := Sin[x]*y;
v2[x_, y_] := Cos[x]*y;
v3[x_, y_] := x;
ParametricPlot3D[{v1[x, y], v2[x, y], v3[x, y]},
{x, -2 \[Pi], 2 \[Pi]}, {y, -2 \[Pi], 2 \[Pi]}]

• This draws a surface parametrized by my vector. I want the result to look like VectorPlot3D but only on a surface. The vectors can of course stick out from the surface, but their starting points need to be on it. – Echows Mar 18 '16 at 12:20
• Something like that? dropbox.com/s/spyrb0peho5vh39/V1.pdf?dl=0 – Ozb4mCLIVtxVf6mkd7nk Mar 18 '16 at 12:25
• More like this: postimg.org/image/la0kismuh (from some random article I managed to find) – Echows Mar 18 '16 at 13:39