画两个相同的管子来说明数学问题

画两个相同的管子来说明数学问题

我正在用本网站的 percusse 修改代码来解决我的数学问题。你能帮忙添加右侧管子的标记吗?

在此处输入图片描述

\documentclass[tikz]{standalone}
\usetikzlibrary{calc}
\begin{document}

\begin{tikzpicture}[scale=.54]
\shade[left color=red,right color=red!40] 
    (-1,-2)--(-1,-5) arc (180:360:1)  -- (1,-2) arc (0:180:1 and 0.3);
\draw (0,0) ellipse (1 and .3);
\draw (-1,0)--(-1,-5) arc (180:360:1) --(1,-5) -- (1,0);
\draw[red!90!black!70] (0,-2) ellipse (1 and .3);

\foreach \y/\x in {-5/1,-4/2,-3/3,-2/4}
    {
    \draw (-0.2,\y) to[bend right=10](0.2,\y) node[right,yslant=0.15](\x){};

    \foreach \z in {0.2,0.4,0.6,0.8}
       \draw ($(-0.1,\z) + (0,\y)$)to[bend right=5]($(0.1,\z)+(0,\y)$);
    };



\shade[left color=red,right color=red!40] 
    (3,-2.7)--(3,-5) arc (180:360:1)  -- (5,-2.7) arc (0:180:1 and 0.3);
\draw (4,0) ellipse (1 and .3);
\draw (3,0)--(3,-5) arc (180:360:1) --(5,-5) -- (5,0);
\draw[red!90!black!70] (4,-2.7) ellipse (1 and .3);


\foreach \y/\x in {-5/1,-4/2,-3/3,-2/4}
    {
    \draw (3.8,\y) to[bend right=10](4.2,\y) node[right,yslant=0.15](\x){};

    \foreach \z in {0.2,0.4,0.6,0.8}
       \draw ($(-0.1,\z) + (0,\y)$)to[bend right=15]($(0.1,\z)+(0,\y)$);
    };
\end{tikzpicture}

\end{document}

答案1

您可以定义一个pic,然后在自定义位置使用自定义参数重复使用它。

笔记:管子的代码取自这个答案@percusse 的。

\documentclass[tikz,border=7mm]{standalone}

\tikzset{
  tube/.pic={
    \pgfmathsetmacro\level{#1-5.7}
    \shade[left color=.,right color=.!40]
      (-1,\level)--(-1,-5) arc (180:360:1) -- (1,\level) arc (0:180:1 and 0.3);
    \draw[.!90!black!70] (0,\level) ellipse (1 and .3);
    \begin{scope}[black]
      \draw (0,0) ellipse (1 and .3);
      \draw (-1,0)--(-1,-5) arc (180:360:1) --(1,-5) -- (1,0);
      \foreach \y/\x in {-5/1,-4/2,-3/3,-2/4}{
        \draw (-0.2,\y) to[bend right=10](0.2,\y) node[right,yslant=0.15](\x){\x};
        \foreach \z in {0.2,0.4,0.6,0.8}
          \draw[yshift=\y cm] (-0.1,\z)to[bend right=5](0.1,\z);
      };
    \end{scope}
  }
}

\begin{document}
  \begin{tikzpicture}
    \pic[red]{tube=2};
    \path (3,0) pic[blue]{tube=3.4} ++(3,0) pic[green]{tube=2.8};
  \end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

您可以shift在这里使用。再次使用 绘制相同的管子xshift=4cm,然后调整填充高度和红色椭圆。

\documentclass[tikz]{standalone}
\usetikzlibrary{calc}
\begin{document}

\begin{tikzpicture}[scale=.54]
\shade[left color=red,right color=red!40]
    (-1,-2)--(-1,-5) arc (180:360:1)  -- (1,-2) arc (0:180:1 and 0.3);
\draw (0,0) ellipse (1 and .3);
\draw[red!90!black!70] (0,-2) ellipse (1 and .3);   %% put this before
\draw (-1,0)--(-1,-5) arc (180:360:1) --(1,-5) -- (1,0);    %% put this line here

\foreach \y/\x in {-5/1,-4/2,-3/3,-2/4}
    {
    \draw (-0.2,\y) to[bend right=10](0.2,\y) node[right,yslant=0.15](\x){};

    \foreach \z in {0.2,0.4,0.6,0.8}
       \draw ($(-0.1,\z) + (0,\y)$)to[bend right=5]($(0.1,\z)+(0,\y)$);
    };

\begin{scope}[xshift=4cm]
\shade[left color=red,right color=red!40]
    (-1,-2.7)--(-1,-5) arc (180:360:1)  -- (1,-2.7) arc (0:180:1 and 0.3);
\draw (0,0) ellipse (1 and .3);

\draw[red!90!black!70] (0,-2.7) ellipse (1 and .3);
\draw (-1,0)--(-1,-5) arc (180:360:1) --(1,-5) -- (1,0);   %% put this line here

\foreach \y/\x in {-5/1,-4/2,-3/3,-2/4}
    {
    \draw (-0.2,\y) to[bend right=10](0.2,\y) node[right,yslant=0.15](\x){};

    \foreach \z in {0.2,0.4,0.6,0.8}
       \draw ($(-0.1,\z) + (0,\y)$)to[bend right=5]($(0.1,\z)+(0,\y)$);
    };
    \end{scope}


%\shade[left color=red,right color=red!40]
%    (3,-2.7)--(3,-5) arc (180:360:1)  -- (5,-2.7) arc (0:180:1 and 0.3);
%\draw (4,0) ellipse (1 and .3);
%\draw (3,0)--(3,-5) arc (180:360:1) --(5,-5) -- (5,0);
%\draw[red!90!black!70] (4,-2.7) ellipse (1 and .3);
%
%
%\foreach \y/\x in {-5/1,-4/2,-3/3,-2/4}
%    {
%    \draw (3.8,\y) to[bend right=10](4.2,\y) node[right,yslant=0.15](\x){};
%
%    \foreach \z in {0.2,0.4,0.6,0.8}
%       \draw ($(-0.1,\z) + (0,\y)$)to[bend right=15]($(0.1,\z)+(0,\y)$);
%    };
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容