3

I have found the following reference which creates a vertical cylinder with a bottom. However I need a horizontal cylinder with a bottom, but can't seem to find an easy (and working) example. I tried using the rotated coordinate system from tikz-3dplot, but to no avail. This is my testing code:

\documentclass[tikz]{standalone}

\usepackage{tikz}
\usepackage{tikz-3dplot} %requires 3dplot.sty to be in same directory, or in    your LaTeX installation
\usetikzlibrary{shapes.geometric,calc}

\title{TikZ: cylinder with bottom - example}
\begin{document}

\tdplotsetmaincoords{0}{0}

\begin{tikzpicture}[tdplot_main_coords]
  \node[cylinder,draw=black,thick,aspect=0.7,minimum height=4cm,minimum     width=3cm,shape border rotate=0,cylinder uses custom fill, cylinder body     fill=red!30,cylinder end fill=red!10] (A) {A};

\tdplotsetrotatedcoords{0}{90}{0}

\draw[dashed,tdplot_rotated_coords]
    let \p1 = ($ (A.after bottom) - (A.before bottom) $),
        \n1 = {0.5*veclen(\x1,\y1)-\pgflinewidth},
        \p2 = ($ (A.bottom) - (A.after bottom)!.5!(A.before bottom) $),
        \n2 = {veclen(\x2,\y2)-\pgflinewidth}
  in
    ([xshift=-\pgflinewidth] A.before bottom) arc [start angle=0, end angle=180,
    x radius=\n1, y radius=\n2];
\end{tikzpicture}

\end{document}

enter image description here

3

Like this?

enter image description here

You just need to change how the arc is drawn. Your code has start angle=0,end angle=180, so it is the upper half of an ellipse, while you need the right half.

The starting point is the bottom of the cylinder, so you need start angle=270, and to get the correct part of the ellipse, use delta angle=180 instead of end angle=90. You also need to swap the x and y radius, so the arc command becomes

arc [start angle=270, delta angle=180,
    x radius=\n2, y radius=\n1];

The tikz-3dplot stuff isn't needed. Complete code:

\documentclass[tikz,border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,calc}
\begin{document}

\begin{tikzpicture}
  \node[cylinder,draw=black,thick,aspect=0.7,minimum height=4cm,minimum     width=3cm,shape border rotate=0,cylinder uses custom fill, cylinder body     fill=red!30,cylinder end fill=red!10] (A) {A};

\draw[dashed]
    let \p1 = ($ (A.after bottom) - (A.before bottom) $),
        \n1 = {0.5*veclen(\x1,\y1)-\pgflinewidth},
        \p2 = ($ (A.bottom) - (A.after bottom)!.5!(A.before bottom) $),
        \n2 = {veclen(\x2,\y2)-\pgflinewidth}
  in
    ([xshift=-\pgflinewidth] A.before bottom) arc [start angle=270, delta angle=180,
    x radius=\n2, y radius=\n1];
\end{tikzpicture}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.