但我正在努力在顶视图上复制毛毛虫波的效果。
我尝试使用装饰库、蛇形以及路径之间的填充,但显然结果远远达不到我需要的效果。
有什么建议吗?
\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}
答案1
我尝试开发一个函数,wave
但很难达到你所说的绘图效果。我对结果并不满意,但也许你可以使用它,或者改进它……
一些评论
\addplot3
该功能使用彩色图来表示。- 绘图的底部部分基于
fill between
。 - 箭头在
axis
环境之外,因此默认坐标系的 z 轴向上;我使用变量\lattitude
强调联系两个坐标系之间。
代码
\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}