나는 한동안 LaTeX와 TikZ를 사용하여 괜찮은 3D 결정 격자를 만들려고 노력해 왔으며 마침내 누군가가 완벽한 코드를 만든 코드를 찾을 수 있었습니다. 그러나 아무리 노력해도 3D 격자 대신 무작위 방향의 구형 부품이 엉망이 됩니다.
아래는 내가 사용한 코드입니다(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}
답변1
내 실수를 발견했습니다. 이른 아침이었고 다음을 추가하는 것을 잊어버렸습니다.
\usetikzlibrary{perspective}