4 from math
import radians
, degrees
6 # fallback implementation for Python 2.1
7 def radians(x
): return x
*pi
/180
8 def degrees(x
): return x
*180/pi
10 startbox
= box
.polygon(corners
=[[0,-0.6], [0.5,0.1], [-0.25,0.1]])
11 endbox
= box
.polygon(corners
=[[4.5,3.9], [5.5,4.0], [5.2,3.4]])
13 # the arc connector <<<
15 for b
in [startbox
, endbox
]:
16 c1
.stroke(b
.path(), [style
.linewidth
.Thick
, style
.linejoin
.round])
17 c1
.fill(path
.circle_pt(b
.center
[0], b
.center
[1], 2))
18 absangle
= degrees(atan2(endbox
.center
[1] - startbox
.center
[1], endbox
.center
[0] - startbox
.center
[0]))
22 # the direct connection
23 direct
= path
.line_pt(startbox
.center
[0], startbox
.center
[1], endbox
.center
[0], endbox
.center
[1])
24 c1
.stroke(direct
, [style
.linestyle
.dashed
])
27 l
= connector
.arc(startbox
, endbox
, relangle
=relangle
, boxdists
=[0.0,0.0])
28 c1
.stroke(l
, [style
.linewidth
.Thick
, color
.rgb
.red
, deco
.earrow
.Large
])
30 # the relangle parameter
31 comp1
= path
.path(path
.moveto(*direct
.atbegin()),
32 path
.rlineto(len*cos(radians(absangle
+ relangle
)), len*sin(radians(absangle
+ relangle
))))
34 ang
= path
.path(path
.arc(direct
.atbegin()[0], direct
.atbegin()[1], 0.8*len, absangle
, absangle
+relangle
))
35 c1
.stroke(ang
, [deco
.earrow
.large
])
36 pos
= ang
.at(0.5*ang
.arclen())
37 c1
.text(pos
[0], pos
[1], r
"~relangle", [text
.halign
.left
])
40 bulge
= 0.5 * direct
.arclen() * tan(0.5*radians(relangle
))
41 bul
= path
.path(path
.moveto(*direct
.at(0.5*direct
.arclen())),
42 path
.rlineto(bulge
* cos(radians(absangle
+90)), bulge
* sin(radians(absangle
+90))))
43 c1
.stroke(bul
, [deco
.earrow
.large
])
44 pos
= bul
.at(0.5*bul
.arclen())
45 c1
.text(pos
[0], pos
[1], r
"~(rel)bulge", [text
.halign
.left
])
49 # the curve connector <<<
51 for b
in [startbox
, endbox
]:
52 c2
.stroke(b
.path(), [style
.linewidth
.Thick
, style
.linejoin
.round])
53 c2
.fill(path
.circle_pt(b
.center
[0], b
.center
[1], 2))
54 absangle
= degrees(atan2(endbox
.center
[1] - startbox
.center
[1], endbox
.center
[0] - startbox
.center
[0]))
61 # the direct connection
62 direct
= path
.line_pt(startbox
.center
[0], startbox
.center
[1], endbox
.center
[0], endbox
.center
[1])
63 c2
.stroke(direct
, [style
.linestyle
.dashed
])
66 l
= connector
.curve(startbox
, endbox
, relangle1
=relangle1
, relangle2
=relangle2
, absbulge
=absbulge
, relbulge
=relbulge
, boxdists
=[0.0,0.0])
67 #l = connector.curve(startbox, endbox, absangle1=absangle+relangle1, absangle2=absangle+relangle2, absbulge=absbulge, relbulge=relbulge, boxdists=[0.0,0.0])
68 c2
.stroke(l
, [style
.linewidth
.Thick
, color
.rgb
.red
, deco
.earrow
.Large
])
70 # the relangle parameters
72 c2
.stroke(path
.path(path
.moveto(*direct
.atbegin()),
73 path
.rlineto(len*cos(radians(absangle
+ relangle1
)),
74 len*sin(radians(absangle
+ relangle1
)))))
75 ang
= path
.path(path
.arc(direct
.atbegin()[0], direct
.atbegin()[1], 0.8*len, absangle
, absangle
+relangle1
))
76 c2
.stroke(ang
, [deco
.earrow
.large
])
77 pos
= ang
.at(0.5*ang
.arclen())
78 c2
.text(pos
[0], pos
[1], r
"~relangle1", [text
.halign
.left
])
81 c2
.stroke(path
.path(path
.moveto(*direct
.atbegin()), path
.rlineto(len, 0)))
82 ang
= path
.path(path
.arc(direct
.atbegin()[0], direct
.atbegin()[1], 0.5*len, 0, absangle
+relangle1
))
83 c2
.stroke(ang
, [deco
.earrow
.large
])
84 pos
= ang
.at(0.2*ang
.arclen())
85 c2
.text(pos
[0], pos
[1], r
"~absangle1", [text
.halign
.left
])
88 c2
.stroke(path
.path(path
.moveto(*direct
.atend()),
89 path
.rlineto(len*cos(radians(absangle
)),
90 len*sin(radians(absangle
)))))
91 c2
.stroke(path
.path(path
.moveto(*direct
.atend()),
92 path
.rlineto(len*cos(radians(absangle
+ relangle2
)),
93 len*sin(radians(absangle
+ relangle2
)))))
94 ang
= path
.path(path
.arc(direct
.atend()[0], direct
.atend()[1],
95 0.8*len, absangle
, absangle
+relangle2
))
96 c2
.stroke(ang
, [deco
.earrow
.large
])
97 pos
= ang
.at(0.5*ang
.arclen())
98 c2
.text(pos
[0], pos
[1], r
"~relangle2", [text
.halign
.left
])
100 # the bulge parameter
101 bulge
= absbulge
+ direct
.arclen() * relbulge
102 bul
= path
.path(path
.moveto(*direct
.atbegin()),
103 path
.rlineto(bulge
* cos(radians(absangle
+relangle1
)), bulge
* sin(radians(absangle
+relangle1
))))
104 c2
.stroke(bul
, [deco
.earrow
.large
])
105 pos
= bul
.at(0.7*bul
.arclen())
106 c2
.text(pos
[0], pos
[1], r
"~(rel)bulge", [text
.halign
.left
])
108 bul
= path
.path(path
.moveto(*direct
.atend()),
109 path
.rlineto(-bulge
* cos(radians(absangle
+relangle2
)), -bulge
* sin(radians(absangle
+relangle2
))))
110 c2
.stroke(bul
, [deco
.earrow
.large
])
111 pos
= bul
.at(0.7*bul
.arclen())
112 c2
.text(pos
[0], pos
[1], r
"~(rel)bulge", [text
.halign
.left
, text
.vshift(1)])
117 c1
.insert(c2
, [trafo
.translate(6.5, 0)])
120 # vim:foldmethod=marker:foldmarker=<<<,>>>