我正在用渐近线制作一个简单的 3d 图,并希望图中有一个漂亮的箭头。我确实设法在那里放了一个箭头,但它看起来非常不对称。我希望箭头的顶部和底部有相同的线宽。有什么想法可以实现这一点吗?
该图像由以下代码生成:
settings.outformat = "png";
settings.render = 10;
settings.prc = false;
unitsize(1.0cm);
import three;
real width = 2.7;
real height = 1.6;
real depth = 1.2;
real lw = 2; //linewidth
currentprojection = obliqueX;
//define matplotlib default colors
pen C0 = RGB(31,119,180);
pen C3 = RGB(214,39,40);
//draw box
draw((0,0,0) -- (0,0,-height), C0+dashed+linewidth(lw));
draw((0,0,-height) -- (0,4*width,-height), C0+dashed+linewidth(lw));
draw((0,0,-height) -- (depth,0,-height), C0+dashed+linewidth(lw));
draw((0,0,0) -- (0,4*width,0), C0+linewidth(lw));
draw((depth,0,0) -- (0,0,0), C0+linewidth(lw));
draw((depth,0,-height) -- (depth,4*width,-height) -- (depth,4*width,0) -- (depth,0,0) -- (depth,0,-height), C0+linewidth(lw));
draw((depth,4*width,-height) -- (0,4*width,-height) -- (0,4*width,0) -- (depth,4*width,0), C0+linewidth(lw));
label("Box", (depth, 2*width, -0.40*height),C0);
//draw axis arrows
real axisZshift = -2.4;
real axisXshift = 0.2;
real axisLength = 1.0;
draw((0,axisZshift,axisXshift)--(-axisLength,axisZshift,axisXshift), arrow=Arrow3(TeXHead2(normal=Y)), L=Label("$z$", position=EndPoint, align=N+E));
draw((0,axisZshift,axisXshift)--(0,axisZshift,axisXshift+axisLength), arrow=Arrow3(TeXHead2(normal=X)), L=Label("$x$", position=EndPoint, align=N));
draw((0,axisZshift,axisXshift)--(0,axisZshift+axisLength,axisXshift), arrow=Arrow3(TeXHead2(normal=X)), L=Label("$y$", position=EndPoint, align=E));
//draw red arrow
draw((depth, 3.5*width, 1.5*height) -- (depth, 0.5*width, 1.5*height), arrow=Arrow3(TeXHead2, emissive(C3)), L=Label("red arrow", position=MidPoint, align=N), C3+linewidth(2*lw));
答案1
一种方法是使用2D
箭头和2D
投影,通过project()
函数:
settings.outformat = "png";
settings.render = 10;
settings.prc = false;
unitsize(1.0cm);
import three;
real width = 2.7;
real height = 1.6;
real depth = 1.2;
real lw = 2; //linewidth
currentprojection = obliqueX;
//define matplotlib default colors
pen C0 = RGB(31,119,180);
pen C3 = RGB(214,39,40);
//draw box
draw(project((0,0,0) -- (0,0,-height) ), C0+dashed+linewidth(lw));
draw(project((0,0,-height) -- (0,4*width,-height)), C0+dashed+linewidth(lw));
draw(project((0,0,-height) -- (depth,0,-height) ), C0+dashed+linewidth(lw));
draw(project((0,0,0) -- (0,4*width,0) ), C0+linewidth(lw));
draw(project((depth,0,0) -- (0,0,0) ), C0+linewidth(lw));
draw(project((depth,0,-height) -- (depth,4*width,-height) -- (depth,4*width,0) -- (depth,0,0) -- (depth,0,-height)), C0+linewidth(lw));
draw(project((depth,4*width,-height) -- (0,4*width,-height) -- (0,4*width,0) -- (depth,4*width,0)), C0+linewidth(lw));
label("Box", project((depth, 2*width, -0.40*height)),C0);
//draw axis arrows
real axisZshift = -2.4;
real axisXshift = 0.2;
real axisLength = 1.0;
draw(project((0,axisZshift,axisXshift)--(-axisLength,axisZshift,axisXshift )), arrow=Arrow(TeXHead), L=Label("$z$", position=EndPoint, align=N+E));
draw(project((0,axisZshift,axisXshift)--(0,axisZshift,axisXshift+axisLength)), arrow=Arrow(TeXHead), L=Label("$x$", position=EndPoint, align=N));
draw(project((0,axisZshift,axisXshift)--(0,axisZshift+axisLength,axisXshift)), arrow=Arrow(TeXHead), L=Label("$y$", position=EndPoint, align=E));
//draw red arrow
draw(project((depth, 3.5*width, 1.5*height) -- (depth, 0.5*width, 1.5*height)), arrow=Arrow(TeXHead), L=Label("red arrow", position=MidPoint, align=N), C3+linewidth(2*lw));
为了简化流程,您还可以定义一些函数,例如
void draw(guide3 g, pen p){
draw(project(g),p);
};
然后,例如,像这样的命令
draw((0,0,0) -- (0,0,-height), C0+dashed+linewidth(lw));
将自动绘制投影。