-
Notifications
You must be signed in to change notification settings - Fork 0
/
arrows_pi.asy
159 lines (149 loc) · 5.44 KB
/
arrows_pi.asy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// Copyright (c) 2007, Philippe Ivaldi.
// Last modified: Mon Dec 31 15:29:19 CET 2007
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or (at
// your option) any later version.
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
// 02110-1301, USA.
arrowhead EdgeHead()
{
arrowhead oa;
oa.head=new path(path g, position position, pen p=currentpen, real size=0,
real angle=arrowangle)
{
if(size == 0) size=arrowsize(p);
bool relative=position.relative;
real position=position.position.x;
if(relative) position=reltime(g,position);
path r=subpath(g,position,0.0);
pair x=point(r,0);
real t=arctime(r,size);
pair y=point(r,t);
path base=y+2*size*I*dir(r,t)--y-2*size*I*dir(r,t);
path left=rotate(-angle,x)*r;
real[] T=arrowbasepoints(base,left,r);
pair denom=point(right,T[1])-y;
real factor=denom != 0 ? length((point(left,T[0])-y)/denom) : 1;
path left=rotate(-angle,x)*r;
real[] T=arrowbasepoints(base,left,r);
return subpath(left,0,T[0])--y--cycle;
};
return oa;
}
arrowhead EdgeHead=EdgeHead();
arrowhead EdgeHookHead(real dir=arrowdir, real barb=arrowbarb)
{
arrowhead oa;
oa.head=new path(path g, position position, pen p=currentpen, real size=0,
real angle=arrowangle)
{
if(size == 0) size=arrowsize(p);
angle *= arrowhookfactor;
bool relative=position.relative;
real position=position.position.x;
if(relative) position=reltime(g,position);
path r=subpath(g,position,0);
pair x=point(r,0);
real t=arctime(r,size);
pair y=point(r,t);
path base=y+2*size*I*dir(r,t)--y-2*size*I*dir(r,t);
path left=rotate(-angle,x)*r;
path right=rotate(angle,x)*r;
real[] T=arrowbasepoints(base,left,right);
pair denom=point(right,T[1])-y;
real factor=denom != 0 ? length((point(left,T[0])-y)/denom) : 1;
path left=rotate(-angle,x)*r;
path right=rotate(angle*factor,x)*r;
real[] T=arrowbasepoints(base,left,right);
left=subpath(left,0,T[0]);
right=subpath(right,T[1],0);
pair pl0=point(left,0), pl1=relpoint(left,1);
pair pr0=relpoint(right,0), pr1=relpoint(right,1);
pair M=(pl1+pr0)/2;
pair v=barb*unit(M-pl0);
pl1=pl1+v; pr0=pr0+v;
left=pl0{dir(-dir+degrees(M-pl0))}..pl1--M;
right=M--pr0..pr1{dir(dir+degrees(pr1-M))};
return left--y--cycle;
};
return oa;
}
arrowhead EdgeHookHead=EdgeHookHead();
arrowhead EdgeSimpleHead(real dir=arrowdir, real barb=arrowbarb)
{
arrowhead oa;
oa.head=new path(path g, position position, pen p=currentpen, real size=0,
real angle=arrowangle)
{
if(size == 0) size=arrowsize(p);
bool relative=position.relative;
real position=position.position.x;
if(relative) position=reltime(g,position);
path r=subpath(g,position,0);
pair x=point(r,0);
real t=arctime(r,size);
pair y=point(r,t);
path base=y+2*size*I*dir(r,t)--y-2*size*I*dir(r,t);
path left=rotate(-angle,x)*r;
path right=rotate(angle,x)*r;
real[] T=arrowbasepoints(base,left,right);
pair denom=point(right,T[1])-y;
real factor=denom != 0 ? length((point(left,T[0])-y)/denom) : 1;
path left=rotate(-angle,x)*r;
path right=rotate(angle*factor,x)*r;
real[] T=arrowbasepoints(base,left,right);
return subpath(left,T[0],0);
};
return oa;
}
arrowhead EdgeSimpleHead=EdgeSimpleHead();
private real position(position position, real size, path g, bool center)
{
bool relative=position.relative;
real position=position.position.x;
if(relative) {
position *= arclength(g);
if(center) position += 0.5*size;
position=arctime(g,position);
} else if(center)
position=arctime(g,arclength(subpath(g,0,position))+0.5*size);
return position;
}
arrowbar EdgeArrows(arrowhead head=EdgeHead,real size=0, real angle=arrowangle,
filltype filltype=FillDraw, position position=EndPoint,
real space=infinity)
{
return new bool(picture pic, path g, pen p, margin margin) {
pair direction;
real sg=sgn(dot(N,space*I*dir(g,length(g)/2)));
space = (space == infinity) ? 2*linewidth(p) : space/2;
if (sg>=0)
{
direction=-space*I*dir(g,length(g)/2);
sg=1;
}
else direction=space*I*dir(g,length(g)/2);
picture tpic;
tpic.add(new void (frame f, transform t) {
drawarrow(f,head,t*shift(inverse(t)*(-direction))*g,p,
size,sg*angle,filltype,position,true,margin,false);
drawarrow(f,head,t*shift(inverse(t)*direction)*reverse(g),p,
size,sg*angle,filltype,position,true,margin,false);
});
tpic.addPath(g,p);
real sz=size;
real gle=angle;
filltype fl=filltype;
addArrow(tpic,head,g,p,sz,gle,fl,position(position,size,g,false));
add(pic,tpic);
return false;
};
};
arrowbar EdgeArrows=EdgeArrows();