如何在 LaTeX 中绘制 3D 矩形?

如何在 LaTeX 中绘制 3D 矩形?

我尝试使用 LaTeX 绘制下面的图片:

通缉

我尝试了下面的代码但它看起来与我想要的不一样:

\documentclass{article}
\usepackage{tikz}

\definecolor{cof}{RGB}{219,144,71}
\definecolor{pur}{RGB}{186,146,162}
\definecolor{greeo}{RGB}{91,173,69}
\definecolor{greet}{RGB}{52,111,72}

\begin{document}

\begin{tikzpicture}[thick,scale=5]
\coordinate (A1) at (0, 0);
\coordinate (A2) at (0, 1);
\coordinate (A3) at (1, 1);
\coordinate (A4) at (1, 0);
\coordinate (B1) at (0.5, 0.5);
\coordinate (B2) at (0.3, 1.3);
\coordinate (B3) at (1.3, 1.3);
\coordinate (B4) at (1.3, 0.3);

\draw[very thick] (A1) -- (A2);
\draw[very thick] (A2) -- (A3);
\draw[very thick] (A3) -- (A4);
\draw[very thick] (A4) -- (A1);

\draw[dashed] (A1) -- (B1);
\draw[dashed] (B1) -- (B2);
\draw[very thick] (A2) -- (B2);
\draw[very thick] (B2) -- (B3);
\draw[very thick] (A3) -- (B3);
\draw[very thick] (A4) -- (B4);
\draw[very thick] (B4) -- (B3);
\draw[dashed] (B1) -- (B4);

\draw[fill=yellow,opacity=0.6] (A1) -- (B1) -- (B4) -- (A4);
\draw[fill=black!20,opacity=0.5] (A1) -- (A2) -- (A3) -- (A4);
\draw[opacity=0.6] (A1) -- (A2) -- (B2) -- (B1);
\draw[opacity=0.6] (B1) -- (B2) -- (B3) -- (B4);
\draw[opacity=0.6] (A3) -- (B3) -- (B4) -- (A4);
\draw[opacity=0.6] (A2) -- (B2) -- (B3) -- (A3);

\end{tikzpicture}

\end{document}

答案1

我重做了你的图表,现在命令变少了。我猜这些点一开始就是随机的,所以我就把它们随机地画出来了。我不确定你想给图片上色,所以我暂时把它留成黑白色。如果你在给某个部分上色时遇到困难,请告诉我。

更新:

  • 为具有不同边框颜色的背景方块添加了自定义样式。

输出

在此处输入图片描述

代码

\documentclass[margin=10pt]{standalone}
\usepackage{tikz}

\usetikzlibrary{calc}

\definecolor{cof}{RGB}{219,144,71}
\definecolor{pur}{RGB}{186,146,162}
\definecolor{greeo}{RGB}{91,173,69}
\definecolor{greet}{RGB}{52,111,72}

\tikzset{%
    nod/.style={draw,minimum height=3cm, minimum width=2cm, anchor=south west, outer sep=0, text height=3ex},
    nodc/.style={nod,draw=none,append after command={%
        (\tikzlastnode.south east) edge[gray] (\tikzlastnode.south west) 
        (\tikzlastnode.south west) edge[gray] (\tikzlastnode.north west)
        (\tikzlastnode.north west) edge (\tikzlastnode.north east) 
        (\tikzlastnode.north east) edge (\tikzlastnode.south east)
        }
    },
}

\begin{document}
\begin{tikzpicture}[thick]
\node[nod, label=90:A] (a) at (0,0) {$cosx$};
\node[nod, label=90:B] (b) at (2,0) {$sinx$};
\node[nodc, minimum height=2cm, minimum width=2.8cm] (c) at (5,4.5) {};
\draw (a.north west) -- (c.north west);
\draw (b.north east) -- (c.north east);
\draw (b.south east) -- (c.south east);
\draw[dashed, gray] (a.south west) -- (c.south west);

\node[fill=black, circle, inner sep=3pt] (dot) at ($(b.north west-|c.south west)+(.5,0)$) {};
\draw[->] (dot) --++ (2,0) coordinate (ar);
\draw (ar)++(.1,0) to[out=0,in=0, looseness=2] ($(dot)+(1,5)$)
    edge[out=180,in=180,looseness=2,->] ($(a.north east)+(0,1.5)$);
\begin{scope}[shift={(2.5,-.2)}]
\draw plot [only marks, mark=*, mark size=1pt, domain=2:4, samples=20] (\x,{rnd*1.25+3.5/5*\x+0.5});
\end{scope}
\end{tikzpicture}
\end{document}

相关内容