1

I have code which outputs a number of parabolas

\begin{document}
\tdplotsetmaincoords{70}{20}
\begin{tikzpicture}[tdplot_main_coords,
declare function={pX=2;}]
 \begin{scope}[canvas is yz plane at x=0]
  \draw (-pX,-pX) coordinate (bl1) -- (pX,-pX) coordinate (br1)
   -- (pX,pX) coordinate (tr1)  -- (-pX,pX) coordinate (tl1) -- cycle;
   \draw[stealth-stealth] (0,pX) node[below left]{$x_2$}
   -- (0,0) --  (pX,0) node[below left]{$x_1$};
   \pgflowlevelsynccm
   %\draw[-{Latex[bend]}] (2,0) arc(0:380:1);
   %\draw[-{Latex[bend]}] (0,-1) arc(-90:290:1);
   %\draw[-{Latex[bend]}] (0,0) arc(-90:380:1);
 \end{scope}
 \foreach \X in {bl,tl,br,tr}
 {\draw[-latex] (\X1) -- ++ (1,0,0);}
 %
 \draw (0,0,0) -- (4,0,0);
 % plane
  \fill[gray,fill opacity=0.3] (-1,-4,0) -- (7,-4,0) --
  (7,4,0) -- (-1,4,0) -- cycle;
 \begin{scope}[canvas is yz plane at x=4]
  \draw (-pX,-pX) coordinate (bl2) -- (pX,-pX) coordinate (br2)
   -- (pX,pX) coordinate (tr2)  -- (-pX,pX) coordinate (tl2) -- cycle;
   \draw[stealth-stealth] (0,pX) -- (0,0) --  (pX,0);
   \pgflowlevelsynccm
   %\draw[-{Latex[bend]}] (1,0) arc(0:380:0.25);
   %\draw[-{Latex[bend]}] (0,-0.25) arc(-90:290:0.25);
   %\draw[-{Latex[bend]}] (0,0.25) arc(-90:380:0.25);
 \end{scope}
 \draw[-latex] (4,0,0) -- (6,0,0) node[below left]{$x_3$};
 \foreach \X in {bl,tl,br,tr}
 {\draw[-latex] (\X2) -- ++ (1,0,0);}
  \begin{scope}[canvas is xy plane at z=0]
   \begin{scope}
        \clip (0,-2) rectangle (4,3);
        \foreach \X in {-2,-1.6,...,2}
         {\draw (0,\X) parabola ++(5,1);}
       \end{scope} 
%       \draw[-stealth] (-1,0) -- (5,0) node[below right]{$x_3$};
%       \draw[-stealth] (0,-0.5) node[above left]{$0$} -- (0,3)
%       node[right=2em,yshift=-1em]{$\theta(x_3)$};
%       \draw[-stealth] (4,-0.5) node[above left]{$L$} -- (4,3) node[below right]{$x_1$};
  \end{scope}
\end{tikzpicture}
\end{document}

which looks like this.

I am trying to replace the parabola curves by a series of lines like this enter image description here so as to make a series of layers with each layer having a random arrow direction. Can this be done in tikz? Thanks in advance.

1

This adds random arrows.

\documentclass[tikz,border=3mm]{standalone}
\usepackage{tikz-3dplot}
\begin{document}
\tdplotsetmaincoords{70}{20}
\begin{tikzpicture}[tdplot_main_coords,
declare function={pX=2;}]
 \begin{scope}[canvas is yz plane at x=0]
  \draw (-pX,-pX) coordinate (bl1) -- (pX,-pX) coordinate (br1)
   -- (pX,pX) coordinate (tr1)  -- (-pX,pX) coordinate (tl1) -- cycle;
   \draw[stealth-stealth] (0,pX) node[below left]{$x_2$}
   -- (0,0) --  (pX,0) node[below left]{$x_1$};
   \pgflowlevelsynccm
 \end{scope}
 \foreach \X in {bl,tl,br,tr}
 {\draw[-latex] (\X1) -- ++ (1,0,0);}
 %
 \draw (0,0,0) -- (4,0,0);
 % plane
  \fill[gray,fill opacity=0.3] (-1,-4,0) -- (7,-4,0) --
  (7,4,0) -- (-1,4,0) -- cycle;
 \begin{scope}[canvas is yz plane at x=4]
  \draw (-pX,-pX) coordinate (bl2) -- (pX,-pX) coordinate (br2)
   -- (pX,pX) coordinate (tr2)  -- (-pX,pX) coordinate (tl2) -- cycle;
   \draw[stealth-stealth] (0,pX) -- (0,0) --  (pX,0);
 \end{scope}
 \draw[-latex] (4,0,0) -- (6,0,0) node[below left]{$x_3$};
 \foreach \X in {bl,tl,br,tr}
 {\draw[-latex] (\X2) -- ++ (1,0,0);}
  \begin{scope}[canvas is xy plane at z=0]
   \begin{scope}
      \clip (0,-2) rectangle (4,3);
      \foreach \X in {0.25,0.75,...,2.75}
       {\pgfmathsetmacro{\myrnd}{rnd*360}
       \foreach \Y in {-1.75,-1.25,...,1.75}
        {
        \draw[-stealth] ({\X-0.2*cos(\myrnd)},{\Y-0.2*sin(\myrnd)}) --
        ({\X+0.2*cos(\myrnd)},{\Y+0.2*sin(\myrnd)});
        }
        \draw[densely dashed] (\X+0.25,-2) -- (\X+0.25,2);}
%       \foreach \X in {-2,-1.6,...,2}
%        {\draw (0,\X) parabola ++(5,1);}
   \end{scope} 
  \end{scope}
\end{tikzpicture}
\end{document}

enter image description here

Or

\documentclass[tikz,border=3mm]{standalone}
\usepackage{tikz-3dplot}
\begin{document}
\tdplotsetmaincoords{70}{20}
\begin{tikzpicture}[tdplot_main_coords,
declare function={pX=2;}]
 \begin{scope}[canvas is yz plane at x=0]
  \draw (-pX,-pX) coordinate (bl1) -- (pX,-pX) coordinate (br1)
   -- (pX,pX) coordinate (tr1)  -- (-pX,pX) coordinate (tl1) -- cycle;
   \draw[stealth-stealth] (0,pX) node[below left]{$x_2$}
   -- (0,0) --  (pX,0) node[below left]{$x_1$};
   \pgflowlevelsynccm
 \end{scope}
 \foreach \X in {bl,tl,br,tr}
 {\draw[-latex] (\X1) -- ++ (1,0,0);}
 %
 \draw (0,0,0) -- (4,0,0);
 % plane
  \fill[gray,fill opacity=0.3] (-1,-4,0) -- (7,-4,0) --
  (7,4,0) -- (-1,4,0) -- cycle;
 \begin{scope}[canvas is yz plane at x=4]
  \draw (-pX,-pX) coordinate (bl2) -- (pX,-pX) coordinate (br2)
   -- (pX,pX) coordinate (tr2)  -- (-pX,pX) coordinate (tl2) -- cycle;
   \draw[stealth-stealth] (0,pX) -- (0,0) --  (pX,0);
 \end{scope}
 \draw[-latex] (4,0,0) -- (6,0,0) node[below left]{$x_3$};
 \foreach \X in {bl,tl,br,tr}
 {\draw[-latex] (\X2) -- ++ (1,0,0);}
 \foreach \Z in {0,0.5,...,2} 
  {\begin{scope}[canvas is xy plane at z=\Z]
   \begin{scope}
      \foreach \X in {0.25,0.75,...,2.75}
       {\pgfmathsetmacro{\myrnd}{rnd*360}
       \foreach \Y in {-1.75,-1.25,...,1.75}
        {
        \draw[-stealth] ({\X-0.2*cos(\myrnd)},{\Y-0.2*sin(\myrnd)}) --
        ({\X+0.2*cos(\myrnd)},{\Y+0.2*sin(\myrnd)});
        }
        \draw[densely dashed] (\X+0.25,-2) -- (\X+0.25,2);}
%       \foreach \X in {-2,-1.6,...,2}
%        {\draw (0,\X) parabola ++(5,1);}
   \end{scope} 
  \end{scope}}
\end{tikzpicture}
\end{document}

enter image description here

4
  • This is perfect almost! How can I change this so that between each row of arrows there is a dotted line, and also, in each row all the arrows point in the same direction? I just want each row of arrows in the x3 direction to be at random directions. – rami_salazar Nov 13 '19 at 17:15
  • @rodger_kicks Done. – user194703 Nov 13 '19 at 17:20
  • This is perfect. I can't thank you enough. Is it easy to extend this into the x2 axis, to make the "layers" extend upwards? So that the dashed lines go upwards and the arrows repeat? – rami_salazar Nov 13 '19 at 17:29
  • 1
    @rodger_kicks I added a loop over \Z :\foreach \Z in {0,0.5,...,2} . You can change the values to move the arrows closer or further away from each other. – user194703 Nov 13 '19 at 17:33

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.