帮助在 Tikz 中沿路径创建实体圆柱体以绘制晶格图

帮助在 Tikz 中沿路径创建实体圆柱体以绘制晶格图

我正在尝试使用 Tikz 绘制一个图表来显示钻石的晶格结构。它应该看起来像下面的插图参考

在此处输入图片描述

我设法找出了每个碳原子的位置。我将每个位置定义为坐标 (A、B、...Q),并设法绘制了原子,但我不喜欢显示哪些原子相连的线条的外观。

我的问题是线条彼此之间不够清晰。我不想画出简单的线条,而是画出将原子连接在一起的三维圆柱体,因为我认为这会让图像看起来更好。然而,我不知道如何让 Tikz 做到这一点。

这是我目前得到的信息。有人知道吗?

在此处输入图片描述

\documentclass[10pt]{article}
\usepackage{tikz}
\begin{document}
\pagestyle{empty}

\begin{tikzpicture}[scale = 1]

%points on cube

\coordinate (A) at (0,0,0);
\coordinate (B) at (0,0,4);
\coordinate (D) at (0,4,0);
\coordinate (C) at (0,4,4);
\coordinate (E) at (4,0,0);
\coordinate (F) at (4,0,4);
\coordinate (H) at (4,4,0);
\coordinate (G) at (4,4,4);

%center of faces

\coordinate (I) at (0,2,2); %center of face ABCD
\coordinate (J) at (4,2,2); %center of face EFGH
\coordinate (K) at (2,4,2); %center of face DCGH
\coordinate (L) at (2,0,2); %center of face ABFE
\coordinate (M) at (2,2,4); %center of face CBGF
\coordinate (N) at (2,2,0); %center of face DAEH

%connectors

\coordinate (O) at (1,1,3);
\coordinate (P) at (1,3,1);
\coordinate (Q) at (3,1,1);
\coordinate (R) at (3,3,3);
%place non-atom cube corners
\shadedraw [ball color= gray] (A) circle (0.1cm);
\shadedraw [ball color= gray] (C) circle (0.1cm);
\shadedraw [ball color= gray] (F) circle (0.1cm);
\shadedraw [ball color= gray] (H) circle (0.1cm);
\shadedraw [ball color= black] (B) circle (0.25cm);
\shadedraw [ball color= black] (D) circle (0.25cm);
\shadedraw [ball color= black] (E) circle (0.25cm);
\shadedraw [ball color= black] (G) circle (0.25cm);
%draw the center of each face
\shadedraw [ball color= red] (I) circle (0.25cm);
\shadedraw [ball color= red] (J) circle (0.25cm);
\shadedraw [ball color= red] (K) circle (0.25cm);
\shadedraw [ball color= red] (L) circle (0.25cm);
\shadedraw [ball color= red] (M) circle (0.25cm);
\shadedraw [ball color= red] (N) circle (0.25cm);
%connectors
\shadedraw [ball color= blue] (O) circle (0.25cm);
\shadedraw [ball color= blue] (P) circle (0.25cm);
\shadedraw [ball color= blue] (Q) circle (0.25cm);
\shadedraw [ball color= blue] (R) circle (0.25cm);
%draw cube
\draw [dashed] (A) -- (B);
\draw [dashed] (B) -- (C);
\draw [dashed] (C) -- (D);
\draw [dashed] (D) -- (A);
\draw [dashed] (E) -- (F);
\draw [dashed] (F) -- (G);
\draw [dashed] (G) -- (H);
\draw [dashed] (H) -- (E);
\draw [dashed] (A) -- (E);
\draw [dashed] (B) -- (F);
\draw [dashed] (C) -- (G);
\draw [dashed] (D) -- (H);
%connections from faces to O
\draw [very thick] (B) -- (O);
\draw [very thick] (I) -- (O);
\draw [very thick] (M) -- (O);
\draw [very thick] (L) -- (O);
%connections from faces to P
\draw [very thick] (N) -- (P);
\draw [very thick] (I) -- (P);
\draw [very thick] (D) -- (P);
\draw [very thick] (K) -- (P);
%connections from faces to Q
\draw [very thick] (E) -- (Q);
\draw [very thick] (J) -- (Q);
\draw [very thick] (N) -- (Q);
\draw [very thick] (L) -- (Q);
%connections from faces to R
\draw [very thick] (G) -- (R);
\draw [very thick] (M) -- (R);
\draw [very thick] (J) -- (R);
\draw [very thick] (K) -- (R);
\end{tikzpicture}
\end{document}

答案1

在此处输入图片描述

该模型采用圆柱体连接,渲染如下Asymptotecr.asy

size(300);
import solids;

currentprojection=orthographic (
camera=(8,5,4),
up=(0,0,1),
target=(2,2,2),
zoom=0.5
);

// save predefined 2D orientation vectors
pair NN=N;
pair SS=S;
pair EE=E;
pair WW=W;

//%points on cube

triple A = (0,0,0);
triple B = (0,0,4);
triple D = (0,4,0);
triple C = (0,4,4);
triple E = (4,0,0);
triple F = (4,0,4);
triple H = (4,4,0);
triple G = (4,4,4);

triple[] cubicCornerA={  
  A,C,F,H,
};

triple[] cubicCornerB={  
  B,D,E,G,
};


//%center of faces

triple I = (A+B+C+D)/4; //%center of face ABCD
triple J = (E+F+G+H)/4; //%center of face EFGH
triple K = (D+C+G+H)/4; //%center of face DCGH
triple L = (A+B+F+E)/4; //%center of face ABFE
triple M = (C+B+G+F)/4; //%center of face CBGF
triple N = (D+A+E+H)/4; //%center of face DAEH

triple[] faceCenter={  
  I,J,K,L,M,N,
};


//%connectors
triple O = (1,1,3);
triple P = (1,3,1);
triple Q = (3,1,1);
triple R = (3,3,3);

triple[] connectors={  
  O,P,Q,R,
};

//%place non-atom cube corners

real cornerAR=0.05;
real cornerBR=0.2;
real faceCR=0.2;
real connR=faceCR;

draw(A--B--C--D--cycle,dashed);
draw(E--F--G--H--cycle,dashed);
draw(A--E,dashed);
draw(B--F,dashed);
draw(C--G,dashed);
draw(D--H,dashed);

real cylR=0.062;

void Draw(guide3 g,pen p=currentpen){
  draw(
    cylinder(
      point(g,0),cylR,arclength(g),point(g,1)-point(g,0)
    ).surface(
               new pen(int i, real j){
                 return p;
               }
             )
  );
}

//%connections from faces to O
pen connectPen=lightgray;
Draw(B--O,connectPen);
Draw(I--O,connectPen);
Draw(M--O,connectPen);
Draw(L--O,connectPen);

//%connections from faces to P
Draw(N--P,connectPen);
Draw(I--P,connectPen);
Draw(D--P,connectPen);
Draw(K--P,connectPen);

//%connections from faces to Q
Draw(E--Q,connectPen);
Draw(J--Q,connectPen);
Draw(N--Q,connectPen);
Draw(L--Q,connectPen);

//%connections from faces to R
Draw(G--R,connectPen);
Draw(M--R,connectPen);
Draw(J--R,connectPen);
Draw(K--R,connectPen);

void drawSpheres(triple[] C, real R, pen p=currentpen){
  for(int i=0;i<C.length;++i){
    draw(sphere(C[i],R).surface(
                        new pen(int i, real j){return p;}
                        )
    );
  }
}

drawSpheres(cubicCornerA,cornerAR,lightgray);
drawSpheres(cubicCornerB,cornerBR,darkgray);
drawSpheres(faceCenter,faceCR,red);
drawSpheres(connectors,connR,lightblue);

使用 进行处理asy -f pdf cr.asy以获得交互式(仅限 Adob​​e Reader)独立版cr.pdf,或使用asy -f pdf -noprc -render=0 cr.asy 以获得普通版cr.pdf,或asy -f png -render=5 cr.asy 获得较小的光栅图像cr.png

相关内容