tikz:如何用半透明的 3D 板创建这样的图片

tikz:如何用半透明的 3D 板创建这样的图片

我正在尝试重新创建以下图片。我尝试使用 Mathcha.io 重新创建此图片,但我无法在彩色板上获得正确的半透明 3D 外观。有没有办法重新创建这张图片?

在此处输入图片描述

答案1

这确实很简单。更新:简化代码。

\documentclass[tikz,border=3.14pt]{standalone}
\usepackage{tikz-3dplot}
\definecolor{darkgreen}{rgb}{0.0, 0.8, 0.2}
\newcommand{\TranslucentPlane}[3][]{
\draw[fill=#3!70,opacity=0.6] (-3,-3,#2) -- (-3,3,#2) -- (3,3,#2) -- (3,-3,#2) -- cycle;
\draw[fill=#3!40,opacity=0.6] (-3,3,#2) -- (3,3,#2) -- (3,3,{#2+0.2}) -- (-3,3,{#2+0.2})
-- cycle;
\draw[fill=#3!40,opacity=0.6] (-3,3,#2) -- (-3,-3,#2) -- (-3,-3,{#2+0.2}) -- (-3,3,{#2+0.2})
-- cycle;
\draw[fill=#3!40,opacity=0.6] (-3,-3,{#2+0.2}) -- (-3,3,{#2+0.2}) -- (3,3,{#2+0.2}) -- 
(3,-3,{#2+0.2}) -- cycle;
\draw[fill=#3!40,opacity=0.6] (3,-3,#2) -- (3,3,#2) -- (3,3,{#2+0.2}) -- (3,-3,{#2+0.2})
-- cycle;
\draw[fill=#3!40,opacity=0.6] (3,-3,#2) -- (-3,-3,#2) -- (-3,-3,{#2+0.2}) --
(3,-3,{#2+0.2})
-- cycle;
}
\begin{document}
\tdplotsetmaincoords{70}{40}
\begin{tikzpicture}[tdplot_main_coords]
\tdplotsetrotatedcoords{0}{00}{0}
\begin{scope}[tdplot_rotated_coords]
\foreach \Z/\Col in {1/black,2/gray,3/blue,4/blue,5/darkgreen,6/darkgreen}
{
\TranslucentPlane{\Z}{\Col}
}
\end{scope}
\end{tikzpicture}
\end{document}

在此处输入图片描述

旧答案

在此处输入图片描述

\documentclass[tikz,border=3.14pt]{standalone}
\usepackage{tikz-3dplot}
\begin{document}
\tdplotsetmaincoords{70}{40}
\begin{tikzpicture}[tdplot_main_coords]
\tdplotsetrotatedcoords{0}{00}{0}
\begin{scope}[tdplot_rotated_coords]
\foreach \Z in {1}
{
\draw[fill=black!70,opacity=0.6] (-3,-3,\Z) -- (-3,3,\Z) -- (3,3,\Z) -- (3,-3,\Z) -- cycle;
\draw[fill=black!40,opacity=0.6] (-3,3,\Z) -- (3,3,\Z) -- (3,3,{\Z+0.2}) -- (-3,3,{\Z+0.2})
-- cycle;
\draw[fill=black!40,opacity=0.6] (-3,3,\Z) -- (-3,-3,\Z) -- (-3,-3,{\Z+0.2}) -- (-3,3,{\Z+0.2})
-- cycle;
\draw[fill=black!70,opacity=0.6] (-3,-3,{\Z+0.2}) -- (-3,3,{\Z+0.2}) -- (3,3,{\Z+0.2}) -- 
(3,-3,{\Z+0.2}) -- cycle;
\draw[fill=black!40,opacity=0.6] (3,-3,\Z) -- (3,3,\Z) -- (3,3,{\Z+0.2}) -- (3,-3,{\Z+0.2})
-- cycle;
\draw[fill=black!40,opacity=0.6] (3,-3,\Z) -- (-3,-3,\Z) -- (-3,-3,{\Z+0.2}) --
(3,-3,{\Z+0.2})
-- cycle;
}
\foreach \Z in {2}
{
\draw[fill=gray!70,opacity=0.6] (-3,-3,\Z) -- (-3,3,\Z) -- (3,3,\Z) -- (3,-3,\Z) -- cycle;
\draw[fill=gray!40,opacity=0.6] (-3,3,\Z) -- (3,3,\Z) -- (3,3,{\Z+0.2}) -- (-3,3,{\Z+0.2})
-- cycle;
\draw[fill=gray!40,opacity=0.6] (-3,3,\Z) -- (-3,-3,\Z) -- (-3,-3,{\Z+0.2}) -- (-3,3,{\Z+0.2})
-- cycle;
\draw[fill=gray!70,opacity=0.6] (-3,-3,{\Z+0.2}) -- (-3,3,{\Z+0.2}) -- (3,3,{\Z+0.2}) -- 
(3,-3,{\Z+0.2}) -- cycle;
\draw[fill=gray!40,opacity=0.6] (3,-3,\Z) -- (3,3,\Z) -- (3,3,{\Z+0.2}) -- (3,-3,{\Z+0.2})
-- cycle;
\draw[fill=gray!40,opacity=0.6] (3,-3,\Z) -- (-3,-3,\Z) -- (-3,-3,{\Z+0.2}) --
(3,-3,{\Z+0.2})
-- cycle;
}
\foreach \Z in {3,4}
{
\draw[fill=blue!70,opacity=0.6] (-3,-3,\Z) -- (-3,3,\Z) -- (3,3,\Z) -- (3,-3,\Z) -- cycle;
\draw[fill=blue!40,opacity=0.6] (-3,3,\Z) -- (3,3,\Z) -- (3,3,{\Z+0.2}) -- (-3,3,{\Z+0.2})
-- cycle;
\draw[fill=blue!40,opacity=0.6] (-3,3,\Z) -- (-3,-3,\Z) -- (-3,-3,{\Z+0.2}) -- (-3,3,{\Z+0.2})
-- cycle;
\draw[fill=blue!70,opacity=0.6] (-3,-3,{\Z+0.2}) -- (-3,3,{\Z+0.2}) -- (3,3,{\Z+0.2}) -- 
(3,-3,{\Z+0.2}) -- cycle;
\draw[fill=blue!40,opacity=0.6] (3,-3,\Z) -- (3,3,\Z) -- (3,3,{\Z+0.2}) -- (3,-3,{\Z+0.2})
-- cycle;
\draw[fill=blue!40,opacity=0.6] (3,-3,\Z) -- (-3,-3,\Z) -- (-3,-3,{\Z+0.2}) --
(3,-3,{\Z+0.2})
-- cycle;
}

\foreach \Z in {5,6}
{
\draw[fill=green!70,opacity=0.6] (-3,-3,\Z) -- (-3,3,\Z) -- (3,3,\Z) -- (3,-3,\Z) -- cycle;
\draw[fill=green!40,opacity=0.6] (-3,3,\Z) -- (3,3,\Z) -- (3,3,{\Z+0.2}) -- (-3,3,{\Z+0.2})
-- cycle;
\draw[fill=green!40,opacity=0.6] (-3,3,\Z) -- (-3,-3,\Z) -- (-3,-3,{\Z+0.2}) -- (-3,3,{\Z+0.2})
-- cycle;
\draw[fill=green!70,opacity=0.6] (-3,-3,{\Z+0.2}) -- (-3,3,{\Z+0.2}) -- (3,3,{\Z+0.2}) -- 
(3,-3,{\Z+0.2}) -- cycle;
\draw[fill=green!40,opacity=0.6] (3,-3,\Z) -- (3,3,\Z) -- (3,3,{\Z+0.2}) -- (3,-3,{\Z+0.2})
-- cycle;
\draw[fill=green!40,opacity=0.6] (3,-3,\Z) -- (-3,-3,\Z) -- (-3,-3,{\Z+0.2}) --
(3,-3,{\Z+0.2})
-- cycle;
}
\end{scope}
\end{tikzpicture}
\end{document}

相关内容