6

I am trying draw this cylinder. enter image description here

I used tkz-euclide. My code

\documentclass[border=2mm,12pt]{standalone}
\usepackage{fouriernc}
\usepackage{tikz}
\usepackage{tkz-euclide}
\usetkzobj{all}
\usetikzlibrary{shadings}
\begin{document}
\begin{tikzpicture}
\def\R{2}
\def\a{0.5}
\def\h{2*\R}
(\R,0) -- (\R,\h)  arc (360:180:\R cm and \a cm)
          -- (-\R,0) arc (180:360:\R cm and \a cm);

(0,\h) circle (\R cm and \a cm);
  \draw[thick] (-\R,\h) -- (-\R,0) arc (180:360:\R cm and \a cm)-- (\R,\h) ++ (-\R,0) circle (\R cm and \a cm);
  \draw[dashed] (-\R,0) arc (180:0:\R cm and \a cm);
\coordinate (O) at (0,0);
\coordinate (O') at ($(O)+(0,\h)$);
\coordinate (A) at (\R,0);
\coordinate (B) at ($(O) + (-70:{\R} and {\a})$);
\coordinate (A') at ($(A)+(0,\h)$);
\coordinate (B') at ($(B)+(0,\h)$);
\tkzFillPolygon[pattern=north west lines](A,B,B',A')
\tkzDrawPoints[fill = black,size = 5 pt](A,B,O,O',A',B')
\tkzLabelPoints[right](A,A')
\tkzLabelPoints[below](B)
\tkzLabelPoints[above](B')
\tkzLabelPoints[left](O,O')
\tkzDrawSegments[dashed](A,B  O,O')
\tkzDrawSegments[thick](B,B' B',A')
 \end{tikzpicture}
\end{document}

How can I draw it with tikz-3dplot?

0

1 Answer 1

4

Something like this?

\documentclass[border=2mm,12pt,tikz]{standalone}
\usepackage{tikz-3dplot} 
\usetikzlibrary{3d,calc,backgrounds,patterns}
\usepackage{fouriernc}
\begin{document}
\def\myr{3}
\def\h{6}
\def\angA{0}
\def\angB{80}
\tdplotsetmaincoords{80}{60}
\begin{tikzpicture}[tdplot_main_coords]
%    \draw[-latex] (0,0,0) -- (1,0,0) node[pos=1.1]{$x$};
%    \draw[-latex] (0,0,0) -- (0,1,0) node[pos=1.1]{$y$};
%    \draw[-latex] (0,0,0) -- (0,0,1) node[pos=1.1]{$z$};
  \begin{scope}[canvas is xy plane at z=0]
   \path (0,0) coordinate[label=below:$O$] (O);
   \draw[dashed] (\tdplotmainphi:\myr) arc(\tdplotmainphi:\tdplotmainphi+180:\myr);
   \draw[dashed] (\angA:\myr) coordinate (A) -- (\angB:\myr) coordinate (B)
    node[pos=-0.1] {$A$} node[pos=1.1] {$B$};
   \draw[thick] (\tdplotmainphi:\myr) coordinate(BR) arc(\tdplotmainphi:\tdplotmainphi-180:\myr)
   coordinate(BL);
  \end{scope}
  %
  \begin{scope}[canvas is xy plane at z=\h]
   \draw[thick] (0,0) coordinate[label=above:$O'$] (O') circle[radius=\myr];
   \draw[dashed] (O) -- (O');
   \draw[thick] (\angA:\myr) coordinate (A') -- (\angB:\myr) coordinate (B')
    node[pos=-0.1] {$A'$} node[pos=1.1] {$B'$};
   \path[pattern=north east lines] (A) -- (B) -- (B') -- (A') -- cycle;
   \pgfmathtruncatemacro{\itest}{-sign(sin(\angA-\tdplotmainphi))}
   \draw (BR) -- (\tdplotmainphi:\myr) (BL) -- (\tdplotmainphi-180:\myr);
   \ifnum\itest=-1
    \draw[dashed] (A) -- (A');
   \else
    \draw[thick] (A) -- (A');
   \fi
   \pgfmathtruncatemacro{\itest}{-sign(sin(\angB-\tdplotmainphi))}
   \ifnum\itest=-1
    \draw[dashed] (B) -- (B');
   \else
    \draw[thick] (B) -- (B');
   \fi
  \end{scope}
  \foreach \X in {A,B,O}
  {\fill (\X) circle(1pt) (\X') circle(1pt);}
\end{tikzpicture}
\end{document} 

enter image description here

The vertical boundaries of the plane are dashed if they are on the back of the cylinder.

\documentclass[border=2mm,12pt,tikz]{standalone}
\usepackage{tikz-3dplot} 
\usetikzlibrary{3d,calc,backgrounds,patterns}
\usepackage{fouriernc}
\begin{document}
\def\myr{3}
\def\h{6}
\def\angA{0}
\def\angB{80}
\foreach \X in {0,10,...,350}
{\tdplotsetmaincoords{80}{\X}
\begin{tikzpicture}[tdplot_main_coords]
\path[tdplot_screen_coords,use as bounding box] (-1.3*\myr,-1) rectangle 
(1.3*\myr,\h+1);
%    \draw[-latex] (0,0,0) -- (1,0,0) node[pos=1.1]{$x$};
%    \draw[-latex] (0,0,0) -- (0,1,0) node[pos=1.1]{$y$};
%    \draw[-latex] (0,0,0) -- (0,0,1) node[pos=1.1]{$z$};
  \begin{scope}[canvas is xy plane at z=0]
   \path (0,0) coordinate[label=below:$O$] (O);
   \draw[dashed] (\tdplotmainphi:\myr) arc(\tdplotmainphi:\tdplotmainphi+180:\myr);
   \draw[dashed] (\angA:\myr) coordinate (A) -- (\angB:\myr) coordinate (B)
    node[pos=-0.1] {$A$} node[pos=1.1] {$B$};
   \draw[thick] (\tdplotmainphi:\myr) coordinate(BR) arc(\tdplotmainphi:\tdplotmainphi-180:\myr)
   coordinate(BL);
  \end{scope}
  %
  \begin{scope}[canvas is xy plane at z=\h]
   \draw[thick] (0,0) coordinate[label=above:$O'$] (O') circle[radius=\myr];
   \draw[dashed] (O) -- (O');
   \draw[thick] (\angA:\myr) coordinate (A') -- (\angB:\myr) coordinate (B')
    node[pos=-0.1] {$A'$} node[pos=1.1] {$B'$};
   \path[pattern=north east lines] (A) -- (B) -- (B') -- (A') -- cycle;
   \pgfmathtruncatemacro{\itest}{-sign(sin(\angA-\tdplotmainphi))}
   \draw (BR) -- (\tdplotmainphi:\myr) (BL) -- (\tdplotmainphi-180:\myr);
   \ifnum\itest=-1
    \draw[dashed] (A) -- (A');
   \else
    \draw[thick] (A) -- (A');
   \fi
   \pgfmathtruncatemacro{\itest}{-sign(sin(\angB-\tdplotmainphi))}
   \ifnum\itest=-1
    \draw[dashed] (B) -- (B');
   \else
    \draw[thick] (B) -- (B');
   \fi
  \end{scope}
  \foreach \X in {A,B,O}
  {\fill (\X) circle(1pt) (\X') circle(1pt);}
\end{tikzpicture}}
\end{document} 

enter image description here

3
  • Can I choose a canvas plane with the equaton x + 2y - z = 0? Commented Mar 24, 2019 at 15:06
  • @minhthien_2016 Not without extra efforts. One would have to compute the intersection curve between this plane and the cylinder. E.g. by saying that x^2+y^2=R^2 or using trigonometric relations x=R*cos(alpha) and y=R*sin(alpha), plugging them into the plane equation, solve it and plot the solution.
    – user121799
    Commented Mar 24, 2019 at 15:16
  • I have just post a new question at tex.stackexchange.com/questions/481283/… Commented Mar 25, 2019 at 1:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .