TikZ-3Dplot – How to Automatically Draw Dashed Lines of a Cube When Rotated

tikz-3dplot

I draw this cube, and dashed lines I have to draw by hand.

enter image description here

\documentclass[tikz,border=3mm]{standalone}
\usepackage{tikz-3dplot}
\begin{document}
    \tdplotsetmaincoords{60}{120}
    \begin{tikzpicture}[tdplot_main_coords,declare function={a=3;
        }]
        \path 
        (a,-a,-a) coordinate (A)
        (a,a,-a) coordinate (B)
        (-a,a,-a) coordinate (C)
        (-a,-a,-a) coordinate (D)
        (a,-a,a) coordinate (E)
        (a,a,a) coordinate (F)
        (-a,a,a) coordinate (G)
        (-a,-a,a) coordinate (H)
        (0,0,0)  coordinate (O)
        ;
        \draw (E) -- (A) -- (B) --(C) -- (G) -- (H) -- (E) (E) -- (F) -- (G) (B) -- (F);
            \draw[dashed] (A) -- (D) -- (C) (D) -- (H);
        %\path foreach \p/\g in {A/-90,B/90,C/0,D/0,E/0,F/0,G/0,H/0}{(\p)node{}+(\g:2.5mm) node{$\p$}}; 
    
    \end{tikzpicture}
\end{document}  

How to draw dashed lines automatically of a cube when I rotate the cube like this

Best Answer

This is the first time I use pst-solides3d. About TikZ, you can see here

\documentclass[pstricks]{standalone}
\usepackage{pst-solides3d}
\begin{document}
    \multido{\iA=0+5}{25}{%
        \psset{viewpoint=50 -45 \iA\space add 30 rtp2xyz,Decran=50}
    \begin{pspicture}[solidmemory](-4,-4)(4,4)
        \psSolid[object=cube,a=2.5,action=draw*,fillcolor=green!50!white]
    \end{pspicture}%
}
\end{document}

enter image description here

Use action=draw.

\documentclass[pstricks]{standalone}
\usepackage{pst-solides3d}
\begin{document}
    \multido{\iA=0+5}{50}{%
        \psset{viewpoint=50 -45 \iA\space add 30 rtp2xyz,Decran=50}
    \begin{pspicture}[solidmemory](-4,-4)(4,4)
        \psSolid[object=cube,a=2.5,action=draw,fillcolor=green!50!white]
    \end{pspicture}%
}
\end{document}

enter image description here