Como faço uma rede de cristal 3D usando TikZ?

Como faço uma rede de cristal 3D usando TikZ?

Há algum tempo venho tentando fazer uma rede de cristal 3D decente usando LaTeX e TikZ e finalmente consegui encontrar algum código onde alguém havia feito um código perfeito. No entanto, não importa o que eu tente, em vez de uma rede 3D, recebo uma confusão de peças esféricas orientadas aleatoriamente.

Resultado pretendido Meu resultado

Abaixo está o código que usei (https://github.com/dog-blood/utterly-unorganized-latex-code/tree/main/Chem/Unit%203%20Gasses):

\begin{tikzpicture}[isometric view,rotate around z=180,line cap=round,line join=round,scale=0.8]
    
    
    \tikzset{xy/.style={canvas is xy plane at       z=\a,shift={(0.5*\a,0.5*\a)},rotate=90*\i,fill=red1,draw=pag!30},
        xz/.style={canvas is xz plane at y=\a,shift={(0.5*\a,0.5*\a)},rotate=90*\i,fill=red1,draw=pag!30},
        yz/.style={canvas is yz plane at x=\a,shift={(0.5*\a,0.5*\a)},rotate=90*\i,fill=red1,draw=pag!30},
        my ball/.style={top color=red2, bottom color=red2}}
    
    
    \def\a{3} % edge length
    \pgfmathsetmacro\r{0.25*sqrt(2.5)*\a} % sphere radius
    % background
    \foreach\i in {0,120,240}
    \draw[rotate=\i,color=pag!,my ball] (\a,0,0) --++ (0,\r,0) arc (90:135:\r) arc (0:60:\r cm)
    {[canvas is xz plane at y=0] arc (135:90:\r)} -- cycle;
    % sphere (center)
    \draw[my ball, color=pag]  (0.5*\a,0.5*\a,0.5*\a) circle (\r cm);
    % foreground
    \foreach\i in {0,120,240}
    \draw[rotate=\i,my ball,color=pag] (\a,\a,0) --++ (60:\r cm) arc (60:120:\r cm) -- cycle;
    
    \foreach\s in {xy,xz,yz} \foreach\i in {1,...,4}
    \draw[\s] (45:{\a*sin(45)}) --++ (180:\r) arc (180:270:\r) -- cycle;
\end{tikzpicture}

Responder1

Descobri meu erro, era de manhã cedo e esqueci de acrescentar:

\usetikzlibrary{perspective}

informação relacionada