1
$\begingroup$

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:

example

$\endgroup$
5
  • $\begingroup$ ...shouldn't you be using ParametricPlot3D[] for this instead? $\endgroup$ Mar 18, 2016 at 11:59
  • $\begingroup$ Ah, so you want the normal vectors of a surface, then? $\endgroup$ Mar 18, 2016 at 13:45
  • $\begingroup$ 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. $\endgroup$
    – Echows
    Mar 18, 2016 at 14:01
  • 1
    $\begingroup$ 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 $\endgroup$
    – I. Konuk
    Nov 13, 2016 at 14:15
  • $\begingroup$ @I.Konuk Never too late, my friend. $\endgroup$
    – xabdax
    Sep 5, 2021 at 9:50

3 Answers 3

2
$\begingroup$

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]

enter image description here

$\endgroup$
1
  • $\begingroup$ Thanks! This is exactly what I wanted. $\endgroup$
    – Echows
    Mar 18, 2016 at 15:53
2
$\begingroup$

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}}]

enter image description here

$\endgroup$
0
$\begingroup$

@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]}]
$\endgroup$
3
  • 1
    $\begingroup$ 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. $\endgroup$
    – Echows
    Mar 18, 2016 at 12:20
  • $\begingroup$ Something like that? dropbox.com/s/spyrb0peho5vh39/V1.pdf?dl=0 $\endgroup$ Mar 18, 2016 at 12:25
  • $\begingroup$ More like this: postimg.org/image/la0kismuh (from some random article I managed to find) $\endgroup$
    – Echows
    Mar 18, 2016 at 13:39

Your Answer

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

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