在 3D 环境中绘制圆柱体内的圆柱束

在 3D 环境中绘制圆柱体内的圆柱束

我一直试图在 TikZ 中绘制下图:

在此处输入图片描述

到目前为止,在提出的问题的帮助下,我取得了哪些成就在三维平面中绘制圆柱体这是:

\documentclass[border=10pt,tikz]{standalone}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}
\draw [fill=gray, fill opacity=.25]
(180:2.5mm) coordinate (a)
 -- ++(0,-12.5mm) coordinate (b)
 arc (180:360:2.5mm and 0.875mm) coordinate (d)
 -- (a -| d) coordinate (c) arc (0:180:2.5mm and 0.875mm);
 \draw [fill=gray, fill opacity=.25]
 (0,0) coordinate (t) circle (2.5mm and 0.875mm);
 \draw []
 (180:7.5mm) coordinate (A)
 -- ++(0,-12.5mm) coordinate (B) node [midway, right, inner sep=1pt] {}
 arc (180:360:7.5mm and 2.625mm) coordinate (D)
 -- (A -| D) coordinate (C) arc (0:180:7.5mm and 2.625mm);
 \draw []
 (0,0) coordinate (T) circle (7.5mm and 2.625mm);
 \end{tikzpicture}
 \end{document}

我不明白如何(1)排列多个气缸和(2)隐藏主气缸后面的气缸部分,从而得到所示的图形。

答案1

欢迎!您可以安装正交视图,然后按适当的顺序添加这些东西。对于重复的东西,小圆柱体pic很有用。

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{perspective,3d,patterns.meta}
\begin{document}
\makeatletter
\tikzset{pics/3d cylinder z/.style={code={%
            \tikzset{3d/cylinder/.cd,#1}%
            \def\pv##1{\pgfkeysvalueof{/tikz/3d/cylinder/##1}}%
            \edef\mylocalaz{\pgf@view@az}%
            \draw[/tikz/3d/cylinder/mantle,pic actions] %[left color=gray!90,right color=gray!60,middle color=gray!20] 
            plot[domain=\pgf@view@az:\pgf@view@az-180,variable=\t,smooth]
            ({\pv{r}*cos(\t)},
            {\pv{r}*sin(\t)},0)
            -- 
            plot[domain=\mylocalaz-180:\mylocalaz,variable=\t,smooth]
            ({\pv{r}*cos(\t)},
            {\pv{r}*sin(\t)},
            \pv{h}) 
            -- cycle;
            \draw[/tikz/3d/cylinder/top,pic actions] %[fill=gray!30] 
            plot[domain=0:360,variable=\t,smooth cycle]
            ({\pv{r}*cos(\t)},
            {\pv{r}*sin(\t)},
            \pv{h}); 
            \pgfkeys{/tikz/3d/cylinder/extra}
    }},
    3d/.cd,cylinder/.cd,r/.initial=0.3,h/.initial=4,extra/.code={},
    top/.style={fill=white,postaction={pattern={Lines[angle=-45,distance={3pt}]}}},
    mantle/.style={fill=white}}
\makeatother    
\begin{tikzpicture}[line cap=round,line join=round,declare function={az=0;R=1.6;}]
 \begin{scope}[3d view={az}{35}]
  \draw plot[smooth,variable=\t,domain=00:180]
   ({R*cos(\t+az)},{R*sin(\t+az)},4);
  \path foreach \Y in {1,2,3,4}
  { foreach \X in {1,-1}
   {({cos(\Y*\X*45-\X*45/2+az+90)},{sin(\Y*\X*45-\X*45/2+az+90)},0)
    pic{3d cylinder z}}
    \ifnum\Y=2
     (0,0,0) pic{3d cylinder z}
    \fi
    };
  \draw[fill=white] plot[smooth,variable=\t,domain=00:-180]
   ({R*cos(\t+az)},{R*sin(\t+az)},4) --
   plot[smooth,variable=\t,domain=-180:00]
   ({R*cos(\t+az)},{R*sin(\t+az)},0) -- cycle;
 \end{scope}
\end{tikzpicture}   
\end{document}

在此处输入图片描述

可以将仰角改变为任何合理的正值,任意改变方位角,并可以引入旋转小圆柱体的旋转角。

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{perspective,3d,patterns.meta}
\begin{document}
\makeatletter
\tikzset{pics/3d cylinder z/.style={code={%
            \tikzset{3d/cylinder/.cd,#1}%
            \def\pv##1{\pgfkeysvalueof{/tikz/3d/cylinder/##1}}%
            \edef\mylocalaz{\pgf@view@az}%
            \draw[/tikz/3d/cylinder/mantle,pic actions] %[left color=gray!90,right color=gray!60,middle color=gray!20] 
            plot[domain=\pgf@view@az:\pgf@view@az-180,variable=\t,smooth]
            ({\pv{r}*cos(\t)},
            {\pv{r}*sin(\t)},0)
            -- 
            plot[domain=\mylocalaz-180:\mylocalaz,variable=\t,smooth]
            ({\pv{r}*cos(\t)},
            {\pv{r}*sin(\t)},
            \pv{h}) 
            -- cycle;
            \draw[/tikz/3d/cylinder/top,pic actions] %[fill=gray!30] 
            plot[domain=0:360,variable=\t,smooth cycle]
            ({\pv{r}*cos(\t)},
            {\pv{r}*sin(\t)},
            \pv{h}); 
            \pgfkeys{/tikz/3d/cylinder/extra}
    }},
    3d/.cd,cylinder/.cd,r/.initial=0.3,h/.initial=4,extra/.code={},
    top/.style={fill=white,postaction={pattern={Lines[angle=-45,distance={3pt}]}}},
    mantle/.style={fill=white}}
\makeatother    
\foreach \Rotation in {2.5,5,...,45}
{\begin{tikzpicture}[line cap=round,line join=round,
    declare function={az=0;R=1.6;rot=\Rotation;}]
 \begin{scope}[3d view={az}{35}]
  \draw plot[smooth,variable=\t,domain=00:180]
   ({R*cos(\t+az)},{R*sin(\t+az)},4);
  \path foreach \Y in {1,2,3,4}
  { foreach \X in {1,-1}
   {({cos(\Y*\X*45-\X*45/2+az+90+Mod(rot+45/2,45)-45)},
   {sin(\Y*\X*45-\X*45/2+az+90+Mod(rot+45/2,45)-45)},0)
    pic{3d cylinder z}}
    \ifnum\Y=2
     (0,0,0) pic{3d cylinder z}
    \fi
    };
  \draw[fill=white] plot[smooth,variable=\t,domain=00:-180]
   ({R*cos(\t+az)},{R*sin(\t+az)},4) --
   plot[smooth,variable=\t,domain=-180:00]
   ({R*cos(\t+az)},{R*sin(\t+az)},0) -- cycle;
 \end{scope}
\end{tikzpicture}}   
\end{document}

在此处输入图片描述

相关内容