Welcome to our community

Be a part of something great, join today!

TiKZ Cylinder Question about LaTeX (Evgeny.Makarov)

dwsmith

Well-known member
Feb 1, 2012
1,673
I cant seem to make a cylinder that is circular on the yz axis and runs length wise down the x.
Evgeny.Makarov do you know how to accomplish this?

I tried using \filldraw with the arc command to round and shade the circular sides but it wasn't going so well.
 

Evgeny.Makarov

Well-known member
MHB Math Scholar
Jan 30, 2012
2,492
Re: cylinder (Evgeny.Makarov)

Code:
\usetikzlibrary{arrows}
\begin{tikzpicture}[>=stealth']
\newcommand{\rx}{.5cm}
\newcommand{\ry}{1.5cm}
\filldraw[right color=gray!70,left color=white,middle color=gray!30,shading=axis,opacity=1] (6,0) circle ({\rx} and \ry);
\filldraw[top color=gray!70!black,bottom color=gray!70!black,middle color=gray!30,shading=axis,opacity=1] (0,-\ry) -- (6,-\ry) arc (-90:-270:{\rx} and \ry) -- (0,\ry) arc (90:270:{\rx} and \ry);
\draw[dashed] (0,-\ry) arc (-90:90:{\rx} and \ry);

\draw[dashed] (0,0) -- (6,0); \draw[->] (6,0) -- (7.5,0) node[below] {$x$};
\draw[dashed] (0,0) -- (0,\ry); \draw[->] (0,\ry) -- (0,\ry+1cm) node[left] {$z$};
\draw[dashed] (0,0) -- (\ry,\ry); \draw[->] (\ry,\ry) -- (\ry+.5cm,\ry+.5cm) node[below right] {$y$};
\end{tikzpicture}
gives this.

cylinder.png

(Used code from StackExchange.)
 

dwsmith

Well-known member
Feb 1, 2012
1,673
Re: cylinder (Evgeny.Makarov)

Code:
\usetikzlibrary{arrows}
\begin{tikzpicture}[>=stealth']
\newcommand{\rx}{.5cm}
\newcommand{\ry}{1.5cm}
\filldraw[right color=gray!70,left color=white,middle color=gray!30,shading=axis,opacity=1] (6,0) circle ({\rx} and \ry);
\filldraw[top color=gray!70!black,bottom color=gray!70!black,middle color=gray!30,shading=axis,opacity=1] (0,-\ry) -- (6,-\ry) arc (-90:-270:{\rx} and \ry) -- (0,\ry) arc (90:270:{\rx} and \ry);
\draw[dashed] (0,-\ry) arc (-90:90:{\rx} and \ry);

\draw[dashed] (0,0) -- (6,0); \draw[->] (6,0) -- (7.5,0) node[below] {$x$};
\draw[dashed] (0,0) -- (0,\ry); \draw[->] (0,\ry) -- (0,\ry+1cm) node[left] {$z$};
\draw[dashed] (0,0) -- (\ry,\ry); \draw[->] (\ry,\ry) -- (\ry+.5cm,\ry+.5cm) node[below right] {$y$};
\end{tikzpicture}
gives this.

View attachment 638

(Used code from StackExchange.)
I have seen that one but one you change $x$ to come out of the paper it doesn't translate well.