2 # -*- coding: ISO-8859-15 -*-
4 sys
.path
.insert(0, "..")
8 from math
import radians
, degrees
10 # fallback implementation for Python 2.1
11 def radians(x
): return x
*pi
/180
12 def degrees(x
): return x
*180/pi
14 startbox
= box
.polygon(corners
=[[0,-0.6], [0.5,0.1], [-0.25,0.1]])
15 endbox
= box
.polygon(corners
=[[4.5,3.9], [5.5,4.0], [5.2,3.4]])
17 # the arc connector <<<
19 for b
in [startbox
, endbox
]:
20 c1
.stroke(b
.path(), [style
.linewidth
.Thick
, style
.linejoin
.round])
21 c1
.fill(path
.circle_pt(b
.center
[0], b
.center
[1], 2))
22 absangle
= degrees(atan2(endbox
.center
[1] - startbox
.center
[1], endbox
.center
[0] - startbox
.center
[0]))
26 # the direct connection
27 direct
= path
.line_pt(startbox
.center
[0], startbox
.center
[1], endbox
.center
[0], endbox
.center
[1])
28 c1
.stroke(direct
, [style
.linestyle
.dashed
])
31 l
= connector
.arc(startbox
, endbox
, relangle
=relangle
, boxdists
=[0.0,0.0])
32 c1
.stroke(l
, [style
.linewidth
.Thick
, color
.rgb
.red
, deco
.earrow
.Large
])
34 # the relangle parameter
35 comp1
= path
.path(path
.moveto(*direct
.atbegin()),
36 path
.rlineto(len*cos(radians(absangle
+ relangle
)), len*sin(radians(absangle
+ relangle
))))
38 ang
= path
.path(path
.arc(direct
.atbegin()[0], direct
.atbegin()[1], 0.8*len, absangle
, absangle
+relangle
))
39 c1
.stroke(ang
, [deco
.earrow
.large
])
40 pos
= ang
.at(0.5*ang
.arclen())
41 c1
.text(pos
[0], pos
[1], r
"~relangle", [text
.halign
.left
])
44 bulge
= 0.5 * direct
.arclen() * tan(0.5*radians(relangle
))
45 bul
= path
.path(path
.moveto(*direct
.at(0.5*direct
.arclen())),
46 path
.rlineto(bulge
* cos(radians(absangle
+90)), bulge
* sin(radians(absangle
+90))))
47 c1
.stroke(bul
, [deco
.earrow
.large
])
48 pos
= bul
.at(0.5*bul
.arclen())
49 c1
.text(pos
[0], pos
[1], r
"~(rel)bulge", [text
.halign
.left
])
53 # the curve connector <<<
55 for b
in [startbox
, endbox
]:
56 c2
.stroke(b
.path(), [style
.linewidth
.Thick
, style
.linejoin
.round])
57 c2
.fill(path
.circle_pt(b
.center
[0], b
.center
[1], 2))
58 absangle
= degrees(atan2(endbox
.center
[1] - startbox
.center
[1], endbox
.center
[0] - startbox
.center
[0]))
65 # the direct connection
66 direct
= path
.line_pt(startbox
.center
[0], startbox
.center
[1], endbox
.center
[0], endbox
.center
[1])
67 c2
.stroke(direct
, [style
.linestyle
.dashed
])
70 l
= connector
.curve(startbox
, endbox
, relangle1
=relangle1
, relangle2
=relangle2
, absbulge
=absbulge
, relbulge
=relbulge
, boxdists
=[0.0,0.0])
71 #l = connector.curve(startbox, endbox, absangle1=absangle+relangle1, absangle2=absangle+relangle2, absbulge=absbulge, relbulge=relbulge, boxdists=[0.0,0.0])
72 c2
.stroke(l
, [style
.linewidth
.Thick
, color
.rgb
.red
, deco
.earrow
.Large
])
74 # the relangle parameters
76 c2
.stroke(path
.path(path
.moveto(*direct
.atbegin()),
77 path
.rlineto(len*cos(radians(absangle
+ relangle1
)),
78 len*sin(radians(absangle
+ relangle1
)))))
79 ang
= path
.path(path
.arc(direct
.atbegin()[0], direct
.atbegin()[1], 0.8*len, absangle
, absangle
+relangle1
))
80 c2
.stroke(ang
, [deco
.earrow
.large
])
81 pos
= ang
.at(0.5*ang
.arclen())
82 c2
.text(pos
[0], pos
[1], r
"~relangle1", [text
.halign
.left
])
85 c2
.stroke(path
.path(path
.moveto(*direct
.atbegin()), path
.rlineto(len, 0)))
86 ang
= path
.path(path
.arc(direct
.atbegin()[0], direct
.atbegin()[1], 0.5*len, 0, absangle
+relangle1
))
87 c2
.stroke(ang
, [deco
.earrow
.large
])
88 pos
= ang
.at(0.2*ang
.arclen())
89 c2
.text(pos
[0], pos
[1], r
"~absangle1", [text
.halign
.left
])
92 c2
.stroke(path
.path(path
.moveto(*direct
.atend()),
93 path
.rlineto(len*cos(radians(absangle
)),
94 len*sin(radians(absangle
)))))
95 c2
.stroke(path
.path(path
.moveto(*direct
.atend()),
96 path
.rlineto(len*cos(radians(absangle
+ relangle2
)),
97 len*sin(radians(absangle
+ relangle2
)))))
98 ang
= path
.path(path
.arc(direct
.atend()[0], direct
.atend()[1],
99 0.8*len, absangle
, absangle
+relangle2
))
100 c2
.stroke(ang
, [deco
.earrow
.large
])
101 pos
= ang
.at(0.5*ang
.arclen())
102 c2
.text(pos
[0], pos
[1], r
"~relangle2", [text
.halign
.left
])
104 # the bulge parameter
105 bulge
= absbulge
+ direct
.arclen() * relbulge
106 bul
= path
.path(path
.moveto(*direct
.atbegin()),
107 path
.rlineto(bulge
* cos(radians(absangle
+relangle1
)), bulge
* sin(radians(absangle
+relangle1
))))
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
])
112 bul
= path
.path(path
.moveto(*direct
.atend()),
113 path
.rlineto(-bulge
* cos(radians(absangle
+relangle2
)), -bulge
* sin(radians(absangle
+relangle2
))))
114 c2
.stroke(bul
, [deco
.earrow
.large
])
115 pos
= bul
.at(0.7*bul
.arclen())
116 c2
.text(pos
[0], pos
[1], r
"~(rel)bulge", [text
.halign
.left
, text
.vshift(1)])
121 c1
.insert(c2
, [trafo
.translate(6.5, 0)])
122 c1
.writeEPSfile("connector", paperformat
=document
.paperformat
.A4
)
123 c1
.writePDFfile("connector")
125 # vim:foldmethod=marker:foldmarker=<<<,>>>