Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

How to create custom TikZ node "cylinder with bottom", where hidden line in cylinder bottom is shown using dashed line.

Something like the following creation, except node center should be in the middle of cylinder (as if it was in the middle of the center of 3D cylinder), not in center of the side -- it looks imbalanced

https://www.writelatex.com/1149537sksqzs#/2737083/

\documentclass[tikz]{standalone}

\usepackage{tikz}
\usetikzlibrary{shapes.geometric,calc}

\begin{document}
\begin{tikzpicture}
  \node[cylinder,draw=black,thick,aspect=0.7,
        minimum height=1.7cm,minimum width=1.5cm,
        shape border rotate=90,
        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)},
        \p2 = ($ (A.bottom) - (A.after bottom)!.5!(A.before bottom) $),
        \n2 = {veclen(\x2,\y2)}
  in
    (A.before bottom) arc [start angle=0, end angle=180,
    x radius=\n1, y radius=\n2];
\end{tikzpicture}
\end{document}

3D cylinder with bottom

share|improve this question
1  
It seams to be a problem of line width. Try x radius=\n1 - \pgflinewidth ? –  Tarass Jun 3 at 17:58

1 Answer 1

As Tarass correctly guessed, it is a problem of line width, but it affects both to the arc radius and to the initial point (A.before bottom). This is a possible fix:

\documentclass[tikz]{standalone}

\usepackage{tikz}
\usetikzlibrary{shapes.geometric,calc}

\title{TikZ: cylinder with bottom - example}
\begin{document}
\begin{tikzpicture}
  \node[cylinder,draw=black,thick,aspect=0.7,minimum height=1.7cm,minimum width=1.5cm,shape border rotate=90,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=0, end angle=180,
    x radius=\n1, y radius=\n2];
\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
    
Good shot, I haven't a tex box to try it. –  Tarass Jun 3 at 19:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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