3

I would like to draw "Velocity field" or "Vector Field" like:

The velocity field for F(x,y,z) = <y,z,x>

I have tried using PGFplots "quiver" but this only works for vector fields on SURFACES:

\begin{tikzpicture}
\begin{axis}[
domain=0:1,
xmax=1,
ymax=1,
]
\addplot3[cyan,/pgfplots/quiver,
quiver/u=y,
quiver/v=z,
quiver/w=x,
quiver/scale arrows=0.1,
-stealth,samples=10] ({x},{y},{x+y});
\end{axis}
\end{tikzpicture}

My (failed) attempt.

Is there a mechanism for drawing vectors on a 3D LATTICE? Something which does

for i from 1 to 10
   for j from 1 to 10
      for k from 1 to 10
            draw vector (i,j,k) -- f(i,j,k);
      end do;
   end do;
end do;

in PGFplots or Tikz? (As done here: 3D Vector Fields in Asymptote )

  • Is there some reason you don't want to use Asymptote? Unlike PGF/TikZ, Asymptote knows about 3D. (3D in PGF/TikZ is 2D pretending to be 3D, which is why drawing order matters, for example.) – cfr Sep 5 '16 at 10:09
  • i.stack.imgur.com/BbhYt.png ;) – cfr Sep 5 '16 at 10:20
  • I have no experience with Asymptote. Was hoping there would be an "in house" solution. – vrbatim Sep 5 '16 at 11:20
6

You could unroll the layers in z direction by hand using \pgfplotsinvokeforeach like in the hedgehog example below. I could not use your example because the parametric function f = (x,y,x+y) actually is a surface.

\documentclass{article}
\usepackage{pgfplots}
\begin{document}

\begin{tikzpicture}
  \begin{axis}[
    domain=-1:1,
    samples=10,
    xmin=-1,xmax=1,
    ymin=-1,ymax=1,
    zmin=-1,zmax=1,
    ]
    \pgfplotsinvokeforeach{-1,-.5,0,.5,1}{
      \addplot3[cyan,quiver,-stealth,
      point meta={sqrt((x)^2+(y)^2+(z)^2)},
      quiver={
        u={x/sqrt((x)^2+(y)^2+(z)^2)},
        v={y/sqrt((x)^2+(y)^2+(z)^2)},
        w={z/sqrt((x)^2+(y)^2+(z)^2)},
        colored,scale arrows=.1}]
      (x,y,#1);
    }
  \end{axis}
\end{tikzpicture}

\end{document}

enter image description here

  • Very impressive! I'm relieved that my attempt with the equation from the question was not totally wrong-headed. I thought I must be missing something when it didn't look three dimensional. – cfr Sep 5 '16 at 16:24

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.