使用 Tikz 绘制逼真的钻石 3D 晶体结构

使用 Tikz 绘制逼真的钻石 3D 晶体结构

在此处输入图片描述

我可以画出同样的图片吗(来自绘制逼真的 3D 晶体结构(钻石))在乳胶中使用 tikz?

这就是我至今得到的。

在此处输入图片描述

来自代码:

    \begin{tikzpicture}
    \tdplotsetmaincoords{0}{60}{140}    
    \pgfmathsetmacro{\d}{2.5}
    \draw[] (0,0,0) -- (4*\d,0,0) -- (4*\d,4*\d,0) -- (0,4*\d,0) -- (0,0,0);
    \draw[] (0,0,4*\d) -- (4*\d,0,4*\d) -- (4*\d,4*\d,4*\d) -- (0,4*\d,4*\d) -- (0,0,4*\d);
    \draw[] (0,0,4*\d) -- (4*\d,0,4*\d) -- (4*\d,0,0) -- (0,0,0) -- (0,0,4*\d);
    \draw[] (0,4*\d,4*\d) -- (4*\d,4*\d,4*\d) -- (4*\d,4*\d,0) -- (0,4*\d,0) -- (0,4*\d,4*\d);
    
    \coordinate (Aa) at (0,0,0); 
    \coordinate (Ab) at (4*\d,0,0); 
    \coordinate (Ac) at (0,4*\d,0);
    \coordinate (Ad) at (4*\d,4*\d,0);   
    \coordinate (Ae) at  (2*\d,2*\d,0);
    \coordinate (Ba) at  (\d,\d,\d);
    \coordinate (Bb) at  (3*\d,3*\d,\d);        
    \coordinate (Ca) at  (2*\d,0,2*\d);
    \coordinate (Cb) at  (0,2*\d,2*\d); 
    \coordinate (Cc) at (4*\d,2*\d,2*\d);   
    \coordinate (Cd) at  (2*\d,4*\d,2*\d);
    \coordinate (Da) at  (3*\d,\d,3*\d);
    \coordinate (Db) at  (\d,3*\d,3*\d);
    \coordinate (Ea) at  (0,0,4*\d);
    \coordinate (Eb) at  (4*\d,0,4*\d);
    \coordinate (Ec) at  (0,4*\d,4*\d);
    \coordinate (Ed) at  (4*\d,4*\d,4*\d);
    \coordinate (Ee) at  (2*\d,2*\d,4*\d);
\begin{scope}[line width=10,shade,shading angle=30]
    \draw[] (Ba) -- (Aa);
    \draw[] (Ba) -- (Ae);
    \draw[] (Bb) -- (Ae);
    \draw[] (Bb) -- (Ad);
    \draw[] (Ba) -- (Ca);
    \draw[] (Bb) -- (Cc);
    \draw[] (Bb) -- (Cd);
    \draw[] (Da) -- (Ca);
    \draw[] (Da) -- (Cc);
    \draw[] (Db) -- (Cb);
    \draw[] (Db) -- (Cd);
    \draw[] (Da) -- (Eb);
    \draw[] (Da) -- (Ee);
    \draw[] (Db) -- (Ee);
    \draw[] (Db) -- (Ec);
\end{scope}
\node[draw,circle,minimum size=1cm,shading=ball] at (Aa) {}; 
\node[draw,circle,minimum size=1cm,shading=ball] at (Ab) {}; 
\node[draw,circle,minimum size=1cm,shading=ball] at (Ac) {};
\node[draw,circle,minimum size=1cm,shading=ball] at (Ad) {};     
\node[draw,circle,minimum size=1cm,shading=ball] at (Ae) {};
\node[draw,circle,minimum size=1cm,shading=ball] at (Ba) {};
\node[draw,circle,minimum size=1cm,shading=ball] at (Bb) {};        
\node[draw,circle,minimum size=1cm,shading=ball] at (Ca) {};
\node[draw,circle,minimum size=1cm,shading=ball] at (Cb) {};    
\node[draw,circle,minimum size=1cm,shading=ball] at (Cc) {};    
\node[draw,circle,minimum size=1cm,shading=ball] at (Cd) {};
\node[draw,circle,minimum size=1cm,shading=ball] at (Da) {};
\node[draw,circle,minimum size=1cm,shading=ball] at (Db) {};
\node[draw,circle,minimum size=1cm,shading=ball] at (Ea) {};
\node[draw,circle,minimum size=1cm,shading=ball] at (Eb) {};
\node[draw,circle,minimum size=1cm,shading=ball] at (Ec) {};
\node[draw,circle,minimum size=1cm,shading=ball] at (Ed) {};
\node[draw,circle,minimum size=1cm,shading=ball] at (Ee) {};
\end{tikzpicture}

答案1

解决方案草图Gene Ressler。以下草图代码的输出是 5542 行的 tikz 代码。

special|\tikzstyle{BondStyle}=[thin,double=lightgray,double distance=5pt]
\tikzstyle{BordCellStyle}=[line width=6pt,lightgray!50!yellow,line cap=round]
\tikzstyle{AtomStyle}=[fill opacity=0,draw opacity=0]
|[lay=under]

def d 2.5
def O (0,0,0)
def Aa [0,0,0]
def Ab [4*d,0,0]
def Ac [0,4*d,0]
def Ad [4*d,4*d,0]
def Ae [2*d,2*d,0]
def Ba [d,d,d]
def Bb [3*d,3*d,d]
def Ca [2*d,0,2*d]
def Cb [0,2*d,2*d]
def Cc [4*d,2*d,2*d]
def Cd [2*d,4*d,2*d]
def Da [3*d,d,3*d]
def Db [d,3*d,3*d]
def Ea [0,0,4*d]
def Eb [4*d,0,4*d]
def Ec [0,4*d,4*d]
def Ed [4*d,4*d,4*d]
def Ee [2*d,2*d,4*d]

def pAa [Aa]+(O)
def pAb [Ab]+(O)
def pAc [Ac]+(O)
def pAd [Ad]+(O)
def pAe [Ae]+(O)
def pBa [Ba]+(O)
def pBb [Bb]+(O)
def pCa [Ca]+(O)
def pCb [Cb]+(O)
def pCc [Cc]+(O)
def pCd [Cd]+(O)
def pDa [Da]+(O)
def pDb [Db]+(O)
def pEa [Ea]+(O)
def pEb [Eb]+(O)
def pEc [Ec]+(O)
def pEd [Ed]+(O)
def pEe [Ee]+(O)

def tras rotate(10,[0,1,0]) then rotate(23,[1,0,0])

def bondstyle [line style=BondStyle]

def cellstyle [line style=BordCellStyle]

def rC 0.5

def atom {sweep[fill style=AtomStyle]{60,rotate(360/60,[0,0,1])} 
sweep{10,rotate(180/10,[1,0,0])}(0,0,-rC)}

def ret {

line[bondstyle] (pAa)(pBa)
line[bondstyle] (pAe)(pBa)
line[bondstyle] (pAe)(pBb)
line[bondstyle] (pAd)(pBb)

line[bondstyle] (pCa)(pBa)
line[bondstyle] (pCc)(pBb)
line[bondstyle] (pCd)(pBb)
line[bondstyle] (pDa)(pCa)

line[bondstyle] (pDa)(pCc)
line[bondstyle] (pDb)(pCb)
line[bondstyle] (pDb)(pCd)
line[bondstyle] (pEb)(pDa)

line[bondstyle] (pEc)(pDb)
line[bondstyle] (pEe)(pDa)
line[bondstyle] (pEe)(pDb)

line[cellstyle] (pAa)(pAb)
line[cellstyle] (pAb)(pAd)
line[cellstyle] (pAc)(pAd)
line[cellstyle] (pAa)(pAc)

line[cellstyle] (pAa)(pEa)
line[cellstyle] (pAb)(pEb)
line[cellstyle] (pAc)(pEc)
line[cellstyle] (pAd)(pEd)

line[cellstyle] (pEa)(pEb)
line[cellstyle] (pEb)(pEd)
line[cellstyle] (pEc)(pEd)
line[cellstyle] (pEa)(pEc)

put{translate([Aa])}{atom}
put{translate([Ab])}{atom}
put{translate([Ac])}{atom}
put{translate([Ad])}{atom}
put{translate([Ae])}{atom}
put{translate([Ba])}{atom}
put{translate([Bb])}{atom}
put{translate([Ca])}{atom}
put{translate([Cb])}{atom}
put{translate([Cc])}{atom}
put{translate([Cd])}{atom}
put{translate([Da])}{atom}
put{translate([Db])}{atom}
put{translate([Ea])}{atom}
put{translate([Eb])}{atom}
put{translate([Ec])}{atom}
put{translate([Ed])}{atom}
put{translate([Ee])}{atom}

}

def npAa [[tras]].(pAa)
def npAb [[tras]].(pAb)
def npAc [[tras]].(pAc)
def npAd [[tras]].(pAd)
def npAe [[tras]].(pAe)

def npBa [[tras]].(pBa)
def npBb [[tras]].(pBb)

def npCa [[tras]].(pCa)
def npCb [[tras]].(pCb)
def npCc [[tras]].(pCc)
def npCd [[tras]].(pCd)

def npDa [[tras]].(pDa)
def npDb [[tras]].(pDb)

def npEa [[tras]].(pEa)
def npEb [[tras]].(pEb)
def npEc [[tras]].(pEc)
def npEd [[tras]].(pEd)
def npEe [[tras]].(pEe)

special|
\fill[shading=ball,ball color=black] #1 circle[radius=14pt];
|[lay=in](npAa)

special|
\fill[shading=ball,ball color=black] #1 circle[radius=14pt];
|[lay=in](npAb)

special|
\fill[shading=ball,ball color=black] #1 circle[radius=14pt];
|[lay=in](npAc)

special|
\fill[shading=ball,ball color=black] #1 circle[radius=14pt];
|[lay=in](npAd)

special|
\fill[shading=ball,ball color=black] #1 circle[radius=14pt];
|[lay=in](npAe)

special|
\fill[shading=ball,ball color=black] #1 circle[radius=14pt];
|[lay=in](npBa)

special|
\fill[shading=ball,ball color=black] #1 circle[radius=14pt];
|[lay=in](npBb)

special|
\fill[shading=ball,ball color=black] #1 circle[radius=14pt];
|[lay=in](npCa)

special|
\fill[shading=ball,ball color=black] #1 circle[radius=14pt];
|[lay=in](npCb)

special|
\fill[shading=ball,ball color=black] #1 circle[radius=14pt];
|[lay=in](npCc)

special|
\fill[shading=ball,ball color=black] #1 circle[radius=14pt];
|[lay=in](npCd)

special|
\fill[shading=ball,ball color=black] #1 circle[radius=14pt];
|[lay=in](npDa)

special|
\fill[shading=ball,ball color=black] #1 circle[radius=14pt];
|[lay=in](npDb)

special|
\fill[shading=ball,ball color=black] #1 circle[radius=14pt];
|[lay=in](npEa)

special|
\fill[shading=ball,ball color=black] #1 circle[radius=14pt];
|[lay=in](npEb)

special|
\fill[shading=ball,ball color=black] #1 circle[radius=14pt];
|[lay=in](npEc)

special|
\fill[shading=ball,ball color=black] #1 circle[radius=14pt];
|[lay=in](npEd)

special|
\fill[shading=ball,ball color=black] #1 circle[radius=14pt];
|[lay=in](npEe)

put{[[tras]]}{ret}



global { language tikz }

编译 tikz 代码你将获得:

钻石三维结构

相关内容