我想用 画一个八面体TikZ
,但我发现无处可下手,我试着画 6 个点然后正确地连接它们,但这种方法根本没有 3D 感,这是我的画:
\begin{tikzpicture}[scale=3]
\coordinate (A1) at (0,0);
\coordinate (A2) at (0.6,0.2);
\coordinate (A3) at (1,0);
\coordinate (A4) at (0.4,-0.2);
\coordinate (B1) at (0.5,0.5);
\coordinate (B2) at (0.5,-0.5);
\draw[dashed] (A1) -- (A2) -- (A3);
\draw (A1) -- (A4) -- (A3);
\draw[dashed] (B1) -- (A2) -- (B2);
\draw (B1) -- (A4) -- (B2);
\draw (B1) -- (A1) -- (B2) -- (A3) --cycle;
\end{tikzpicture}
我想知道如何才能给每个表面添加阴影,并使每个表面半透明,还能从观察者的角度调整不可见边缘的颜色更浅,就像维基百科页面上的那样:
所以我的问题是:如何完善我的绘图,使多面体看起来像 3D 对象?或者除了可以做到这一点TikZ
之外还有其他软件包吗?谢谢TikZ
答案1
您可以使用fill
和opacity
构造:
\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.6,0.2);
\coordinate (A3) at (1,0);
\coordinate (A4) at (0.4,-0.2);
\coordinate (B1) at (0.5,0.5);
\coordinate (B2) at (0.5,-0.5);
\begin{scope}[thick,dashed,,opacity=0.6]
\draw (A1) -- (A2) -- (A3);
\draw (B1) -- (A2) -- (B2);
\end{scope}
\draw[fill=cof,opacity=0.6] (A1) -- (A4) -- (B1);
\draw[fill=pur,opacity=0.6] (A1) -- (A4) -- (B2);
\draw[fill=greeo,opacity=0.6] (A3) -- (A4) -- (B1);
\draw[fill=greet,opacity=0.6] (A3) -- (A4) -- (B2);
\draw (B1) -- (A1) -- (B2) -- (A3) --cycle;
\end{tikzpicture}
\end{document}
答案2
TikZ 还具有 xyz 坐标系统,在这里非常有用。有一个很好的答案利用了这个功能:桌子,即 Tikz 中供人就餐的家具
这是绘制八面体的方法。要旋转它,请尝试使用x
和y
的z
选项tikzpicture
:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[line join=bevel,z=-5.5]
\coordinate (A1) at (0,0,-1);
\coordinate (A2) at (-1,0,0);
\coordinate (A3) at (0,0,1);
\coordinate (A4) at (1,0,0);
\coordinate (B1) at (0,1,0);
\coordinate (C1) at (0,-1,0);
\draw (A1) -- (A2) -- (B1) -- cycle;
\draw (A4) -- (A1) -- (B1) -- cycle;
\draw (A1) -- (A2) -- (C1) -- cycle;
\draw (A4) -- (A1) -- (C1) -- cycle;
\draw [fill opacity=0.7,fill=green!80!blue] (A2) -- (A3) -- (B1) -- cycle;
\draw [fill opacity=0.7,fill=orange!80!black] (A3) -- (A4) -- (B1) -- cycle;
\draw [fill opacity=0.7,fill=green!30!black] (A2) -- (A3) -- (C1) -- cycle;
\draw [fill opacity=0.7,fill=purple!70!black] (A3) -- (A4) -- (C1) -- cycle;
\end{tikzpicture}
\end{document}
答案3
PSTricks 可以处理这个问题。使用xelatex
或运行它latex->dvips->ps2pdf
\documentclass{article}
\usepackage[dvipsnames]{pstricks}
\usepackage{pst-solides3d}
\begin{document}
\begin{pspicture}(-2.5,-2)(2.5,2.5)
\psset{lightsrc=10 20 30,viewpoint=40 10 30 rtp2xyz,Decran=40}
\psSolid[object=octahedron,a=3,linecolor=blue,
opacity=0.6,hollow,hue=0 1,
action=draw**]
% \axesIIID(3,3,3)(4,4,4)
\end{pspicture}
\end{document}
答案4
向集合中添加另一种方法:开发版本pgfplots
支持“面片图”,其中用户提供要绘制的多边形集合:
\documentclass{minimal}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[axis equal]
\addplot3[fill opacity=0.7,patch,table/row sep=\\,
patch table={
0 1 4\\
1 2 4\\
2 3 4\\
3 0 4\\
0 1 5\\
1 2 5\\
2 3 5\\
3 0 5\\
}]
table
{
-1 0 0\\
0 -1 0\\
1 0 0\\
0 1 0\\
0 0 1\\
0 0 -1\\
};
\end{axis}
\end{tikzpicture}
\end{document}