# How can I draw this cylinder with TikZ?

I'm trying to draw this. I would appreciate it if someone would help me to draw this.

• You can see here Commented Aug 1, 2021 at 4:33
• Or here Commented Aug 1, 2021 at 7:37

I put \Angle as the angle of phi, and I consider two cases \Angle from 0 to 180, and \Angle from 180 to 360. For example, with \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}


You can use like that

\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}


With \Angle = 300, my code

\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}


Or you can use

\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}


• Thank you. It worked out fine!!!
– user248344
Commented Aug 2, 2021 at 14:21
• Can you accept the answer? Commented Sep 26, 2021 at 12:22