Drawing a cylinder along the x-axis in LaTeX

  • Topic: LaTeX 
  • Thread starter Thread starter Dustinsfl
  • Start date Start date
  • Tags Tags
    Cylinder Latex
Join the discussion
Registration is free. Start your own thread to ask a follow-up.
2 replies · 3K views
Dustinsfl
Messages
2,217
Reaction score
5
I can't 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.
 
Physics news on Phys.org
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.)
 
Attachments
  • cylinder.png
    cylinder.png
    4.9 KB · Views: 126
Re: cylinder (Evgeny.Makarov)

Evgeny.Makarov said:
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.

https://www.physicsforums.com/attachments/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.