如何使立方体正确呈现其隐藏线的虚线?

如何使立方体正确呈现其隐藏线的虚线?

第一次紧急尝试如下。我希望每当我在动画中更改相机时,隐藏线都会自动用虚线渲染。如何做到这一点?

在此处输入图片描述

\documentclass[border=\dimexpr355pt/113\relax]{standalone} 
\usepackage{filecontents}
\usepackage{asymptote}
\begin{filecontents*}{testfile.asy}
import three;
settings.render=0;
currentprojection=perspective(3,-4,4,center=true);
    draw((0,0,0)--(0,2,0));
    draw((0,0,0)--(2,0,0));
    draw((2,2,0)--(0,2,0));
    draw((2,2,0)--(2,0,0)); 
    draw((0,0,0)--(0,0,2));
    draw((0,2,0)--(0,2,2));
    draw((2,0,0)--(2,0,2));
    draw((2,2,0)--(2,2,2));
    draw((0,0,2)--(0,2,2));
    draw((0,0,2)--(2,0,2));
    draw((2,2,2)--(0,2,2));
    draw((2,2,2)--(2,0,2));
\end{filecontents*}
\begin{document}
    \asyinclude[height=25mm,inline=true,attach=false,viewportwidth=4cm,viewportheight=25mm]{testfile.asy}
\end{document}

答案1

这是 Tikz 版本。

  \documentclass[tikz,border=3mm]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{3dtools}
\begin{document}
    \pgfdeclarelayer{background} 
    \pgfdeclarelayer{foreground}
    \pgfsetlayers{background,main,foreground} 
    \foreach \Angle in {5,15,...,355}
    {\begin{tikzpicture}[same bounding box=A,line cap=round,line join=round,visible/.style={draw,solid}, hidden/.style={draw, dashed}, 3d/install view={phi=\Angle,psi=0,theta=70},declare function={a=2;} ]
            \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)
            [3d coordinate={(O)=0.5*(A)+0.5*(G)}];
            \foreach \p in {A,B,C,D,E,F,G,H,O}
            {\draw[fill=black] (\p) circle (1.2 pt);}
            \foreach \p/\g in {A/-90,B/-90,C/-90,D/90,E/90,F/90,G/90,H/90,O/-90}
            {\path (\p)+(\g:3mm) node{$\p$};}
            \tikzset{3d/polyhedron/.cd,O={(O)},
                fore layer=foreground,back layer=background,
                back/.style={3d/polyhedron/complete dashes,fill=none},
                fore/.style={3d/visible,fill=none},%3d/polyhedron/edges have complete dashes=false
                draw face with corners={{(A)},{(B)},{(C)},{(D)}},
                draw face with corners={{(A)},{(B)},{(F)},{(E)}},
            draw face with corners={{(E)},{(F)},{(G)},{(H)}},
                draw face with corners={{(C)},{(D)},{(H)},{(G)}},
                draw face with corners={{(A)},{(E)},{(H)},{(D)}},
                draw face with corners={{(B)},{(C)},{(G)},{(F)}}}
        \end{tikzpicture}}
\end{document}  

在此处输入图片描述

相关内容