0

Is there a way to draw three hollow cylinders with finite thickness in TikZ? The result should look something like this:

Hollow cylinder with thickness

I already found the shape=cylinder option as in here or here. But I have no clue how to obtain the thickness and all that in "real" 3D

Edit:

Despite only asking for a hint to a specific shape or option, I'll try to please @cfr and add a MWE with no content

\documentclass[a4paper,10pt]{scrreprt}
\usepackage[T1]{fontenc}
% \usepackage[utf8]{inputenc}
\usepackage[latin1]{inputenc}
\usepackage{geometry}
\geometry{a4paper,left=25mm,right=25mm, top=25mm, bottom=25mm}
\usepackage{tikz}

\begin{document}
% There is absolutely no content here
\end{document}
  • 2
    Your question leaves all the effort to our community, even typing the essentials of a TeX document such as \documentclass{}...\begin{document} etc. As it is, most of our users will be very reluctant to touch your question, and you are left to the mercy of our procrastination team who are very few in number and very picky about selecting questions. You can improve your question by adding a minimal working example (MWE) that more users can copy/paste onto their systems to work on. If no hero takes the challenge we might have to close your question. – cfr Apr 9 '15 at 21:24
  • Seriously? Despite I am very greatful for @Harish Kumar's solution, I only asked for a hint to a TikZ option or a special shape or something like that, not a full MWE. Why do you think I added the links to the two other threads? But for the sake of your happiness I'll edit the answer. – raedma Apr 10 '15 at 7:23
2

You can use Qrrbrbirlbel's answer here. It looks real 3D to me.

\documentclass[tikz,border=4]{standalone}
\usetikzlibrary{calc,shapes.geometric}
\pgfmathparse{atan2(0,1)}
\ifdim\pgfmathresult pt=0pt % atan2(y, x)
  \tikzset{declare function={atanXY(\x,\y)=atan2(\y,\x);atanYX(\y,\x)=atan2(\y,\x);}}
\else                       % atan2(x, y)
  \tikzset{declare function={atanXY(\x,\y)=atan2(\x,\y);atanYX(\y,\x)=atan2(\x,\y);}}
\fi
\begin{document}
\begin{tikzpicture}[font=\sffamily\small,
   mycylinder/.style={draw, shape=cylinder, aspect=1.5, minimum height=+3cm,
    minimum width=+2cm, left color=blue!30, right color=blue!60, middle color=blue!10,
    shape border rotate=90, append after command={%
      let \p{cyl@center} = ($(\tikzlastnode.before top)!0.5! (\tikzlastnode.after top)$),
          \p{cyl@x}      = ($(\tikzlastnode.before top)-(\p{cyl@center})$),
          \p{cyl@y}      = ($(\tikzlastnode.top)       -(\p{cyl@center})$)
      in (\p{cyl@center}) edge[draw,double distance=1pt,double=gray!40!white, fill=blue!10, to path={
        ellipse [x radius=veclen(\p{cyl@x})-1\pgflinewidth,
                 y radius=veclen(\p{cyl@y})-1\pgflinewidth,
                 rotate=atanXY(\p{cyl@x})]}] () }}]
\node[thick,mycylinder] (a) at (0,0){};
\coordinate (b) at ($(a.after top)!0.5!(a.before top)$);
\coordinate (c) at ($(a.north)!2!(b)$);
\node[thick,mycylinder,anchor=south] at (c){};
\end{tikzpicture}
\end{document}

enter image description here

Adjusting minimum width, minimum height, aspect and adding third cylinder gives

\documentclass[tikz,border=4]{standalone}
\usetikzlibrary{calc,shapes.geometric}
\pgfmathparse{atan2(0,1)}
\ifdim\pgfmathresult pt=0pt % atan2(y, x)
  \tikzset{declare function={atanXY(\x,\y)=atan2(\y,\x);atanYX(\y,\x)=atan2(\y,\x);}}
\else                       % atan2(x, y)
  \tikzset{declare function={atanXY(\x,\y)=atan2(\x,\y);atanYX(\y,\x)=atan2(\x,\y);}}
\fi
\begin{document}
\begin{tikzpicture}[font=\sffamily\small,
   mycylinder/.style={draw, shape=cylinder, aspect=1, minimum height=+2cm,
    minimum width=+3cm, left color=blue!30, right color=blue!60, middle color=blue!10,
    shape border rotate=90, append after command={%
      let \p{cyl@center} = ($(\tikzlastnode.before top)!0.5! (\tikzlastnode.after top)$),
          \p{cyl@x}      = ($(\tikzlastnode.before top)-(\p{cyl@center})$),
          \p{cyl@y}      = ($(\tikzlastnode.top)       -(\p{cyl@center})$)
      in (\p{cyl@center}) edge[draw,double distance=1pt,double=gray!40!white, fill=blue!10, to path={
        ellipse [x radius=veclen(\p{cyl@x})-1\pgflinewidth,
                 y radius=veclen(\p{cyl@y})-1\pgflinewidth,
                 rotate=atanXY(\p{cyl@x})]}] () }}]
\node[thick,mycylinder] (a) at (0,0){};
\coordinate (b) at ($(a.after top)!0.5!(a.before top)$);
\coordinate (c) at ($(a.north)!2!(b)$);
\node[thick,mycylinder,anchor=south] (d) at (c){};
\coordinate (bb) at ($(d.after top)!0.5!(d.before top)$);
\coordinate (cc) at ($(d.north)!2!(bb)$);
\node[thick,mycylinder,anchor=south] (e) at (cc){};
\end{tikzpicture}
\end{document}

enter image description here

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.