这些是我尝试过的事情
settings.outformat="pdf";
settings.prc=false;
settings.render=0;
import graph;
import math;
unitsize(1cm);
size(10cm,0);
defaultpen(linewidth(1bp));
real xmin=-2,xmax=3;
real ymin=-2,ymax=3;
real dxmin=0.35;
real dxmax=dxmin;
real dymin=dxmin;
real dymax=dxmax;
add(shift(-2.5,-3)*scale(0.5)*grid(11,12,paleblue+0.3bp));
xaxis(Label("$x$",position=Relative(1),align=2NE),
xmin-dxmin,xmax+dxmax,RightTicks(Step=1,step=0.5),Arrow(HookHead),above=true);
yaxis(Label("$y$",position=Relative(1),align=N+E),
ymin-dymin,ymax+dymax,LeftTicks (Step=1,step=0.5,OmitTick(0)),Arrow(HookHead),above=true);
//--------------
void pstLineAB(pair A, pair B, real nodesepA=0, real nodesepB=0,
pen p=currentpen)
{
//these is inspired by \pstLineAB[Options]{A}{B} in the pst-eucl documentation.
pair A1,B1;
if (nodesepA < 0)
{
A1=A+nodesepA*unit(B-A);
// the direction of unit coincides with nodesepA >0
}
else if (nodesepA > 0)
{
A1=A+nodesepA*unit(B-A);
}
else { A1=A; }
if (nodesepB < 0)
{
B1=B+nodesepB*unit(A-B);
// the direction of unit coincides with nodesepB >0
}
else if (nodesepB >0)
{
B1=B+nodesepB*unit(A-B);
}
else { B1=B;}
draw(A1--B1,p);
}
//---
void pstLineAB(pair A, pair B, real nodesep=0, pen p=currentpen)
{
pstLineAB(A,B,nodesepA=nodesep,nodesepB=nodesep,p);
}
pair A=(1,1),B=(-1,-1);
dot("A",A,red); dot("B",B,green);
pstLineAB(A,B,nodesepA=-.4,nodesepB=-1,green);
pstLineAB(A,B,nodesep=.4,red);
我想写一个命令,他们喜欢这样:
pair A1=pstLineAB[A][-.4],
B1=pstLineAB[B][-1],
A2=pstLineAB[A][.4],
B2=pstLineAB[B][.4];
或者something have the same function
。
事实上,我不知道该怎么做。
问:我该怎么办?
答案1
如果您有权限,path
那么您可以使用函数获得端点point(path,int )
。由于这是一条简单A--B
路径,因此point(A--B,0)
给出A
而point(A--B,1)
给出B
。请在此处找到代码的修改,返回pstLineAB
以便path
您可以绘制它或返回端点。
settings.outformat="pdf";
settings.prc=false;
settings.render=0;
import graph;
import math;
unitsize(1cm);
size(10cm,0);
defaultpen(linewidth(1bp));
real xmin=-2,xmax=3;
real ymin=-2,ymax=3;
real dxmin=0.35;
real dxmax=dxmin;
real dymin=dxmin;
real dymax=dxmax;
add(shift(-2.5,-3)*scale(0.5)*grid(11,12,paleblue+0.3bp));
xaxis(Label("$x$",position=Relative(1),align=2NE),
xmin-dxmin,xmax+dxmax,RightTicks(Step=1,step=0.5),Arrow(HookHead),above=true);
yaxis(Label("$y$",position=Relative(1),align=N+E),
ymin-dymin,ymax+dymax,LeftTicks (Step=1,step=0.5,OmitTick(0)),Arrow(HookHead),above=true);
//--------------
path pstLineAB(pair A, pair B, real nodesepA=0, real nodesepB=nodesepA)
{
//these is inspired by \pstLineAB[Options]{A}{B} in the pst-eucl documentation.
pair A1,B1;
if (nodesepA < 0)
{
A1=A+nodesepA*unit(B-A);
// the direction of unit coincides with nodesepA >0
}
else if (nodesepA > 0)
{
A1=A+nodesepA*unit(B-A);
}
else { A1=A; }
if (nodesepB < 0)
{
B1=B+nodesepB*unit(A-B);
// the direction of unit coincides with nodesepB >0
}
else if (nodesepB >0)
{
B1=B+nodesepB*unit(A-B);
}
else { B1=B;}
return A1--B1;
}
//---
//void pstLineAB(pair A, pair B, real nodesep=0, pen p=currentpen)
//{
//pstLineAB(A,B,nodesepA=nodesep,nodesepB=nodesep,p);
//
pair A=(1,1),B=(-1,-1);
dot("A",A,red); dot("B",B,green);
path ex1=pstLineAB(A,B,nodesepA=-.4,nodesepB=-1);
path ex2=pstLineAB(A,B,nodesepA=.4);
dot("$A_1$",point(ex1,0));
dot("$B_1$",point(ex1,1));
draw(ex1,green);
dot("$A_2$",point(ex2,0));
dot("$B_2$",point(ex2,1));
draw(ex2,red);
和输出