使用 tikz 绘制 2 个圆柱体

使用 tikz 绘制 2 个圆柱体

我不太擅长使用 tikz。我想画一些类似的东西

在此处输入图片描述

到目前为止,通过查看我在网上找到的一些类似的解决方案,我可以做到这一点

在此处输入图片描述

使用以下代码

    \begin{figure}
\centering
\begin{tikzpicture}
\coordinate(C2) at (0,0,0);
  \node[cylinder,draw=black,thick,aspect=0.7,minimum height=5cm,minimum     width=2cm,shape border rotate=0] (A) at ($(C2)-(0,0,0)$) {A};

\draw[dashed]
    let \p1 = ($ (A.after bottom) - (A.before bottom) $),
        \n1 = {0.5*veclen(\x1,\y1)-\pgflinewidth},
        \p2 = ($ (A.bottom) - (A.after bottom)!0.5!(A.before bottom) $),
        \n2 = {veclen(\x2,\y2)-\pgflinewidth}
  in
    ([xshift=-\pgflinewidth] A.before bottom) arc [start angle=270, delta angle=180,
    x radius=\n2, y radius=\n1];
    \draw [<->] (A.before top) -- (A.after top) node [midway, above,fill=white] {$2a$};
    
    
\coordinate(C3) at (0,0);
\node [cylinder,draw=black,thick,aspect=0.7,minimum height=5cm,minimum     width=2cm,shape border rotate=0] (B) at ($(C3)-(+2.7,0,7)$){3};
\draw[dashed]
    let \p1 = ($ (B.after bottom) - (B.before bottom) $),
        \n1 = {0.5*veclen(\x1,\y1)-\pgflinewidth},
        \p2 = ($ (B.bottom) - (B.after bottom)!0.5!(B.before bottom) $),
        \n2 = {veclen(\x2,\y2)-\pgflinewidth}
  in
    ([xshift=-\pgflinewidth] B.before bottom) arc [start angle=270, delta angle=180,
    x radius=\n2, y radius=\n1];
    \draw [<->] (B.before top) -- (B.after top) node [midway, above,fill=white] {$2a$};
    
   \draw[dashed](-3,0)to(3,0);
   %  \draw[dashed](7,0)to(9,0);
   % \draw(0,-0.5)to(0,-1);
    % \draw(7,-0.5)to(7,-1);
     %\draw(0,-0.75)to(2,-0.75);
    % \draw(7,-0.75)to(5,-0.75);
    % \draw[dotted](2,-0.75)to(3.5,-0.75)node[above]{$\ell$}to(5,-0.75);
    
\end{tikzpicture}
\end{figure}

我需要说明的是,我“手动”将一个圆柱体放在另一个圆柱体上,但我真的不确定我是否知道它们是如何移动的。我如何才能清楚地定义这两个圆柱体的相对位置?有人知道如何添加垂直线“h”和水平线“z”吗?

答案1

您只需绘制直线和椭圆(或圆弧)。您还可以将圆柱体包含在循环中,\foreach这样您只需绘制一个。

像这样:

\documentclass[border=2mm]{standalone}    
\usepackage    {tikz}

\begin{document}
\begin{tikzpicture}[line cap=round,line join=round]
  % dimensions
  \def\a{1}
  \def\h{4}
  \def\z{3}
  % cylinders 
  \foreach\i in {0,\h} % we draw the same figure at heights 0 and \h
  {%
    \draw[red] (-0.5*\z,\i) -- (-0.5*\a,\i);   % axis
    \draw[red,dashed] (-0.5*\a,\i) -- (\z,\i); % axis
    \draw (\z,\i+\a) -- (0,\i+\a) arc (90:270:0.5*\a cm and \a cm) -- (\z,\i-\a) ;
    \draw[dashed] (0,\i-\a) arc (-90:90:0.5*\a cm and \a cm);
    \draw (\z,\i) ellipse (0.5*\a cm and \a cm);
    \draw[red] (\z,\i) -- (1.5*\z,\i); % axis
    \fill[red] (0,\i)  circle (1pt);
    \fill[red] (\z,\i) circle (1pt);
  }
  % auxiliary lines and labels
  \draw[blue,dashed] (\z+0.2,\h+\a)   -- (1.5*\z,\h+\a);
  \draw[blue,dashed] (\z+0.2,-\a)     -- (1.5*\z,-\a);
  \draw[blue,dashed] (0,-\a-0.1)      -- (0,-2*\a)          node [below]        {$z=0$};
  \draw[blue,dashed] (\z,-\a-0.1)     -- (\z,-2*\a)         node [below]        {$z=\ell$};;
  \draw[blue,<->]    (0,-2*\a+0.1)    -- (\z,-2*\a+0.1)     node [midway,below] {$z$};
  \draw[blue,<->]    (1.5*\z-0.1,-\a) -- (1.5*\z-0.1,0)     node [midway,right] {$a$}; 
  \draw[blue,<->]    (1.5*\z-0.1,0)   -- (1.5*\z-0.1,\h)    node [midway,right] {$h$}; 
  \draw[blue,<->]    (1.5*\z-0.1,\h)  -- (1.5*\z-0.1,\h+\a) node [midway,right] {$a$}; 
\end{tikzpicture}  
\end{document}

将产生: 在此处输入图片描述

相关内容