Cylinder Question about LaTeX (Evgeny.Makarov)

  • Context: LaTeX 
  • Thread starter Thread starter Dustinsfl
  • Start date Start date
  • Tags Tags
    Cylinder Latex
Click For Summary
SUMMARY

This discussion focuses on creating a cylinder in LaTeX that is circular on the yz-axis and extends along the x-axis. The user, Evgeny.Makarov, shares a TikZ code snippet utilizing the \filldraw and arc commands to achieve the desired shading and shape. The provided code demonstrates how to define the radius and shading for the circular sides of the cylinder. However, the user notes challenges in translating the cylinder's appearance when adjusting the x-axis position.

PREREQUISITES
  • Familiarity with LaTeX typesetting
  • Understanding of TikZ library for graphics in LaTeX
  • Knowledge of 3D coordinate systems
  • Experience with shading techniques in TikZ
NEXT STEPS
  • Explore advanced TikZ shading techniques for 3D shapes
  • Learn about the \draw command in TikZ for creating complex shapes
  • Investigate the use of the \newcommand feature in LaTeX for reusable code snippets
  • Study the impact of coordinate transformations in TikZ for 3D representations
USEFUL FOR

This discussion is beneficial for LaTeX users, graphic designers, and educators looking to create 3D visualizations using TikZ, particularly those interested in enhancing their skills in technical illustrations.

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: 104
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
26
Views
1K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 14 ·
Replies
14
Views
3K
  • · Replies 16 ·
Replies
16
Views
3K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 10 ·
Replies
10
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K