看到这个之后回答,我尝试使用圆柱连接器绘制两种颜色的结合,如下图所示:
所以我使用了给定的代码但出现错误(我使用了 Texstudio 和 Texmaker)。
\documentclass{standalone}
\usepackage{asypictureB}
\begin{document}
\begin{asypicture}{name=crystal}
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;
triple C1 = (-3.19898,0.68575,-0.09137);
triple N1 = (-2.00788,-0.15303,-0.05472);
triple H1 = (-3.17155,1.39571,-0.92422);
triple H2 = (-3.31563,1.23754,0.84706);
triple H3 = (-4.08519,0.05549,-0.21396);
triple C2 = (-0.78815,0.67831,0.01256);
triple H4 = (-1.95362,-0.69266,-0.92177);
triple C3 = (0.47237,-0.18670,0.21998);
triple H5 = (-0.86520,1.39211,0.84227);
triple H6 = (-0.69535,1.26040,-0.91400);
triple C4 = (1.73163,0.67172,0.09304);
triple N2 = (0.51467,-1.32801,-0.73516);
triple H7 = (0.46502,-0.59296,1.23918);
triple H8 = (1.39360,-1.82407,-0.57104);
triple H9 = (-0.23067,-1.96899,-0.46111);
triple O1 = (1.80456,1.88884,0.13111);
triple O2 = (2.86188,-0.07112,0.00360);
triple H10 = (3.57354,0.59879,-0.06651);
triple[] Carbon={
C1,C2,C3,C4
};
triple[] Nitrogen={
N1,N2
};
triple[] Oxygen={
O1,O2
};
triple[] Hydrogen={
H1,H2,H3,H4,H5,H6,H7,H8,H9,H10
};
//%place non-atom cube corners
real cylR=0.15;
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;
}
)
);
}
void DrawTwoColors(guide3 g,pen p=currentpen,pen q=currentpen){
draw(
cylinder(
point(g,0),cylR,arclength(g)/2,point(g,1)-point(g,0)
).surface(
new pen(int i, real j){
return p;
}
)
);
draw(
cylinder(
point(g,1),cylR,arclength(g)/2,point(g,0)-point(g,1)
).surface(
new pen(int i, real j){
return q;
}
)
);
}
pen connectPen=lightgray;
pen connectPenH=lightgray;
pen connectPenN=lightblue;
pen connectPenO=red;
pen connectPenC=darkgray;
//Draw(C1--N1,connectPen);
DrawTwoColors(C1--N1,connectPenC,connectPenN);
Draw(N1--C2,connectPen);
Draw(C2--C3,connectPen);
Draw(C3--C4,connectPen);
//Draw(C4--O1,connectPen);
DrawTwoColors(C4--O1,connectPenC,connectPenO);
Draw(H1--C1,connectPen);
Draw(H2--C1,connectPen);
Draw(H3--C1,connectPen);
Draw(H4--N1,connectPen);
Draw(C2--H5,connectPen);
Draw(C2--H6,connectPen);
Draw(C3--H7,connectPen);
Draw(C3--N2,connectPen);
Draw(N2--H8,connectPen);
Draw(N2--H9,connectPen);
//Draw(C4--O2,connectPen);
DrawTwoColors(C4--O2,connectPenC,connectPenO);
Draw(O2--H10,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;}
)
);
}
}
real radC=0.45;
real radN=0.6;
real radO=0.6;
real radH=0.3;
drawSpheres(Carbon,radC,darkgray);
drawSpheres(Nitrogen,radN,lightblue);
drawSpheres(Oxygen,radO,red);
drawSpheres(Hydrogen,radH,lightgray);
\end{asypicture}
\end{document}
@quark67 我仍然遇到同样的错误。
这是我所有步骤的截图:
1-当我选择“构建并查看”时,我得到:
2- 当我选择工具▶︎ 用户▶︎ 1:Asypicture时:
我收到此错误:
@quark67 是的,我在 Windows 10 上,这是我的当前页面:
答案1
在 TeXstudio 中,创建包含代码的文件并将其命名,例如test-crystal.tex
。
转到 TeXstudio 设置,然后选择 Buid。然后点击+ 添加按钮:
在(1)中例如写:Asypicture
在(2)中写:txs:///pdflatex/[--shell-escape]
。
然后点击按钮好的(在 Mac 版本中位于设置窗口的右下角)以验证更改。
然后选择工具▶︎ 用户▶︎ 1:Asypicture。
该文件的目录中还有一堆文件test-crystal.tex
。在这些文件中,.pdf 文件(是的,还有一个名为的文件,test-crystal-crystal_errors.txt
但这里是空白的):