LaTeX Cylinder Question about LaTeX (Evgeny.Makarov)

  • Thread starter Thread starter Dustinsfl
  • Start date Start date
  • Tags Tags
    Cylinder Latex
AI Thread Summary
The discussion centers on creating a cylinder that is circular along the yz-axis and extends along the x-axis using TikZ in LaTeX. The user expresses difficulty in achieving the desired cylindrical shape, particularly when attempting to use the \filldraw command with arcs for shading. They reference code from StackExchange but note that modifying the x-axis to project out of the paper does not yield satisfactory results. The conversation highlights the challenges of visualizing three-dimensional shapes in a two-dimensional medium and the limitations of the current approach.
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: 90
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.
 

Similar threads

Replies
3
Views
2K
Replies
4
Views
3K
Replies
4
Views
4K
Replies
16
Views
3K
Replies
9
Views
3K
Back
Top