Skip to content

Instantly share code, notes, and snippets.

@reyoung
Created May 9, 2012 07:12
Show Gist options
  • Save reyoung/2642607 to your computer and use it in GitHub Desktop.
Save reyoung/2642607 to your computer and use it in GitHub Desktop.
使用Asymptote绘制三维坐标系,可翻转。也可以绘制向量。
void drawFrame(real x0,real y0,real length,string label="",real alpha=0,real beta=0,real gamma=0){
alpha = alpha/180*3.1415926;
beta = beta/180*3.1415926;
gamma = gamma/180*3.1415926;
real r11 = cos(gamma)*cos(beta);
real r12 = -sin(gamma)*cos(alpha)+cos(gamma)*sin(beta)*sin(alpha);
real r13 = sin(gamma)*sin(alpha)+cos(gamma)*sin(beta)*cos(alpha);
real r21 = sin(gamma)*cos(beta);
real r22 = cos(gamma)*cos(alpha)+sin(gamma)*sin(beta)*sin(alpha);
real r23 = -cos(gamma)*sin(alpha)+sin(gamma)*sin(beta)*cos(alpha);
real r31 = -sin(beta);
real r32 = cos(beta)*sin(alpha);
real r33 = cos(beta)*cos(alpha);
real x1 = x0+(r11-0.707*r21)*length;
real y1 = y0+(r31-0.707*r21)*length;
real x2 = x0+(r12-0.707*r22)*length;
real y2 = y0+(r32-0.707*r22)*length;
real x3 = x0+(r13-0.707*r32)*length;
real y3 = y0+(r33-0.707*r32)*length;
draw((x0,y0)--(x1,y1),Arrow);
draw((x0,y0)--(x2,y2),Arrow);
draw((x0,y0)--(x3,y3),Arrow);
label("$\Sigma_"+label+"$",(x0,y0),SE);
label("$Y_"+label+"$",(x1,y1),NE);
label("$X_"+label+"$",(x2,y2),SE);
label("$Z_"+label+"$",(x3,y3),NW);
}
void drawVector(pair f ,pair t, string label,pair w){
draw(f--t,Arrow);
label(label,(f+t)/2,w);
}
drawFrame(0,0,100,"W");
drawFrame(400,200,100,"E",30,30);
pair p=(150,250);
drawVector((0,0),p,"$\overrightarrow{{}^WP_a}$",SE);
drawVector((0,0),(400,200),"$\overrightarrow{{}^WP_E}$",SE);
drawVector((400,200),p,"$\overrightarrow{{}^EP_a}$",SW);
label("$a(1.5,2.5)$",p,NE);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment