3

I am trying to create a cylinder like this

enter image description here

But I only have the cylinder. How how I do it? Thanks.

\documentclass[preview]{standalone}
\usepackage{tikz}
\begin{document}
\begin{figure}
    \centering
    \begin{tikzpicture}
\begin{scope}[x={(.7cm,-.3cm)}]
\path (1,0,0);
\pgfgetlastxy{\cylxx}{\cylxy}
\path (0,1,0);
\pgfgetlastxy{\cylyx}{\cylyy}
\path (0,0,1);
\pgfgetlastxy{\cylzx}{\cylzy}
\pgfmathsetmacro{\cylt}{(\cylzy * \cylyx - \cylzx * \cylyy)/ (\cylzy * \cylxx - \cylzx * \cylxy)}
\pgfmathsetmacro{\ang}{atan(\cylt)}
\pgfmathsetmacro{\ct}{1/sqrt(1 + (\cylt)^2)}
\pgfmathsetmacro{\st}{\cylt * \ct}
\fill[white] (\ct,\st,0) -- ++(0,0,-8) arc[start angle=\ang,delta angle=180,radius=1] -- ++(0,0,8) arc[start angle=\ang+180,delta angle=-180,radius=1];
\begin{scope}[every path/.style={ultra thick}]
\draw (0,0,0) circle[radius=1];

\draw (\ct,\st,0) -- ++(0,0,-8);
\draw (-\ct,-\st,0) -- ++(0,0,-8);
\draw (\ct,\st,-8) arc[start angle=\ang,delta angle=180,radius=1];
\draw[dashed] (\ct,\st,-4) arc[start angle=\ang,delta angle=-180,radius=1];
\draw (\ct,\st,-4) arc[start angle=\ang,delta angle=180,radius=1];
\draw[dashed] (\ct,\st,-8) arc[start angle=\ang,delta angle=-180,radius=1];
\end{scope}
\end{scope}
\end{tikzpicture}
    \caption{Composite Cylinder}
    \label{fig1}
\end{figure}
\end{document}
4
  • Hi, your MWE have some mistakes and it not compiles.
    – Sebastiano
    Nov 10 '20 at 15:34
  • 1
    @Sebastiano, to document class you need to add option preview, i.e.: \documentclass[preview]{standalone} :-)
    – Zarko
    Nov 10 '20 at 15:45
  • @Zarko I have not seen :-((((( Do you can improved the question? There is my name before. Thank you very much.....for your comment....now. :-)
    – Sebastiano
    Nov 10 '20 at 15:48
  • 1
    Hm, this should do OP ... I will correct this asap.
    – Zarko
    Nov 10 '20 at 15:49
4

Like this?

enter image description here

Image is redrawn from scratch. For cylinders are use use node shape cylinder their description is added as pin to nodes anchored to selected cylinder anchors:

\documentclass[margin=1pt, preview]{standalone}
\usepackage{tikz}
      \usetikzlibrary{calc,
                      quotes,
                      shapes.geometric}
\usepackage{siunitx}

\begin{document}
\begin{figure}
    \centering
    \begin{tikzpicture}[
C/.style = {cylinder, rotate=210, draw,
            cylinder uses custom fill,
            cylinder end fill=white, cylinder body fill=red,
            minimum height=30mm, minimum width=15mm, outer sep=0pt,
            aspect=2, anchor=bottom},
pin distance = 7mm, 
every pin edge/.style={shorten <=-2pt, <-}
                        ]
\node [C] (c1) {};
\draw[dashed]   (c1.before bottom)
            to[out=210, in=210, looseness=0.5]  
                (c1.after bottom);
\path (c1.center) node[pin=120:Steel] {};
\path ($(c1.before bottom)!0.5!(c1.after bottom)$) node[pin=30:{$T_1=10$}] {};
%
\node [C] (c2) at ($(c1.top)+(30:5mm)$) {};
\path (c2.center) node[pin=120:Aluminium] {};
\draw[dashed]   (c2.before bottom) 
            to[out=210, in=210, looseness=0.5]  
                (c2.after bottom);
\path ($(c2.before top)!0.5!(c2.after top)$) node[pin=210:{$T_1=1000$}] {};
% measures
\path[transform canvas={shift={(300:5mm)}}]
    (c1.before top) edge ["\SI{5}{in}", sloped] (c1.after bottom)
    (c2.before top) edge ["\SI{5}{in}", sloped] (c2.after bottom);
\end{tikzpicture}
    \caption{Composite Cylinder}
    \label{fig1}
\end{figure}
\end{document}
3
  • Yea like that! how would you add the dimensions?
    – Missael
    Nov 10 '20 at 19:16
  • @m, huh, I forgot on it. I will add them asap.
    – Zarko
    Nov 10 '20 at 19:33
  • Thank you for your help!
    – Missael
    Nov 10 '20 at 19:55

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.