5

can someone provide me with some code, or insights, into how to create a diagram of a shaded cylinder within a cylinder? any typesetting system will do (please specify which one, though).

is it also possible to label the regions? like, with letters (cylinder C, smaller cylinder P, lengthwise T, etc)? any answers or references to existing answers would be much appreciated. thank you!

Torbjørn T.
  • 206,688
Gordon
  • 53

1 Answers1

5

If I understand you correctly, following code may be help you.

\documentclass{standalone}
\usepackage{tikz} 
\usetikzlibrary{calc} 

\tikzset{
  dim above/.style={to path={\pgfextra{
        \pgfinterruptpath
        \draw[>=latex,|<->|] let
        \p1=($(\tikztostart)!2mm!90:(\tikztotarget)$),
        \p2=($(\tikztotarget)!2mm!-90:(\tikztostart)$)
        in(\p1) -- (\p2) node[pos=.5,sloped,above]{#1};
        \endpgfinterruptpath
      }(\tikztostart) -- (\tikztotarget) \tikztonodes
    }
  },
  dim below/.style={to path={\pgfextra{
        \pgfinterruptpath
        \draw[>=latex,|<->|] let 
        \p1=($(\tikztostart)!2mm!90:(\tikztotarget)$),
        \p2=($(\tikztotarget)!2mm!-90:(\tikztostart)$)
        in (\p1) -- (\p2) node[pos=.5,sloped,below]{#1};
        \endpgfinterruptpath
      }(\tikztostart) -- (\tikztotarget) \tikztonodes
    }
  },
}   

\begin{document}
  \begin{tikzpicture}

\draw[thick,-latex] (0,0,0) -- (4,0,0) node[anchor=north east]{$y$};
\draw[thick,-latex] (0,0,0) -- (0,7.5,0) node[anchor=north west]{$z$};
\draw[thick,-latex] (0,0,0) -- (0,0,5) node[anchor=south east]{$x$};

\fill[top color=gray!50!black,bottom color=blue!10,middle color=gray,shading=axis,opacity=0.25] (0,0) circle (2cm and 0.5cm);
\fill[left color=gray!50!black,right color=blue!50!black,middle color=gray!50,shading=axis,opacity=0.25] (2,0) -- (2,4) arc (360:180:2cm and 0.5cm) -- (-2,0) arc (180:360:2cm and 0.5cm);
\fill[top color=blue!90!,bottom color=blue!2,middle color=blue!30,shading=axis,opacity=0.25] (0,4) circle (2cm and 0.5cm);
\draw (-2,4) -- (-2,0) arc (180:360:2cm and 0.5cm) -- (2,4) ++ (-2,0) circle (2cm and 0.5cm);
\draw[densely dashed] (-2,0) arc (180:0:2cm and 0.5cm);

\fill[top color=gray!50!black,bottom color=orange!10,middle color=gray,shading=axis,opacity=0.5] (0,0) circle (1.5cm and 0.25cm);
\fill[left color=gray!50!black,right color=orange!50!black,middle color=gray!50,shading=axis,opacity=0.25] (2,0) -- (2,4) arc (360:180:2cm and 0.5cm) -- (-2,0) arc (180:360:2cm and 0.5cm);
\fill[top color=blue!90!,bottom color=orange!2,middle color=orange!30,shading=axis,opacity=0.25] (0,4) circle (1.5cm and 0.25cm);
\draw (-1.5,4) -- (-1.5,0) arc (180:360:1.5cm and 0.25cm) -- (1.5,4) ++ (-1.5,0) circle (1.5cm and 0.25cm);
\draw[densely dashed] (-1.5,0) arc (180:0:1.5cm and 0.25cm);

\draw (-2,0) to[dim above=$T$,color=orange] (-2,4) ;
\node at (-1.75,4) {$C$};
\node at (-0.75,4) {$P$};
\end{tikzpicture}  
\end{document}

enter image description here