tikz-3dplot 中的无序图层(3d 效果)

tikz-3dplot 中的无序图层(3d 效果)

问题的简短表述

有没有办法根据与观察者位置的距离对 tikz-3dplot 中的图层进行排序?图片应该看起来逼真,以便给读者一些直觉。但我更喜欢不重新排列图形所有项目的解决方案。

例子

以下工作示例未显示正确的 3D 视图,即第二张图片中的球顺序错误:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usepackage{tikz-3dplot}

\begin{document}

\begin{tikzpicture}
 \node[fill=red,circle] (c1) at (0,0,0) {};
 \node[fill=gray,circle] (c2) at (1,0,0) {};
 \node[fill=blue,circle] (c3) at (1,0,1) {};
 \node[fill=green,circle] (c4) at (0,0,1) {};
 \node[fill=black,circle] (c5) at (0,1,0) {};
 \node[fill=orange,circle] (c6) at (1,1,0) {};
 \node[fill=yellow,circle] (c7) at (1,1,1) {};
 \node[fill=magenta,circle] (c8) at (0,1,1) {};
 \draw[line width=2pt] (c1) -- (c2) -- (c3) -- (c4) -- (c1);
 \draw[line width=2pt] (c5) -- (c6) -- (c7) -- (c8) -- (c5);
 \draw[line width=2pt] (c1) -- (c5);
 \draw[line width=2pt] (c2) -- (c6);
 \draw[line width=2pt] (c3) -- (c7);
 \draw[line width=2pt] (c4) -- (c8);
\end{tikzpicture}

\tdplotsetmaincoords{45}{0}
\begin{tikzpicture}[tdplot_main_coords]
 \node[fill=red,circle] (c1) at (0,0,0) {};
 \node[fill=gray,circle] (c2) at (1,0,0) {};
 \node[fill=blue,circle] (c3) at (1,0,1) {};
 \node[fill=green,circle] (c4) at (0,0,1) {};
 \node[fill=black,circle] (c5) at (0,1,0) {};
 \node[fill=orange,circle] (c6) at (1,1,0) {};
 \node[fill=yellow,circle] (c7) at (1,1,1) {};
 \node[fill=magenta,circle] (c8) at (0,1,1)
 \draw[line width=2pt] (c1) -- (c2) -- (c3) -- (c4) -- (c1);
 \draw[line width=2pt] (c5) -- (c6) -- (c7) -- (c8) -- (c5);
 \draw[line width=2pt] (c1) -- (c5);
 \draw[line width=2pt] (c2) -- (c6);
 \draw[line width=2pt] (c3) -- (c7);
 \draw[line width=2pt] (c4) -- (c8);
\end{tikzpicture}

\tdplotsetmaincoords{54.7}{45}
\begin{tikzpicture}[tdplot_main_coords]
 \node[fill=red,circle] (c1) at (0,0,0) {};
 \node[fill=gray,circle] (c2) at (1,0,0) {};
 \node[fill=blue,circle] (c3) at (1,0,1) {};
 \node[fill=green,circle] (c4) at (0,0,1) {};
 \node[fill=black,circle] (c5) at (0,1,0) {};
 \node[fill=orange,circle] (c6) at (1,1,0) {};
 \node[fill=yellow,circle] (c7) at (1,1,1) {};
 \node[fill=magenta,circle] (c8) at (0,1,1) {};
 \draw[line width=2pt] (c1) -- (c2) -- (c3) -- (c4) -- (c1);
 \draw[line width=2pt] (c5) -- (c6) -- (c7) -- (c8) -- (c5);
 \draw[line width=2pt] (c1) -- (c5);
 \draw[line width=2pt] (c2) -- (c6);
 \draw[line width=2pt] (c3) -- (c7);
 \draw[line width=2pt] (c4) -- (c8);
\end{tikzpicture}

\end{document}

进一步展望

也许需要注意的是,我想使用不同的视角(的特征[tikz-3dplot][1]),而无需根据出现的层对整个晶体进行排序。

答案1

使用 PSTricks 的解决方案。使用xelatex(动画需要一些时间) 运行它或使用latex->dvips->ps2pdf

\documentclass[pstricks]{standalone}
\usepackage{pst-solides3d}

\begin{document}

\psset{unit=2}
\multido{\iA=0+10}{38}{%
\begin{pspicture}[solidmemory](-2,-2)(2,2)
\psset{viewpoint=100 \iA\space 20 rtp2xyz,Decran=100}
\psSolid[object=cube,a=1,action=draw,name=my_cube]
\psset{object=point,definition=solidgetsommet,R=10}
\psSolid[args=my_cube 0,linecolor=red]
\psSolid[args=my_cube 1,linecolor=gray]
\psSolid[args=my_cube 2,linecolor=blue]
\psSolid[args=my_cube 3,linecolor=green]
\psSolid[args=my_cube 4,linecolor=black]
\psSolid[args=my_cube 5,linecolor=orange]
\psSolid[args=my_cube 6,linecolor=yellow]
\psSolid[args=my_cube 7,linecolor=magenta]
\end{pspicture}
\newpage}
\multido{\iA=0+10}{36}{%
\begin{pspicture}[solidmemory](-2,-2)(2,2)
\psset{viewpoint=100 20 \iA\space rtp2xyz,Decran=100}
\psSolid[object=cube,a=1,action=draw,name=my_cube]
\psset{object=point,definition=solidgetsommet,R=10}
\psSolid[args=my_cube 0,linecolor=red]
\psSolid[args=my_cube 1,linecolor=gray]
\psSolid[args=my_cube 2,linecolor=blue]
\psSolid[args=my_cube 3,linecolor=green]
\psSolid[args=my_cube 4,linecolor=black]
\psSolid[args=my_cube 5,linecolor=orange]
\psSolid[args=my_cube 6,linecolor=yellow]
\psSolid[args=my_cube 7,linecolor=magenta]
\end{pspicture}
\newpage}

\end{document}

在此处输入图片描述

相关内容