答案1
以下解决方案使用tikz3d.sty
TeX.SX 启动板中的实验性(?)包。要安装它,请执行以下操作:
- 下载
tikz3d.dtx
自http://bazaar.launchpad.net/~tex-sx/tex-sx/development/view/head:/tikz3d.dtx。 dtx
对要提取的文件运行 pdflatextikz3d.sty
。pdflatex tikz3d.dtx
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)
。