我想画这幅画
作为一个新手,我通常的做法(对于所有其他图像)是煞费苦心地逐行绘制并手动调整它们的坐标以获得我想要的形状。 我用这种方式画了几幅图,这是一种令人心力交瘁的方法。
我想知道是否有更好的方法来绘制这些类型的图像。
答案1
也许,Asymptote
可以帮助拯救你的灵魂?
s.tex
:
\documentclass{article}
\usepackage[inline]{asymptote}
\usepackage{lmodern}
\begin{document}
\begin{figure}
\begin{asy}
settings.prc=false;
settings.render=0;
import three;
currentprojection=orthographic(
camera=(-9,6,-6),
up=Y,
target=(0.4,0.4,-0.25),
zoom=0.5,
viewportshift=(0.25,0));
size(300,200);
size3(200,200,100);
real d=0.5; // shift of the lower right corner of the screen
real l=13, h=8; // screen dimensions
// corners of the screen
triple scrlr=(-d,-d,0);
triple scrll=(l,scrlr.y,0);
triple scrur=(scrlr.x,h,0);
triple scrul=(scrll.x,scrur.y,0);
guide3 screen=scrlr--(scrur-2Y)--(scrur+2X-2Y)--(scrur+2X)--scrul--scrll--cycle;
pen screenPen=rgb(1,0.98,0.83);
filldraw(project(screen),screenPen,0.2*screenPen);
draw(project((scrur-2Y)--(scrur+2X)),0.2*screenPen);
// axes
draw(project(O--2X),Arrow(HookHead));
draw(project(O--2Y),Arrow(HookHead));
draw(project(O--(-2Z)),Arrow(HookHead));
label("$x$",2X,2X);
label("$y$",2Y,2Y);
label("$z$\,?",-2Z,-2Z);
// Projection
real a=3, b=4;
triple z0shift=(2,1.5,0);
triple[] z0={O,a*Y, a*Y*0.8+b*X,-a*Y*0.2+b*X};
guide3 sketchFront=z0[0]--z0[1]--z0[2]--z0[3]--cycle;
pen sketchPen=darkblue+1.2pt;
void drawFrame(triple[] v, pen p){
guide3 front=v[0]--v[1]--v[2]--v[3]--cycle;
guide3 back=v[0+4]--v[1+4]--v[2+4]--v[3+4]--cycle;
draw(front,p);
draw(back,p);
for(int i=0;i<4;++i){
draw(v[i]--v[i+4],p); // draw front-back point connections
}
}
triple[] Z0=new triple[8]; // coordinates of the projected sketch
for(int i=0;i<4;++i){
Z0[i]=shift(z0shift)*z0[i];
Z0[i+4]=shift(z0shift)*Z0[i];
}
triple[] Z2=copy(Z0); // coordinates of the "normal" frame z2,
// as Z0 shifted evenly in Z direction
real la1=11,lb1=12;
Z2[0]-=la1*Z;
Z2[1]-=la1*Z;
Z2[0+4]-=la1*Z;
Z2[1+4]-=la1*Z;
Z2[2]-=lb1*Z;
Z2[3]-=lb1*Z;
Z2[2+4]-=lb1*Z;
Z2[3+4]-=lb1*Z;
triple[] Z1=copy(Z0); // coordinates of the "distorted" frame z1,
Z1[0]-= 2*Z+3Z;
Z1[1]-= 3*Z+3Z;
Z1[0+4]-=2*Z+3Z;
Z1[1+4]-=4*Z+3Z;
Z1[2]-=2.5*Z+3Z;
Z1[3]-= 1*Z+3Z;
Z1[2+4]-=3*Z+3Z;
Z1[3+4]-=4*Z+3Z;
triple[] Z3=copy(Z0); // coordinates of the "distorted" frame z3,
Z3[0]-= 3*Z+15Z;
Z3[1]-= 3*Z+15Z;
Z3[0+4]-=3.5*Z+15Z;
Z3[1+4]-=4*Z+15Z;
Z3[2]-=2.5*Z+15Z;
Z3[3]-= 4*Z+15Z;
Z3[2+4]-=2.8*Z+15Z;
Z3[3+4]-=4*Z+15Z;
drawFrame(Z0,sketchPen);
drawFrame(Z1,red+1pt);
drawFrame(Z2,darkgreen+1pt);
drawFrame(Z3,blue+1pt);
label("\{z$_1\}$",Z1[0],-X-Y);
label("\{z$_2\}$",Z2[0],-X-Y);
label("\{z$_3\}$",Z3[0],-X-Y);
// projection rays
real lproj=22;
pen projRayPen=gray+0.2pt;
for(int i=0;i<8;++i){
draw(Z0[i]--(Z0[i]-lproj*Z),projRayPen);
}
\end{asy}
\caption{Drawing primitive shapes with \texttt{Asymptote}.}
\end{figure}
\end{document}
为了处理它latexmk
,请创建文件latexmkrc
:
sub asy {return system("asy '$_[0]'");}
add_cus_dep("asy","eps",0,"asy");
add_cus_dep("asy","pdf",0,"asy");
add_cus_dep("asy","tex",0,"asy");
然后运行latexmk -pdf s.tex
。