2 # -*- coding: ISO-8859-15 -*-
4 sys
.path
.insert(0, "..")
8 startbox
= box
.polygon(corners
=[[0,-0.6], [0.5,0.1], [-0.25,0.1]])
9 endbox
= box
.polygon(corners
=[[4.5,3.9], [5.5,4.0], [5.2,3.4]])
11 # the arc connector <<<
13 for b
in [startbox
, endbox
]:
14 c1
.stroke(b
.path(), [style
.linewidth
.Thick
, style
.linejoin
.round])
15 c1
.fill(path
.circle_pt(b
.center
[0], b
.center
[1], 2))
16 absangle
= degrees(atan2(endbox
.center
[1] - startbox
.center
[1], endbox
.center
[0] - startbox
.center
[0]))
20 # the direct connection
21 direct
= path
.line_pt(startbox
.center
[0], startbox
.center
[1], endbox
.center
[0], endbox
.center
[1])
22 c1
.stroke(direct
, [style
.linestyle
.dashed
])
25 l
= connector
.arc(startbox
, endbox
, relangle
=relangle
, boxdists
=[0.0,0.0])
26 c1
.stroke(l
, [style
.linewidth
.Thick
, color
.rgb
.red
, deco
.earrow
.Large
])
28 # the relangle parameter
29 comp1
= path
.path(path
.moveto(*direct
.atbegin()),
30 path
.rlineto(len*cos(radians(absangle
+ relangle
)), len*sin(radians(absangle
+ relangle
))))
32 ang
= path
.path(path
.arc(direct
.atbegin()[0], direct
.atbegin()[1], 0.8*len, absangle
, absangle
+relangle
))
33 c1
.stroke(ang
, [deco
.earrow
.large
])
34 pos
= ang
.at(0.5*ang
.arclen())
35 c1
.text(pos
[0], pos
[1], r
"~relangle", [text
.halign
.left
])
38 bulge
= 0.5 * direct
.arclen() * tan(0.5*radians(relangle
))
39 bul
= path
.path(path
.moveto(*direct
.at(0.5*direct
.arclen())),
40 path
.rlineto(bulge
* cos(radians(absangle
+90)), bulge
* sin(radians(absangle
+90))))
41 c1
.stroke(bul
, [deco
.earrow
.large
])
42 pos
= bul
.at(0.5*bul
.arclen())
43 c1
.text(pos
[0], pos
[1], r
"~(rel)bulge", [text
.halign
.left
])
47 # the curve connector <<<
49 for b
in [startbox
, endbox
]:
50 c2
.stroke(b
.path(), [style
.linewidth
.Thick
, style
.linejoin
.round])
51 c2
.fill(path
.circle_pt(b
.center
[0], b
.center
[1], 2))
52 absangle
= degrees(atan2(endbox
.center
[1] - startbox
.center
[1], endbox
.center
[0] - startbox
.center
[0]))
59 # the direct connection
60 direct
= path
.line_pt(startbox
.center
[0], startbox
.center
[1], endbox
.center
[0], endbox
.center
[1])
61 c2
.stroke(direct
, [style
.linestyle
.dashed
])
64 l
= connector
.curve(startbox
, endbox
, relangle1
=relangle1
, relangle2
=relangle2
, absbulge
=absbulge
, relbulge
=relbulge
, boxdists
=[0.0,0.0])
65 #l = connector.curve(startbox, endbox, absangle1=absangle+relangle1, absangle2=absangle+relangle2, absbulge=absbulge, relbulge=relbulge, boxdists=[0.0,0.0])
66 c2
.stroke(l
, [style
.linewidth
.Thick
, color
.rgb
.red
, deco
.earrow
.Large
])
68 # the relangle parameters
70 c2
.stroke(path
.path(path
.moveto(*direct
.atbegin()),
71 path
.rlineto(len*cos(radians(absangle
+ relangle1
)),
72 len*sin(radians(absangle
+ relangle1
)))))
73 ang
= path
.path(path
.arc(direct
.atbegin()[0], direct
.atbegin()[1], 0.8*len, absangle
, absangle
+relangle1
))
74 c2
.stroke(ang
, [deco
.earrow
.large
])
75 pos
= ang
.at(0.5*ang
.arclen())
76 c2
.text(pos
[0], pos
[1], r
"~relangle1", [text
.halign
.left
])
79 c2
.stroke(path
.path(path
.moveto(*direct
.atbegin()), path
.rlineto(len, 0)))
80 ang
= path
.path(path
.arc(direct
.atbegin()[0], direct
.atbegin()[1], 0.5*len, 0, absangle
+relangle1
))
81 c2
.stroke(ang
, [deco
.earrow
.large
])
82 pos
= ang
.at(0.2*ang
.arclen())
83 c2
.text(pos
[0], pos
[1], r
"~absangle1", [text
.halign
.left
])
86 c2
.stroke(path
.path(path
.moveto(*direct
.atend()),
87 path
.rlineto(len*cos(radians(absangle
)),
88 len*sin(radians(absangle
)))))
89 c2
.stroke(path
.path(path
.moveto(*direct
.atend()),
90 path
.rlineto(len*cos(radians(absangle
+ relangle2
)),
91 len*sin(radians(absangle
+ relangle2
)))))
92 ang
= path
.path(path
.arc(direct
.atend()[0], direct
.atend()[1],
93 0.8*len, absangle
, absangle
+relangle2
))
94 c2
.stroke(ang
, [deco
.earrow
.large
])
95 pos
= ang
.at(0.5*ang
.arclen())
96 c2
.text(pos
[0], pos
[1], r
"~relangle2", [text
.halign
.left
])
99 bulge
= absbulge
+ direct
.arclen() * relbulge
100 bul
= path
.path(path
.moveto(*direct
.atbegin()),
101 path
.rlineto(bulge
* cos(radians(absangle
+relangle1
)), bulge
* sin(radians(absangle
+relangle1
))))
102 c2
.stroke(bul
, [deco
.earrow
.large
])
103 pos
= bul
.at(0.7*bul
.arclen())
104 c2
.text(pos
[0], pos
[1], r
"~(rel)bulge", [text
.halign
.left
])
106 bul
= path
.path(path
.moveto(*direct
.atend()),
107 path
.rlineto(-bulge
* cos(radians(absangle
+relangle2
)), -bulge
* sin(radians(absangle
+relangle2
))))
108 c2
.stroke(bul
, [deco
.earrow
.large
])
109 pos
= bul
.at(0.7*bul
.arclen())
110 c2
.text(pos
[0], pos
[1], r
"~(rel)bulge", [text
.halign
.left
, text
.vshift(1)])
115 c1
.insert(c2
, [trafo
.translate(6.5, 0)])
116 c1
.writeEPSfile("connector", paperformat
=document
.paperformat
.A4
)
117 c1
.writePDFfile("connector")
119 # vim:foldmethod=marker:foldmarker=<<<,>>>