5

Here I am again humbly pleading for your assistance. I need to replicate this figure: enter image description here

So far, I have managed to get this (the view point is not so important): enter image description here

But I am struggling to replicate the effect of the caterpillar waves on the top view.

I tried using the decoration library, with the snake shape, and fill between paths, but it is evident that the result is far from want I need.

Any suggestion?

\documentclass[border=1mm]{standalone}
\usepackage{tikz,pgf,import,pgfplots}
\usepackage{tikz-3dplot}
\usepackage{xcolor}
\usepackage[sfdefault]{universalis}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{shapes}
\pgfplotsset{compat=1.18} 
\definecolor{maincolor}{cmyk}{1, .50, .10, .01}
\tikzstyle{Axes_s} = [color=black,thick,-latex]
\tikzstyle{wborder} = [color=maincolor,thick, line join = bevel]

\begin{document}
\tdplotsetmaincoords{70}{35}
\begin{tikzpicture}[tdplot_main_coords]
% Lenght of the cube
    \def\l{1}
% Points on the floor    
    \coordinate (O) at (0,0,0);         % Centre
    \coordinate (A) at (-5*\l,0,0);     % Left
    \coordinate (B) at (0,5*\l,0);      % Right
    \coordinate (C) at (-5*\l,5*\l,0);  % Behind
% Points on the top    
    \coordinate (Oa) at ($(O)+(0,0,\l)$);   % Centre above
    \coordinate (Aa) at ($(A)+(0,0,\l)$);   % Left above
    \coordinate (Ba) at ($(B)+(0,0,\l)$);   % Right above
    \coordinate (Ca) at ($(C)+(0,0,\l)$);   % Behind above
% Axis
    % \begin{scope}[scale=1,line join=bevel,tdplot_main_coords]
    %   \draw[Axes_s] (O) -- (\l,0,0) node[below, pos=1.0]{$x$};
    %   \draw[Axes_s] (O) -- (0,7*\l,0) node[below, pos=1.05]{$y$} ;
    %   \draw[Axes_s] (O) -- (0,0,2*\l) node[pos=1.05]{$z$};
    % \end{scope}
% Left face
\begin{scope}[canvas is xz plane at y=0]
    \path[name path=leftfloor] (A)--(O);
    \path[wborder,name path=lefttop] (Aa)--(Oa);
    \tikzfillbetween[of=leftfloor and lefttop] {bottom color = maincolor!10, top color= maincolor!10}; 
    \draw[wborder] (Aa) -- (A) -- (O) -- (Oa);
    \draw[wborder, decorate, decoration={snake,segment length=1.64mm,amplitude=0.2mm, pre length=4pt, post length=4pt}] (Aa) -- (Oa);
    % Braces
    \coordinate (xw1) at ($(Aa)!0.15!(Oa)$);
    \coordinate (xd1) at ($(Aa)!0.7!(Oa)$);    
    \draw[decorate,decoration={brace,amplitude=5pt,raise=1pt,aspect=0.5, mirror}] (xw1) -- (xd1) node[black,midway,xshift=0cm, yshift=-0.5cm, font=\footnotesize,align=center,transform shape] {Length of fetch};  
\end{scope}
% Right face
\begin{scope}[canvas is zy plane at x=0]
    \path[name path=rightfloor] (B)--(O);
    \path[wborder,name path=righttop] (Ba)--(Oa);
    \tikzfillbetween[of=rightfloor and righttop] {bottom color = maincolor!10, top color= maincolor!10}; 
    \draw[wborder] (Ba) -- (B) -- (O) -- (Oa);
    \draw[wborder, decorate, decoration={snake,segment length=1.64mm,amplitude=0.2mm, pre length=4pt, post length=4pt}] (Ba) -- (Oa);
\end{scope}
% Braces on the right behind face
\begin{scope}[canvas is xz plane at y=5*\l]
    \coordinate (x1) at (-5*\l,\l);
    \coordinate (x2) at ($(-5*\l,\l)!0.33!(0,\l)$);
    \coordinate (x3) at ($(0,\l)!0.33!(-5*\l,\l)$);
    \coordinate (x4) at (0,\l);
    \draw[decorate,decoration={brace,amplitude=8pt,raise=2pt,aspect=0.25}] (x1) -- (x2) node[black,midway,transform shape,xshift=-0.3cm, yshift=0.8cm, font=\footnotesize,align=center] {  Ripples to\\ wind waves};    
    \draw[decorate,decoration={brace,amplitude=8pt,raise=2pt,aspect=0.65}] (x2) -- (x3) node[black,midway,transform shape,xshift=0.3cm, yshift=0.8cm, font=\footnotesize,align=center] { Fully developed\\ seas};
    \draw[decorate,decoration={brace,amplitude=8pt,raise=2pt,aspect=0.5}] (x3) -- (x4) node[black,midway,transform shape,xshift=0.7cm, yshift=0.8cm, font=\footnotesize,align=center] { Swell waves};
\end{scope}
% Top face
\begin{scope}[canvas is xy plane at z=\l]
    \draw[wborder, name path= righttop, decorate, decoration={snake,segment length=1.64mm,amplitude=0.2mm, pre length=4pt, post length=4pt}] (Ba) -- (Ca);
    \path[wborder, name path= righttop2, decorate, decoration={snake,segment length=1.64mm,amplitude=0.2mm, pre length=4pt, post length=4pt}] (Aa) -- (Oa);
    \draw[wborder, decorate, decoration={snake,segment length=1.64mm,amplitude=0.2mm, pre length=4pt, post length=4pt}] (Aa) -- (Ca);
    \tikzfillbetween[of=righttop and righttop2] {left color = maincolor!10, right color= maincolor!10, fill opacity=0.1};
\end{scope}    
% Arrows wind direction
\begin{scope}[canvas is xy plane at z=2*\l]
    \coordinate (xw) at ($(Aa)!0.5!(Ca)$);
    \coordinate (xd) at ($(Oa)!0.5!(Ba)$);
    \coordinate (xw0) at ($(Aa)!0.2!(Ca)$);
    \coordinate (xd0) at ($(Oa)!0.2!(Ba)$);
    \node[draw,fill=green!20, single arrow,transform shape,font=\footnotesize,align=center] at ($(xd)!0.2!(xw)$) {Direction of\\wave propagation};
    \node[draw,fill=green!20, single arrow,transform shape, font=\footnotesize,align=center] at (xw) {Wind};
\end{scope}
\end{tikzpicture}

\end{document}
3
  • Hi. Do you have at your disposal the equations describing the movement of the water surface (the waves)?
    – Daniel N
    Commented Jun 27, 2022 at 6:34
  • Hi @DanielN, no, that is the issue. I do not have the equations at hand. Commented Jun 28, 2022 at 8:03
  • Well then, it will be a piece of art. You should construct the sections by hand (I think it will be quicker that way) and draw the transversal waves like a painter using the shade attribute.
    – Daniel N
    Commented Jun 29, 2022 at 20:15

1 Answer 1

1

enter image description here

I tried to work up a function wave that struggles to approach the drawing you were talking about. I'm not very proud of the result, but maybe you can use it, or improve it...

Some remarks

  1. The function is represented using \addplot3 a color map.
  2. The bottom part of the drawing is based on fill between.
  3. The arrows are outside the axis environment and so the default coordinate system must have the z axis pointing upwards; I use the variable \lattitude to stress the connection between the two coordinate systems.

The code

\documentclass[11pt, margin=1cm]{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{tikz-3dplot}
\usetikzlibrary{shapes.arrows, math}
\usepgfplotslibrary{colormaps, fillbetween}

\begin{document}

\xdefinecolor{brgb}{RGB}{0, 0, 189}
\xdefinecolor{trgb}{RGB}{105, 255, 255}

\tikzmath{%
  integer \sampls;
  \sampls = 75;
  real \lattitude, \H, \L, \arrowy;
  \lattitude = 70;
  \H = .3;
  \L = 2;
  \arrowy = 4*\L;  %% controls the y position of the two arrows
  function wave(\x, \y) {%
    \a = pow(\x, 2);
    \b = pow(.75*\y, 2);    
    \res = 1/2*pow(cos(360*sqrt(\a +\b)/(.7*\L)), 2);
    \res = \res +1/5*cos(360*2*\x/\L -\y*abs(\y));
    \res = \res +1/2*pow(cos(380*\L/\x), 2);
    return \H*(2 -\x/\L*\res);
  };
}
\begin{tikzpicture}
  \begin{axis}[%
    view={30}{\lattitude},
    height=4cm,
    width=10cm,
    scale only axis,
    zmin=-.8, zmax=.5,
    shader=flat,
    colormap={tmpwaves}{%
      rgb255=(0, 17, 204)
      rgb255=(0, 77, 255)
      rgb255=(105, 255, 255)
      rgb255=(215, 255, 255)
    },
    hide axis,
    % colorbar,
    % colorbar style={font=\scriptsize},
    scale=1.3]

    \addplot3[domain=0.2:{3*\L}, name path=xline,
    draw=none] (\x, -\L, -.8);
    \addplot3[domain y=-\L:{1.5*\L}, name path=yline,
    draw=none] (3*\L, \y, -.8);
    \addplot3[name path=xcurve,
    domain=0.2:{3*\L}, domain y=0:0, samples=\sampls,
    draw=none] (\x, -\L, {wave(\x, -\L)});
    \addplot3 [domain y=-\L:{1.5*\L}, name path=ycurve, draw=none]
    (3*\L, \y, {wave(3*\L, \y)});

    \addplot[top color=trgb, bottom color=brgb]
    fill between[of=xcurve and xline];
    \addplot[fill=brgb]
    fill between[of=yline and ycurve];

    \addplot3[surf, domain=0.2:{3*\L}, domain y=-\L:{1.5*\L},
    samples=\sampls] {wave(\x, \y)};
  \end{axis}

  %% the arrows
  \tdplotsetmaincoords{\lattitude}{30}
  \begin{scope}[tdplot_main_coords, canvas is xy plane at z=5*\H,
    every node/.style={single arrow, transform shape,
      font=\normalsize, align=center}]
    \node[draw, orange!70!black,
    shade, left color=white, right color=orange,
    text width=8em, text height=3ex, text=black]
    at (-.3*\arrowy, \arrowy) {Wind};
    \node[draw, orange!70!black,
    shade, left color=white, right color=orange,
    text=black]
    at (3.8*\L, \arrowy -\L) {Direction of\\wave propagation};
  \end{scope}
\end{tikzpicture}
\end{document}
2
  • Does this compile you exactly as it is? It doesn't work for me neither in Overleaf nor in Texstudio.
    – JIVP
    Commented Sep 17, 2022 at 23:40
  • Hi @HIVP. It works for me; the result of the compilation is Output written on test_tikz.pdf (1 page, 172964 bytes). It takes some time though. Do you have an error massage?
    – Daniel N
    Commented Sep 18, 2022 at 17:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .