我如何使用 TikZ 绘制这个圆柱体?

我如何使用 TikZ 绘制这个圆柱体?

我正在尝试画这个。如果有人能帮我画这个,我将不胜感激。在此处输入图片描述

答案1

我把 设为\Angle角度phi,并考虑\Angle从 0 到 180 和\Angle从 180 到 360 的两种情况。例如,\Angle = 70

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{3dtools,calc}%https://github.com/marmotghost/tikz-3dtools
\begin{document}
    \foreach \Angle in {70}
    {\begin{tikzpicture}[3d/install view={phi=\Angle,theta=70},line cap=round,line join=round,c/.style={circle,fill,inner sep=1pt},
            declare function={R=2;h=4;}]     
        \path[save named path=cyl] pic{3d/frustum={R=R,r=R,h=h}};
\draw[3d/hidden] plot[smooth,domain=180-\Angle+\pgfkeysvalueof{/tikz/3d/phi}:\Angle] ({R*cos(\x)},{R*sin(\x)},{R*sin(\x)});
\draw[3d/visible] plot[smooth,domain=\pgfkeysvalueof{/tikz/3d/phi}:0] ({R*cos(\x)},{R*sin(\x)},{R*sin(\x)});        
    \draw[3d/hidden] (0:R)  -- (180:R);
\end{tikzpicture}}
\end{document}

在此处输入图片描述

你可以这样使用

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{3dtools,calc}%https://github.com/marmotghost/tikz-3dtools
\begin{document}
    \foreach \Angle in {5,10,...,175}
    {\begin{tikzpicture}[3d/install view={phi=\Angle,theta=70},line cap=round,line join=round,c/.style={circle,fill,inner sep=1pt},
            declare function={R=2;h=4;}]     
        \path[save named path=cyl] pic{3d/frustum={R=R,r=R,h=h}};
\draw[3d/hidden] plot[smooth,domain=180-\Angle+\pgfkeysvalueof{/tikz/3d/phi}:\Angle] ({R*cos(\x)},{R*sin(\x)},{R*sin(\x)});
\draw[3d/visible] plot[smooth,domain=\pgfkeysvalueof{/tikz/3d/phi}:0] ({R*cos(\x)},{R*sin(\x)},{R*sin(\x)});        
    \draw[3d/hidden] (0:R)  -- (180:R);
\end{tikzpicture}}
\end{document}

在此处输入图片描述

使用\Angle = 300我的代码

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{3dtools,calc}%https://github.com/marmotghost/tikz-3dtools
\begin{document}
\foreach \Angle in {300}
{\begin{tikzpicture}[3d/install view={phi=\Angle,theta=70},line cap=round,line join=round,c/.style={circle,fill,inner sep=1pt},
        declare function={R=2;h=4;}]     
        \path[save named path=cyl] pic{3d/frustum={R=R,r=R,h=h}};
        \draw[3d/hidden] plot[smooth,domain=0:\Angle-180] ({R*cos(\x)},{R*sin(\x)},{R*sin(\x)});
        \draw[3d/visible] plot[smooth,domain=\Angle-180:180] ({R*cos(\x)},{R*sin(\x)},{R*sin(\x)}); 
        \draw[3d/hidden] (0:R)  -- (180:R);
\end{tikzpicture}}
\end{document}

在此处输入图片描述

或者你可以使用

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{3dtools,calc}%https://github.com/marmotghost/tikz-3dtools
\begin{document}
\foreach \Angle in {185,190,...,355}
{\begin{tikzpicture}[3d/install view={phi=\Angle,theta=70},line cap=round,line join=round,c/.style={circle,fill,inner sep=1pt},
        declare function={R=2;h=4;}]     
        \path[save named path=cyl] pic{3d/frustum={R=R,r=R,h=h}};
        \draw[3d/hidden] plot[smooth,domain=0:\Angle-180] ({R*cos(\x)},{R*sin(\x)},{R*sin(\x)});
        \draw[3d/visible] plot[smooth,domain=\Angle-180:180] ({R*cos(\x)},{R*sin(\x)},{R*sin(\x)}); 
        \draw[3d/hidden] (0:R)  -- (180:R);
\end{tikzpicture}}
\end{document}

在此处输入图片描述

相关内容