Ich versuche schon seit einiger Zeit, mit LaTeX und TikZ ein ordentliches 3D-Kristallgitter zu erstellen, und habe nun endlich Code gefunden, in dem jemand ein perfektes Gitter erstellt hat. Doch egal, was ich versuche, statt eines 3D-Gitters erhalte ich ein Durcheinander aus zufällig ausgerichteten sphärischen Teilen.
Unten ist der Code, den ich verwendet habe (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}
Antwort1
Ich habe meinen Fehler gefunden. Es war früh am Morgen und ich habe vergessen hinzuzufügen:
\usetikzlibrary{perspective}