tikz add tag
Anonymous 1123
I am trying draw this picture
![ScreenHunter 849.png](/image?hash=128191fc5a950862c6259bc510a4685722086bb961bc77f16a069edcf7d35b68)

I tried
```
\documentclass[border=1mm,tikz]{standalone} 
\usepackage{tikz-3dplot} 
\begin{document} 
\tdplotsetmaincoords{80}{70}
	\begin{tikzpicture}[tdplot_main_coords,declare function={h=4;R=3;r=2;}] 
	\path 
({R*cos(\tdplotmainphi)},{R*sin(\tdplotmainphi)},0 ) coordinate (bl)
	({R*cos(\tdplotmainphi + 180)},{R*sin(\tdplotmainphi + 180)},0 ) coordinate (br);
	\draw[dashed] (bl) arc[start angle=\tdplotmainphi,
	end angle=\tdplotmainphi+180,radius=R];
	\draw[thick] (br) arc[start angle=\tdplotmainphi + 180,
	end angle=\tdplotmainphi+360,radius=R];
	
	\path
	({R*cos(\tdplotmainphi)},{R*sin(\tdplotmainphi)},h ) coordinate (tl)
	({R*cos(\tdplotmainphi + 180)},{R*sin(\tdplotmainphi + 180)},h ) coordinate (tr);
	\draw[thick] (0,0,h) circle[radius = R];
	
	\draw[dashed] (0,0,0) coordinate (O) -- (0,0,h+2) coordinate (O'); 	
	\draw[dashed] (bl) -- (br);	
	\draw[thick]  (tl) -- (bl) (tr) -- (br) (tl) -- (tr) ;
	
\path 
({r*cos(\tdplotmainphi)},{r*sin(\tdplotmainphi)},h ) coordinate (bl2)
({r*cos(\tdplotmainphi + 180)},{r*sin(\tdplotmainphi + 180)},h ) coordinate (br2);
\draw[dashed] (bl2) arc[start angle=\tdplotmainphi,
end angle=\tdplotmainphi+180,radius=r];
\draw[thick] (br2) arc[start angle=\tdplotmainphi + 180,
end angle=\tdplotmainphi+360,radius=r];
1\path
({r*cos(\tdplotmainphi)},{r*sin(\tdplotmainphi)},h+2 ) coordinate (tl2)
({r*cos(\tdplotmainphi + 180)},{r*sin(\tdplotmainphi + 180)},h+2 ) coordinate (tr2);
\draw[thick] (0,0,h+2) circle[radius = r];

\draw[thick]  (tl2) -- (bl2) (tr2) -- (br2) (tl2) -- (tr2) ;

\end{tikzpicture}
\end{document}

```

![ScreenHunter 850.png](/image?hash=bf0052d1ef66f987f75f13a88db71c61ff941b42150b12ef22683ab60061ff12)
Top Answer
marmot
You already determined the critical angle for single cylinders. There is only one more critical angle which determines which fraction of the larger cylinder is covered by the smaller one. In the case at hand, this is just the `arcsin` of the ratio `r/R` plus some stuff that depends on the view angle `phi`. In more complicated settings you could work with clips and reverse clips, but here it is easier to work with the analytic solution.

```
\documentclass[border=1mm,tikz]{standalone} 
\usepackage{tikz-3dplot} 
\begin{document} 
\tdplotsetmaincoords{80}{70}
\begin{tikzpicture}[tdplot_main_coords,
	visible/.style={thick},hidden/.style={dashed},
	declare	function={H=4;h=2;R=3;r=2;phi1=\tdplotmainphi;
		phi2=\tdplotmainphi+180;phi3=\tdplotmainphi-180;
		phi4=\tdplotmainphi+90+asin(r/R);
		phi5=\tdplotmainphi+90-asin(r/R);
		}] 
 \path (0,0,H) coordinate(M) (0,0,H+h) coordinate(m)
	({R*cos(phi1)},{R*sin(phi1)},0 ) coordinate (BL)
	({R*cos(phi2)},{R*sin(phi2)},0 ) coordinate	(BR)
	({R*cos(phi1)},{R*sin(phi1)},H ) coordinate (TL)
	({R*cos(phi2)},{R*sin(phi2)},H ) coordinate	(TR)
	({r*cos(phi1)},{r*sin(phi1)},H ) coordinate (bl)
	({r*cos(phi2)},{r*sin(phi2)},H ) coordinate	(br)
	({r*cos(phi1)},{r*sin(phi1)},H+h) coordinate (tl)
	({r*cos(phi2)},{r*sin(phi2)},H+h) coordinate (tr);
  \begin{scope}[canvas is xy plane at z=0]
   \draw[hidden] (br) arc[start angle=phi3,end angle=phi2,radius=r]
    (BR) arc[start angle=phi3,end angle=phi2,radius=R]
	($(M)+(phi5:R)$) arc[start angle=phi5,end angle=phi4,radius=R];
   \draw[visible] (tr) -- (br) 
   	arc[start angle=phi3,end angle=phi1,radius=r] -- (tl)
	(m) circle[radius=r]
	(TR) -- (BR) arc[start angle=phi3,end angle=phi1,radius=R] -- (TL)
	($(M)+(phi5:R)$) arc[start angle=phi5,end angle=phi4-360,radius=R];
  \end{scope} 	
\end{tikzpicture}
\end{document}
```

![Screen Shot 2020-09-26 at 7.59.38 PM.png](/image?hash=37640f8a32ebbdb8805b6c2465258655add8c14c28789a47d05fead094500f0f)

You can iterate this in a loop. The heights and radii are stored in the lists `lH` and `lR`, respectively.

```
\documentclass[border=1mm,tikz]{standalone} 
\usepackage{tikz-3dplot} 
\begin{document} 
\tdplotsetmaincoords{80}{70}
\begin{tikzpicture}[tdplot_main_coords,
	visible/.style={thick},hidden/.style={dashed},
	declare	function={lH={4,2,1.5,1};% list of heights
	    lR={3,2,1.5,1};% list of radii
	    phi0=\tdplotmainphi+90;
		phihid(\r,\R)=asin(\r/\R);
		}] 
 \pgfmathtruncatemacro{\mydim}{dim(lH)-1}	
 \pgfmathsetmacro{\myh}{0}
 \path (0,0,\myh) coordinate (M0);
 \foreach \X [remember=\myh as \myh,count=\Y] in {0,...,\mydim}
 {\pgfmathsetmacro{\myh}{\myh+{lH}[\X]}
  \pgfmathsetmacro{\myr}{{lR}[\X]}
  \path (0,0,\myh) coordinate (M\Y);
  \begin{scope}[canvas is xy plane at z=0]
   \draw[hidden] ($(M\X)+(phi0+90:\myr)$) 
		arc[start angle=phi0+90,end angle=phi0-90,radius=\myr];
   \draw[visible] ($(M\Y)+(phi0-270:\myr)$)
	  -- ($(M\X)+(phi0-270:\myr)$)
	  arc[start angle=phi0-270,end angle=phi0-90,radius=\myr]
	  -- ($(M\Y)+(phi0-90:\myr)$);
   \ifnum\X=\mydim
    \draw[visible] (M\Y) circle[radius=\myr]; 
   \else
    \pgfmathsetmacro{\myphicrit}{phihid({lR}[\Y],\myr)}
	\draw[hidden] ($(M\Y)+(phi0-\myphicrit:\myr)$)
	  arc[start angle=phi0-\myphicrit,end angle=phi0+\myphicrit,radius=\myr];
	\draw[visible] 
	  ($(M\Y)+(phi0-\myphicrit:\myr)$)
	  arc[start angle=phi0-\myphicrit,end angle=phi0+\myphicrit-360,radius=\myr];
   \fi
  \end{scope}
 }
\end{tikzpicture}
\end{document}
```

![Screen Shot 2020-09-26 at 9.07.34 PM.png](/image?hash=da85348003e6898291d404c790e6ed1d65941b570a78db59dd35e8396736ec60)

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.