AcroHam

Tikz diagram help

Jun 29th, 2025
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Latex 1.64 KB | Source Code | 0 0
  1. \documentclass{standalone}
  2. \usepackage{tikz}
  3. \usepackage{tikz-3dplot}
  4.  
  5. \begin{document}
  6.  
  7. % Set azimuth and elevation for the 3D view
  8. \def\az{110}
  9. \def\elev{70}
  10. \tdplotsetmaincoords{\elev}{\az}
  11.  
  12. \begin{tikzpicture}[tdplot_main_coords, line join=round]
  13.  
  14.   % Cylinder parameters
  15.   \def\r{0.5}
  16.  \def\h{2}
  17.  
  18.   % Base plate (cuboid)
  19.   \draw (-4,-1,-0.5) -- (4,-1,-0.5);
  20.   \draw (4,-1,-0.5) -- (4,1,-0.5);
  21.   \draw (4,1,-0.5) -- (-4,1,-0.5);
  22.   \draw[fill=white] (-4,-1,0) -- (4,-1,0) -- (4,1,0) -- (-4,1,0) -- cycle;
  23.   \draw (4,1,0) -- (4,1,-0.5);
  24.   \draw (4,-1,0) -- (4,-1,-0.5);
  25.   \draw (-4,1,0) -- (-4,1,-0.5);
  26.  
  27.   % Coordinate axes
  28.   \draw[->] (-6,0,0) -- (6,0,0) node[anchor=north east] {$z$};
  29.  \draw[->] (0,-2,0) -- (0,2,0) node[anchor=south west] {$x$};
  30.  \draw[->] (0,0,\h) -- (0,0,3) node[anchor=south] {$y$};
  31.  
  32.   % Vertical cylinder
  33.   \draw[fill=white]
  34.     ({cos(\az+180)*\r},{sin(\az+180)*\r},\h) -- ({cos(\az+180)*\r},{sin(\az+180)*\r},0) --
  35.    ({cos(\az+180)*\r},{sin(\az+180)*\r},0) arc[start angle=\az+180, end angle=470, x radius=\r, y radius=\r] --
  36.    ({cos(\az)*\r},{sin(\az)*\r},0) -- ({cos(\az)*\r},{sin(\az)*\r},\h);
  37.  
  38.   % Top ellipse of the cylinder
  39.   \draw (0,\r,\h) arc[start angle=90, end angle=450, x radius=\r, y radius=\r];
  40.  
  41.   % Hidden coordinate lines (dashed)
  42.   \draw[densely dashed] (-4,0,0) -- (\r,0,0);
  43.   \draw[densely dashed] (0,-\r,0) -- (0,\r,0);
  44.   \draw[densely dashed] (0,0,-0.5) -- (0,0,\h);
  45.  
  46.   % Origin marker
  47.   \node[fill, circle, inner sep=1pt, label=above left:$O$] (O) at (0,0,0) {};
  48.  
  49.   % Top center of the cylinder
  50.   \fill (0,0,\h) circle (0.7pt);
  51.  
  52. \end{tikzpicture}
  53.  
  54. \end{document}
  55.  
Advertisement
Add Comment
Please, Sign In to add comment