学习编程的一个有效方式是去读别人写的代码.我学习了这里的代码.代码虽多,但是简单.代码如下(稍微做了修改):
import settings; pdfviewer="/usr/bin/okular"; outformat="pdf"; size(400); texpreamble("\usepackage{CJK}\AtBeginDocument{\begin{CJK}{UTF8}{gbsn}}\AtEndDocument{\clearpage\end{CJK}}"); //主线轮廓 pair a1=(1.5,7),a2=(1.5,6),a3=(2.2,6); pair b1=(2.2,7),b2=(2.2,5.5),b3=(2.9,5.5); pair c1=(2.9,6.3),c2=(2.9,5.1),c3=(3.6,5.1); pair d1=(3.6,5.7),d2=(3.6,4.6),d3=(4.3,4.6); draw(a1--a2--a3); draw(b1--b2--b3); draw(c1--c2--c3); draw(d1--d2--d3); pair e1=(4.3,5.4),e2=(4.3,4.3),e3=(5,4.3); pair f1=(5,5),f2=(5,4),f3=(5.7,4); pair g1=(5.7,4.6),g2=(5.7,3.7),g3=(6.4,3.7); draw(e1--e2--e3); draw(f1--f2--f3); draw(g1--g2--g3); pair h1=(6.4,4.2),h2=(6.4,3.5),h3=(7.1,3.9),h4=(7.1,3.5); draw(h1--h2); draw(h3--h4); draw(a1--b1,dashed); draw((2.2,6.3)--c1,dashed); draw((2.9,5.7)--d1,dashed); draw((3.6,5.4)--e1,dashed); draw((4.3,5)--f1,dashed); draw((5,4.6)--g1,dashed); draw((5.7,4.2)--h1,dashed); draw((6.4,3.9)--h3,dashed); //侧隙种类 pair k11=midpoint(a2--a3),k12=(1.85,3.5); pair k21=midpoint(b2--b3),k22=(2.55,3.5); pair k31=midpoint(c2--c3),k32=(3.25,3.5); pair k41=midpoint(d2--d3),k42=(3.95,3.5); pair k51=midpoint(e2--e3),k52=(4.65,3.5); pair k61=midpoint(f2--f3),k62=(5.35,3.5); pair k71=midpoint(g2--g3),k72=(6.05,3.5); pair k81=midpoint(h2--h4),k82=(6.75,3); draw(k11--k12,Arrows); draw(k21--k22,Arrows); draw(k31--k32,Arrows); draw(k41--k42,Arrows); draw(k51--k52,Arrows); draw(k61--k62,Arrows); draw(k71--k72,Arrows); draw(k81--k82,BeginArrow); //基线 draw((-1,3.5)--(9,3.5),blue+linewidth(1.5)); //标签1 label("$0$",(-1,3.5),W); label("$+$",(-.8,3.5),N); label("$-$",(-.8,3.5),S); label("零线",(9,3.5),N,red); //标签2 label("$a$",midpoint(a2--a3),SW); label("$b$",midpoint(b2--b3),SW); label("$c$",midpoint(c2--c3),SW); label("$d$",midpoint(d2--d3),SW); label("$e$",midpoint(e2--e3),SW); label("$f$",midpoint(f2--f3),SE); label("$g$",midpoint(g2--g3),SE); label("$h$",midpoint(h2--h4),SW); label("$j_{nmin}=0$",midpoint(k81--k82),E); //辅助标签jnmin real t=1/3,b=1/2; pair O1=(0,4.2); draw(O1--interp(k11,k12,t));//在线段插入分点用interp,t是分的系数 draw(O1--interp(k21,k22,t)); draw(O1--interp(k31,k32,t)); draw(O1--interp(k41,k42,t)); draw(O1--interp(k51,k52,t)); draw(O1--interp(k61,k62,t)); draw(O1--interp(k71,k72,b)); draw(O1--(-1,4.2)); label("$j_{nmin}$",midpoint(O1--(-1,4.2)),N);
编译后产生的图像如下: