绘制两个圆柱体并使用裁剪

绘制两个圆柱体并使用裁剪

我需要绘制如下所示的两个圆柱体,但我想使用剪切使得第一个圆柱体覆盖第二个圆柱体,而不是让第二个圆柱体透过第一个圆柱体,我该怎么做:

\documentclass[tikz]{standalone}
\usetikzlibrary{shapes.geometric,positioning}
\begin{document}
\begin{tikzpicture}
\node (db-slice1) [cylinder, shape border rotate=90, draw,
    minimum height=1cm,minimum width=2cm] {};
\node (db-slice2) [cylinder, shape border rotate=90, draw,
    minimum height=1cm,minimum width=2cm,
    below=-2.5mm of db-slice1] {};
\end{tikzpicture}
\end{document}

本质上我想要绘制的是一个数据库符号,它有三个切片,每个切片彼此略低于彼此,较高的切片剪切较低的切片。

我已经看过了这个例子,但渐变和 3D 效果太多。

在此处输入图片描述

奖金:如何绘制隐藏线虚线而不是剪切它。

答案1

像这样?

在此处输入图片描述

\documentclass[tikz, border=2mm]{standalone}
\usetikzlibrary{shapes.geometric,positioning}
\begin{document}
\begin{tikzpicture}
\node (db-slice1) [cylinder, shape border rotate=90, draw,
    minimum height=1cm,minimum width=2cm, fill=red!30] {A};
\node (db-slice2) [cylinder, shape border rotate=90, draw,
    minimum height=1cm,minimum width=2cm,
    above=0pt of db-slice1.before top, anchor=after bottom, fill=blue!30] {B};
\node (db-slice3) [cylinder, shape border rotate=90, draw,
    minimum height=1cm,minimum width=2cm,
    above=0pt of db-slice2.before top, anchor=after bottom, fill=green!30] {C};
\end{tikzpicture}
\end{document}

相关内容