如何绘制一个带有 3 个球的圆柱体?

如何绘制一个带有 3 个球的圆柱体?

我需要画一个圆柱形的盒子,里面有三个乒乓球,如下所示 在此处输入图片描述

但我只能做圆柱体。我不能把球放进去:

\documentclass{article}

\usepackage{graphicx}

\usepackage{tikz}

\usetikzlibrary{snakes,shapes,decorations.text}

\begin{document}

\begin{center}

\begin{tikzpicture}


   \draw (0,0) node[cylinder,draw=black,thick,aspect=1.4,
    minimum height=3cm,minimum width=2.5cm, shape border rotate=90,
    cylinder uses custom fill, cylinder body fill=red!30,
    cylinder end  fill=blue!10, opacity=.4,anchor=north]
   (A) {};

\draw [dashed] (1.23,-2.87) arc[x radius=1.24, y radius=1/3, start angle=0, end angle=180];

\end{tikzpicture}

\end{center}

\end{document}

答案1

像这样吗?

3个球

\documentclass[tikz,border=10pt,multi]{standalone}
\usetikzlibrary{shapes.geometric,positioning,fit}
\begin{document}
\begin{tikzpicture}[ball/.style={circle, minimum size=25pt, draw}]
  \node (b1) [ball] {};
  \node (b2) [ball, below=0pt of b1] {};
  \node (b3) [ball, below=0pt of b2] {};
  \coordinate (c1) at ([yshift=6pt]b1.center);
  \node (c) [cylinder, draw, fit=(c1) (b2) (b3), shape border rotate=90, inner sep=0pt,, aspect=.5] {};
  \draw [<->] ([xshift=15pt]c.after top) coordinate (a1) -- ([xshift=15pt]c.before bottom) coordinate (a2) node [fill=white, midway] {$3d$};
  \draw [thin, draw=gray, densely dashed] (c.after top) -- (a1) (c.before bottom) -- (a2);
  \draw [thin, densely dashed, draw=gray] (c.before bottom) arc [x radius=12.5pt, y radius=6pt, start angle=0, end angle=180];
  \draw [thin, densely dashed, draw=gray] (b1.north) -- (b3.south) \foreach \i in {1,3,5} {node [left, pos=\i/6] {$d$}};
\end{tikzpicture}
\end{document}

相关内容