unitsize(1cm);
path h=(0,4)--(5,3);
transform t=shift(0,-.8);
DefaultHead=SimpleHead;
draw(Label("$\sqrt{2}$",Rotate(dir(h)),align=N,position=Relative(.2)),h,Arrow());
draw(Label("$b$",Rotate(dir(h))),t*h,Arrow());
draw(Label("$c$",EndPoint,red),t^2*h,Arrow());
draw(Label("$d$",Relative(.25),red),t^3*h,align=S,Arrow());
draw(Label("$e$",EndPoint,align=S,red),t^4*h,Arrow());
draw(Label("$f$",position=Relative(.25)),t^5*h,Arrow());
draw(Label("$g$",align=RightSide),t^6*h,Arrow());
draw(Label("$h$",align=Center),t^7*h,Arrow());
draw(Label(s="$im$",Rotate(dir(h)),FillDraw(blue,red)),t^8*h,Arrow());
draw(Label("$j$",Relative(.25)),t^9*h,Arrow());
draw(Label("$k$",Rotate(dir(h)),position=Relative(.75),FillDraw(blue,green)),t^10*h,.5green,Arrow());
//label(rotate(45)*"NE",t^10*h,NE,p2);
shipout(bbox(2mm,white));
类似的问题:
例如:
frame f;
label(f,"\textbf{frame - picture}",yellow,Fill(.5blue));
add(rotate(20)*scale(3)*f);
我尝试
unitsize(1cm);
path h=(0,4)--(5,3);
frame f;
label(f,Label("\textbf{Exemple \`a venir}",Rotate(dir(h))),yellow,Fill(.5blue));
add(Rotate(dir(h))*f);
但我收到的举报如下:
答案1
要实现所需的输出,请将未旋转的标签放入框架中,然后旋转框架。在框架内旋转标签和框架本身将导致文本错位的旋转框。
你犯的错误是,Rotate
函数的参数是一个变换,而你给了它一个对。相反,我们可以只使用函数rotate
,它接受一个旋转角度。
unitsize(1cm);
path h = (0, 0) -- (3, -1);
real rotate_angle = degrees(dir(h));
frame f;
label(f, "text", yellow, FillDraw(blue, green));
add(rotate(rotate_angle)*f, midpoint(h) + 0.3*dir(rotate_angle - 90));
draw(h);
答案2
这是另一种方法。Charles Staats 定义pathlabel
命令(第 39 页,本教程)。我认为pathlabel
可以稍微改进一下命令,以便使代码更自然(我喜欢写"hypotenus"
thanshift(15N)*"hypotenus"
和写sloped
than sloped=true
)。
// http://asymptote.ualberta.ca/
void pathlabel(picture pic = currentpicture, Label L, path g,
real position=0.5, align align=NoAlign, bool sloped=false,
pen p=currentpen, filltype filltype=NoFill) {
Label L2 = Label(L, align, p, filltype,
position=Relative(position));
if (sloped) {
pair direction = dir(g, reltime(g, position));
real angle = degrees(atan2(direction.y, direction.x));
L2 = rotate(angle)*L2;
}
label(pic, L2, g);
}
unitsize(1cm);
defaultpen(fontsize(10pt));
pair C=(0,0), A=(4,0), B=(0,3);
label("A",A,SE,blue);
label("B",B,NW,blue);
label("C",C,SW,blue);
draw(A--B--C--cycle);
pen p=magenta;
pathlabel("$b$", C--A, align=S,p);
pathlabel("$a$",C--B, position=.4,align=W,sloped=true,p);
pathlabel(shift(15N)*"hypotenus",B--A, sloped=true,p);