Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Short formulation of the question

Is there a way to order layers in tikz-3dplot according to their distance to the observer's position? The picture should look realistic in order to give some intuition to the reader. But I prefer a solution without rearranging all items of the graphic.

Example

The following working example does not show the correct 3D view, i.e. the balls are wrong ordered in the second picture:

\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}

Further outlook

Maybe it is crucial to note that I want to use different view angles (feature of [tikz-3dplot][1]) without ordering the entire crystal with respect to the appearing layers.

share|improve this question

1 Answer 1

up vote 3 down vote accepted

a solution with PSTricks. Run it with xelatex (takes some time for the animation) or use 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}

enter image description here

share|improve this answer
    
Thank you for this nice animation, but I want to include it into a report - animation is probably not the best way to implement this. But I will keep in mind for later presentations! –  strpeter Oct 15 '13 at 10:10
2  
The animation has no sense here! It should only show the that every viewpoint is possible. –  Herbert Oct 15 '13 at 10:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.