如何在 LateX 上绘制立方体

如何在 LateX 上绘制立方体

我一直在尝试在乳胶上绘图,但一直没有进展。我只是想知道是否有人可以帮我画出以下形状?只是需要一点指导,因为我对这个程序还很陌生。

在此处输入图片描述

答案1

在此处输入图片描述

以下解决方案使用tikz3d.styTeX.SX 启动板中的实验性(?)包。要安装它,请执行以下操作:

  1. 下载tikz3d.dtxhttp://bazaar.launchpad.net/~tex-sx/tex-sx/development/view/head:/tikz3d.dtx
  2. dtx对要提取的文件运行 pdflatex tikz3d.sty

    pdflatex tikz3d.dtx
    
  3. pdflatex再次运行tikz3d.dtx以获取tikz3d.pdf该包的文档。

现在pdflatex执行下面的代码应该会出现上面的效果。

\documentclass{minimal}
\usepackage{tikz}
\usepackage{tikz3d}
\begin{document}
\begin{center}
\begin{tikzpicture}[3d/perspective eye={0,5,-10},>=stealth]
\newcommand\xa{5} % half of width at bottom
\newcommand\xb{2} % half of width at top
\newcommand\ya{2} % height
\newcommand\za{2} % half of depth
\coordinate (A) at (3d cs:-\xa,0,-\za);
\coordinate (B) at (3d cs: \xa,0,-\za);
\coordinate (C) at (3d cs: \xa,0, \za);
\coordinate (D) at (3d cs:-\xa,0, \za);
\coordinate (E) at (3d cs:-\xb,\ya, 0);
\coordinate (F) at (3d cs: \xb,\ya, 0);
\draw[thick] (D) -- node[left]{$w$} (A) -- node[below]{$l$} (B) -- (C);
\draw[dashed] (C) -- (D);
\draw[thick] (A) -- (E) -- (D);
\draw[thick] (B) -- (F) -- (C);
\draw[thick] (E) -- node[above]{$t$} (F);
\draw[<->,dashed] (3d cs:1,0,0) -- node[right]{$h$} (3d cs:1,\ya,0);
\end{tikzpicture}
\vspace{1cm}

\begin{tikzpicture}[3d/perspective eye={0,5,-10}]
\newcommand\xa{6} % half of width at bottom, shifted
\newcommand\xb{2} % half of width at top
\newcommand\xc{3} % half of width at top, shifted
\newcommand\ya{2} % height
\newcommand\za{2} % half of depth
\coordinate (A) at (3d cs:-\xa,0,-\za);
\coordinate (B) at (3d cs: \xa,0,-\za);
\coordinate (C) at (3d cs: \xa,0, \za);
\coordinate (D) at (3d cs:-\xa,0, \za);
\coordinate (E) at (3d cs:-\xb,\ya, 0);
\coordinate (F) at (3d cs: \xb,\ya, 0);
\coordinate (E') at (3d cs:-\xc,\ya, 0);
\coordinate (F') at (3d cs: \xc,\ya, 0);
\coordinate (a) at (3d cs:-\xb,0,-\za);
\coordinate (b) at (3d cs: \xb,0,-\za);
\coordinate (c) at (3d cs: \xb,0, \za);
\coordinate (d) at (3d cs:-\xb,0, \za);
\coordinate (a') at (3d cs:-\xc,0,-\za);
\coordinate (b') at (3d cs: \xc,0,-\za);
\coordinate (c') at (3d cs: \xc,0, \za);
\coordinate (d') at (3d cs:-\xc,0, \za);
\draw[thick] (a') -- (A) -- (D) -- (E') -- (A);
\draw[dashed] (d') -- (D);
\draw[thick,fill=gray] (a') -- (E') -- (d') -- cycle;
\draw[thick] (b') -- (B) -- (C) -- (F') -- (B);
\draw[dashed] (c') -- (C);
\draw[thick,fill=gray] (b') -- (F') -- (c') -- cycle;
\draw[thick] (a) -- (b) -- (F) -- (E) -- (a);
\draw[dashed] (a) -- (d) -- (c) -- (b);
\draw[dashed] (d) -- (E);
\draw[dashed] (c) -- (F);
\end{tikzpicture}
\end{center}
\end{document}

代码可以简化为全局设置坐标系3d cs。如果您包括以下行

\makeatletter
\def\tikz@parse@splitxyz#1#2#3,#4,{%
    \def\@next{\tikz@scan@one@point#1(3d cs:{#2},{#3},{#4})}%
}
\makeatother

在序言中,那么您可以删除3d cs:所有坐标中的前缀,例如用 而(-\xa,0,-\za)不是 来书写(3d cs:-\xa,0,-\za)

相关内容