2

I see question at here creating a small cylinder within a larger cylinder to creat a hole in cylinders. I tried

\documentclass[border=1mm,12pt,tikz]{standalone}
\usepackage{tikz-3dplot} 
\usetikzlibrary{3d,calc,backgrounds,patterns}
\usepackage{fouriernc}
\begin{document}
    \def\myr{1.5}
    \def\myR{3}
    \def\h{5}

\tdplotsetmaincoords{70}{80}
    \begin{tikzpicture}[tdplot_main_coords,scale=1,line cap=butt,line join=round]

    \begin{scope}[canvas is xy plane at z=0]
    \coordinate (A) at (\tdplotmainphi:\myr);
    \coordinate (B) at (\tdplotmainphi+180:\myr);
    \coordinate (C) at (\tdplotmainphi:\myR);
    \coordinate (D) at (\tdplotmainphi+180:\myR);
%\draw circle [radius=\myR];
\draw[dashed] circle [radius=\myr];
\draw[dashed] (\tdplotmainphi:\myR) arc(\tdplotmainphi:\tdplotmainphi+180:\myR);
    \draw[thick] (\tdplotmainphi:\myR)  arc(\tdplotmainphi:\tdplotmainphi-180:\myR);    
    \end{scope}
    %
\begin{scope}[canvas is xy plane at z=\h]
\draw[thick] circle [radius=\myr];
\draw[thick] circle [radius=\myR];
    \coordinate (A') at (\tdplotmainphi:\myr);
\coordinate (B') at (\tdplotmainphi+180:\myr);
\coordinate (C') at (\tdplotmainphi:\myR);
\coordinate (D') at (\tdplotmainphi+180:\myR);
\end{scope}
    \foreach \X in {A,B} \draw[dashed] (\X) -- (\X');
    \foreach \X in {C,D} \draw[thick] (\X) -- (\X');
    \end{tikzpicture}
    \end{document} 

enter image description here

I cann't fill two cylinders to create holes in cylinders. How can I fill it?

Can I get like this picture?

enter image description here enter image description here

6

Something like this?

\documentclass[border=1mm,12pt,tikz]{standalone}
\usepackage{tikz-3dplot} 
\begin{document}
\def\myr{1.5}
\def\myR{3}
\def\h{5}

\tdplotsetmaincoords{70}{80}
\begin{tikzpicture}[tdplot_main_coords,scale=1,line cap=butt,line join=round]
 \draw[dashed] ({\myr*cos(\tdplotmainphi)},{\myr*sin(\tdplotmainphi)},0) 
  -- ({\myr*cos(\tdplotmainphi)},{\myr*sin(\tdplotmainphi)},\h)
  ({\myr*cos(\tdplotmainphi+180)},{\myr*sin(\tdplotmainphi+180)},0) 
  -- ({\myr*cos(\tdplotmainphi+180)},{\myr*sin(\tdplotmainphi+180)},\h)
  plot[smooth,variable=\t,domain=0:360] ({\myr*cos(\t)},{\myr*sin(\t)},0)
  plot[smooth,variable=\t,domain=\tdplotmainphi:\tdplotmainphi+180] ({\myR*cos(\t)},{\myR*sin(\t)},0);
 \draw plot[smooth,variable=\t,domain=\tdplotmainphi:\tdplotmainphi+180]
  ({\myR*cos(\t)},{\myR*sin(\t)},\h);
 \draw[left color=gray!80,right color=gray!50,middle color=gray!30,fill
  opacity=0.6] plot[smooth,variable=\t,domain=\tdplotmainphi:\tdplotmainphi-180]
  ({\myR*cos(\t)},{\myR*sin(\t)},\h)
  -- plot[smooth,variable=\t,domain=\tdplotmainphi-180:\tdplotmainphi]
  ({\myR*cos(\t)},{\myR*sin(\t)},0) -- cycle;
 \draw[left color=gray!50,right color=gray!80,middle color=gray!70,fill
  opacity=0.5] plot[smooth,variable=\t,domain=0:360] ({\myR*cos(\t)},{\myR*sin(\t)},\h);
 \clip   plot[smooth,variable=\t,domain=0:360]
  ({\myR*cos(\t)},{\myR*sin(\t)},\h);
 \draw[left color=gray!80,right color=gray!50,middle color=gray!30]
  plot[smooth,variable=\t,domain=\tdplotmainphi:\tdplotmainphi-180] 
  ({\myr*cos(\t)},{\myr*sin(\t)},\h)
  -- plot[smooth,variable=\t,domain=\tdplotmainphi-180:\tdplotmainphi]
  ({\myr*cos(\t)},{\myr*sin(\t)},0) -- cycle;
 \draw[left color=gray!30,right color=gray!50,middle color=gray!80] plot[smooth,variable=\t,domain=0:360] ({\myr*cos(\t)},{\myr*sin(\t)},\h); 
\end{tikzpicture}
\end{document} 

enter image description here

Or

\documentclass[border=1mm,12pt,tikz]{standalone}
\usepackage{tikz-3dplot} 
\begin{document}
\def\myr{1.5}
\def\myR{3}
\def\h{5}

\tdplotsetmaincoords{70}{80}
\begin{tikzpicture}[tdplot_main_coords,scale=1,line cap=butt,line join=round]
 \path[fill=gray!40,even odd rule]
  plot[smooth,variable=\t,domain=0:360] ({\myr*cos(\t)},{\myr*sin(\t)},0)
  plot[smooth,variable=\t,domain=0:360] ({\myR*cos(\t)},{\myR*sin(\t)},0);
 \draw[dashed] ({\myr*cos(\tdplotmainphi)},{\myr*sin(\tdplotmainphi)},0) 
  -- ({\myr*cos(\tdplotmainphi)},{\myr*sin(\tdplotmainphi)},\h)
  ({\myr*cos(\tdplotmainphi+180)},{\myr*sin(\tdplotmainphi+180)},0) 
  -- ({\myr*cos(\tdplotmainphi+180)},{\myr*sin(\tdplotmainphi+180)},\h)
  plot[smooth,variable=\t,domain=\tdplotmainphi:\tdplotmainphi+180] ({\myR*cos(\t)},{\myR*sin(\t)},0);
 \draw[dashed,fill=gray!20] plot[smooth,variable=\t,domain=0:360]
 ({\myr*cos(\t)},{\myr*sin(\t)},0);
 \draw plot[smooth,variable=\t,domain=\tdplotmainphi:\tdplotmainphi+180]
  ({\myR*cos(\t)},{\myR*sin(\t)},\h);
 \draw[left color=gray!80,right color=gray!50,middle color=gray!20,fill
  opacity=0.6] plot[smooth,variable=\t,domain=\tdplotmainphi:\tdplotmainphi-180]
  ({\myR*cos(\t)},{\myR*sin(\t)},\h)
  -- plot[smooth,variable=\t,domain=\tdplotmainphi-180:\tdplotmainphi]
  ({\myR*cos(\t)},{\myR*sin(\t)},0) -- cycle;
 \draw[fill=gray!90,fill opacity=0.6] plot[smooth,variable=\t,domain=0:360] ({\myR*cos(\t)},{\myR*sin(\t)},\h);
 \draw[left color=gray!30,right color=gray!50,middle color=gray!20] plot[smooth,variable=\t,domain=0:360] ({\myr*cos(\t)},{\myr*sin(\t)},\h); 
\end{tikzpicture}
\end{document} 

enter image description here

As is well known, such cylinders are used by koalas for parachuting. The koala is taken from here. The following code has some annotations and allows us to have something inside the cylinder.

\documentclass[border=1mm,12pt,tikz]{standalone}
\usepackage{tikz-3dplot} 
\usepackage{tikzlings}
\usetikzlibrary{decorations.markings}
\newsavebox\Koala
\sbox\Koala{\tikz[scale=0.2]{
\begin{scope}[local bounding box=koala]
\koala
\end{scope}
\foreach \X in {135,120,...,45}
{\draw (koala.\X) -- ++ (\X:1);}
\shade[ball color=blue,opacity=0.4] ($(koala.45)+(45:1)$) to[bend right=35] ($(koala.135)+(135:1)$)
to[out=90,in=90,looseness=2] cycle;}}
\begin{document}
\def\myr{1.5}
\def\myR{3}
\def\h{5}
\tdplotsetmaincoords{70}{80}
\foreach \n in {0,1,...,20}
{\begin{tikzpicture}[tdplot_main_coords,scale=1,line cap=butt,line join=round]
 \path[tdplot_screen_coords,use as bounding box] (-1.1*\myR,-0.4*\myR) rectangle
 (1.1*\myR,0.4*\myR+\h);
 % lower ring
 \path[fill=gray!40,even odd rule]
  plot[smooth,variable=\t,domain=0:360] ({\myr*cos(\t)},{\myr*sin(\t)},0)
  plot[smooth,variable=\t,domain=0:360] ({\myR*cos(\t)},{\myR*sin(\t)},0);
 % dashed inner contours 
 \draw[dashed] ({\myr*cos(\tdplotmainphi)},{\myr*sin(\tdplotmainphi)},0) 
  -- ({\myr*cos(\tdplotmainphi)},{\myr*sin(\tdplotmainphi)},\h)
  ({\myr*cos(\tdplotmainphi+180)},{\myr*sin(\tdplotmainphi+180)},0) 
  -- ({\myr*cos(\tdplotmainphi+180)},{\myr*sin(\tdplotmainphi+180)},\h)
  plot[smooth,variable=\t,domain=\tdplotmainphi:\tdplotmainphi+180] ({\myR*cos(\t)},{\myR*sin(\t)},0);
 % lower inner circle
 \draw[dashed,fill=gray!20] plot[smooth,variable=\t,domain=0:360]
 ({\myr*cos(\t)},{\myr*sin(\t)},0);
 % upper outer contour in the back
 \draw plot[smooth,variable=\t,domain=\tdplotmainphi:\tdplotmainphi+180]
  ({\myR*cos(\t)},{\myR*sin(\t)},\h);
 % upper hole 
 \draw[left color=gray!30,right color=gray!50,middle color=gray!20] plot[smooth,variable=\t,domain=0:360] ({\myr*cos(\t)},{\myr*sin(\t)},\h); 
 % upper ring in the back 
 \draw[fill=gray!90,fill opacity=0.6,even odd rule] 
  plot[smooth,variable=\t,domain=\tdplotmainphi:\tdplotmainphi+180] 
  ({\myR*cos(\t)},{\myR*sin(\t)},\h)  
  plot[smooth,variable=\t,domain=\tdplotmainphi+180:\tdplotmainphi] 
  ({\myr*cos(\t)},{\myr*sin(\t)},\h);
 % koala
 \path[postaction=decorate,decoration={markings,mark=at position
        \n/20 with {\node[rotate={30*sin(\n*36)}]{\usebox\Koala};}}] 
        plot[variable=\x,domain=0:720,samples=72] 
        ({0.2*sin(\x)},0,{1.2*\h-\h*\n/20});
 %  upper ring in the front      
 \draw[fill=gray!90,fill opacity=0.6,even odd rule] 
 plot[smooth,variable=\t,domain=\tdplotmainphi:\tdplotmainphi-180] 
 ({\myR*cos(\t)},{\myR*sin(\t)},\h)  
 plot[smooth,variable=\t,domain=\tdplotmainphi-180:\tdplotmainphi] 
 ({\myr*cos(\t)},{\myr*sin(\t)},\h);
 % front
 \draw[left color=gray!80,right color=gray!50,middle color=gray!20,fill
  opacity=0.6] plot[smooth,variable=\t,domain=\tdplotmainphi:\tdplotmainphi-180]
  ({\myR*cos(\t)},{\myR*sin(\t)},\h)
  -- plot[smooth,variable=\t,domain=\tdplotmainphi-180:\tdplotmainphi]
  ({\myR*cos(\t)},{\myR*sin(\t)},0) -- cycle;
\end{tikzpicture}}
\end{document} 

enter image description here

  • No. I don't want to fill inside of small cylinder. – Thuy Nguyen Sep 16 at 9:05
  • @ThuyNguyen Better now? – Schrödinger's cat Sep 16 at 9:10
  • @ThuyNguyen Sorry, I do not understand the request. – Schrödinger's cat Sep 16 at 9:28
  • Amazing answer. One more refinement would be perfect: the small circle at the bottom may need lighter shade than its surrounding ring. – Diaa Sep 16 at 10:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.