为什么在这种情况下 x 坐标永远不为负数?

为什么在这种情况下 x 坐标永远不为负数?

我已遵循说明这里在水波槽末端创建一个造波器。代码如下:

\documentclass[a4paper, 12pt]{article}

\usepackage{tikz}
\usepackage{tikz-3dplot}
\usepackage{pgfplots}

\usepgflibrary{shapes.geometric}
\usetikzlibrary{calc}
\usepgfplotslibrary{patchplots}

\begin{document}
 \begin{figure}
\centering
%\tdplotsetmaincoords{75}{-30}
\pgfplotsset{compat = newest}
\begin{tikzpicture}
        [   axisstyle/.style={->,blue,thick},
            tankedge/.style={thick,black},      
            fsedge/.style={thick,black},
            fssurf/.style={red, opacity=.5},
            bottomsurf/.style={gray, opacity=.05},
            scale=2.5,
            ]
            \pgfmathsetmacro{\Lx}{15}
            \pgfmathsetmacro{\Ly}{1}
            \pgfmathsetmacro{\h}{3}
            \pgfmathsetmacro{\d}{1}

    \begin{axis}[ ticks=none, axis lines = middle, axis line style=axisstyle,
    xmin=-0.5,xmax={\Lx+1},
        ymin=-0.5,ymax={\Ly+1},
    zmin=-\h,zmax=\h,   
        %view={0}{0},
    xlabel={$x$},ylabel={$y$},zlabel={$z$}]
    \node at (axis cs:0,0,0) [anchor=east]{$O$};
    \node at (axis cs:0,0,-\h) [anchor=east]{$z=-h$};

    %draw MWL & bottom
    \draw[tankedge] (0,0,0) -- ({\Lx},0,0) -- ({\Lx},{\Ly},0) -- (0,{\Ly},0) -- cycle;
    \draw[tankedge] (0,0,{-\h}) -- ({\Lx},0,{-\h}) -- ({\Lx},{\Ly},{-\h}) -- (0,{\Ly},{-\h}) -- cycle;
    \addplot3[patch,bottomsurf,patch type=rectangle,faceted color=black] coordinates{(0,0,-\h) (\Lx,0,-\h) (\Lx,\Ly,-\h) (0,\Ly,-\h)};
    % Far end wall
    \draw[tankedge] ({\Lx},0,0) -- ({\Lx},0,{-\h}) -- ({\Lx},{\Ly},{-\h}) -- ({\Lx},{\Ly},0) -- cycle;
    % Wavemaker Paddle
    \addplot3[surf,fssurf,domain=0:{\Ly},domain y={-\h+\d}:0,shader=flat] ({0.5*(1+y/(\h-\d))*cos(3*pi*x)},x,y);        

    \end{axis}
\end{tikzpicture}
\end{figure}
\end{document}

这个数字是这样的 - 在此处输入图片描述

我无法弄清楚,尽管代码中给出了表面\addplot3[surf,fssurf,domain=0:{\Ly},domain y={-\h+\d}:0,shader=flat] ({0.5*(1+y/(\h-\d))*cos(3*pi*x)},x,y);

图形表面的 x 坐标永不变为负值。

答案1

问题是 TiZ/pgfplots 假设三角函数的参数以度为单位,除非另有说明。为了切换到弧度,您可以使用trig format plots=rad或将三角函数的参数包装到 中deg,等等。

你的其它问题我认为您想在绘图中添加一些水波。这里有一种方法可以添加水波,即在造波器桨的位置,波浪跟随桨,而在远处,它们只是平行波。插值是用 完成的tanh

\documentclass[tikz,border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\begin{document}
\begin{tikzpicture}
        [   axisstyle/.style={->,blue,thick},
            tankedge/.style={thick,black},      
            fsedge/.style={thick,black},
            fssurf/.style={red, opacity=.5},
            bottomsurf/.style={gray, opacity=.05},
            scale=2.5,
            ]
            \pgfmathsetmacro{\Lx}{15}
            \pgfmathsetmacro{\Ly}{1}
            \pgfmathsetmacro{\h}{3}
            \pgfmathsetmacro{\d}{1}
            \pgfmathsetmacro{\Lcrit}{6}
            \pgfmathsetmacro{\hw}{-0.4} % water level
            \pgfmathsetmacro{\aw}{0.2} % amplitude of waves

 \begin{axis}[ ticks=none, axis lines = middle, axis line style=axisstyle,
    xmin=-0.5,xmax={\Lx+1},
        ymin=-0.5,ymax={\Ly+1},
    zmin=-\h,zmax=\h,   
        %view={0}{0},
    xlabel={$x$},ylabel={$y$},zlabel={$z$},
    declare function={f(\z,\y)=0.5*(1+\z/(\h-\d))*cos(deg(3*pi*\y));
    g(\x,\y,\z)=0.5*(tanh(3*(\Lcrit-\x))+1)*f(\z,\y)+\x;
    w(\x)=\aw*cos(deg(\x*pi));},
    %trig format plots=rad,
    ]
    \node at (0,0,0) [anchor=east]{$O$};
    \node at (0,0,-\h) [anchor=east]{$z=-h$};

    %draw MWL & bottom
    \draw[tankedge] (0,0,0) -- ({\Lx},0,0) -- ({\Lx},{\Ly},0) -- (0,{\Ly},0) -- cycle;
    \draw[tankedge] (0,0,{-\h}) -- ({\Lx},0,{-\h}) -- ({\Lx},{\Ly},{-\h}) -- (0,{\Ly},{-\h}) -- cycle;
    \addplot3[patch,bottomsurf,patch type=rectangle,faceted color=black] coordinates{(0,0,-\h) (\Lx,0,-\h) (\Lx,\Ly,-\h) (0,\Ly,-\h)};
    % Far end wall
    \draw[tankedge] ({\Lx},0,0) -- ({\Lx},0,{-\h}) -- ({\Lx},{\Ly},{-\h}) -- ({\Lx},{\Ly},0) -- cycle;
    % Wavemaker Paddle
    \addplot3[surf,fssurf,domain y=0:{\Ly},domain={-\h+\d}:0,shader=flat] 
        ({f(x,y)},y,x);        
    \addplot3[surf,shader=interp,opacity=0.8,
        colormap={blueblack}{color=(blue) color=(blue!60)},
        domain y=0:{\Ly},domain=0:\Lx,samples=51,samples y=51]
    ({g(x,y,\hw+\aw)},y,{\hw+w(x)});
    \fill[blue,opacity=0.8] plot[variable=\x,domain=0:\Lx,samples=51] 
     ({g(\x,0,\hw+\aw)},0,{\hw+w(\x)}) -- ({\Lx},0,-\h)-- 
     (0,0,-\h) --  (0,0,-\h+\d) -- cycle
     ({g(\Lx,0,\hw+\aw)},0,{\hw+w(\Lx)}) --
     ({g(\Lx,\Ly,\hw+\aw)},\Ly,{\hw+w(\Lx)}) --(\Lx,\Ly,-\h)  
     --(\Lx,0,-\h) -- cycle; 
    \draw[tankedge,line cap=round] (0,0,0) -- ({\Lx},0,0)
     edge ({\Lx},0,-\h) -- ({\Lx},{\Ly},0)
     -- ({\Lx},{\Ly},-\h) --  ({\Lx},0,-\h) -- (0,0,-\h) -- cycle;
 \end{axis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容