reduce length of pattern lines by one order of magnitude to prevent problems with...
[PyX/mjg.git] / design / boxalign.py
blobdfe1720b11f1268d3221c2590d240cec88f431de
1 #!/usr/bin/env python
2 import sys, math
3 sys.path[:0] = [".."]
4 import pyx
5 from pyx import *
7 c = canvas.canvas()
8 c.stroke(path.line(0, 0, 4, 2), [deco.earrow.Large()])
9 t = text.text(2, 1, r"$\vec p$")
10 t.linealign(0.1, -2/math.sqrt(20), 4/math.sqrt(20))
11 c.insert(t)
12 c.stroke(path.line(0, 0, 1, 1), [deco.earrow.Large()])
13 t = text.text(0.5, 0.5, r"$\vec a$")
14 t.linealign(0.1, -1/math.sqrt(2), 1/math.sqrt(2))
15 c.insert(t)
16 c.stroke(path.line(-1, 3, 3, -1), [style.linestyle.dotted])
17 c.stroke(path.line(1, 1, 1-1/math.sqrt(2), 1+1/math.sqrt(2)), [deco.earrow.Large()])
18 t = text.text(1-1/math.sqrt(8), 1+1/math.sqrt(8), r"$\vec b$")
19 t.linealign(0.1, 1/math.sqrt(2), 1/math.sqrt(2))
20 c.insert(t)
21 c.writeEPSfile("boxalignpal")
23 ###############################################################################
25 c = canvas.canvas()
26 c.stroke(path.line(0, 0, 4, 2), [deco.earrow.Large()])
27 t = text.text(2, 1, r"$\vec p$")
28 t.linealign(0.1, -2/math.sqrt(20), 4/math.sqrt(20))
29 c.insert(t)
30 c.stroke(path.line(0, 0, -1, 1), [deco.earrow.Large()])
31 t = text.text(-0.5, 0.5, r"$\vec a$")
32 t.linealign(0.1, -1/math.sqrt(2), -1/math.sqrt(2))
33 c.insert(t)
34 c.stroke(path.path(path.arc(0, 0, math.sqrt(2), 0, 360), path.closepath()), [style.linestyle.dotted])
35 c.writeEPSfile("boxalignpac")
37 ###############################################################################
39 c = canvas.canvas()
40 c.stroke(path.line(0, 0, 4, 2), [deco.earrow.Large()])
41 t = text.text(2, 1, r"$\vec e$")
42 t.linealign(0.1, -2/math.sqrt(20), 4/math.sqrt(20))
43 c.insert(t)
44 c.stroke(path.line(0, 0, 6, 2), [deco.earrow.Large()])
45 t = text.text(3, 1, r"$\vec f$")
46 t.linealign(0.1, 2/math.sqrt(60), -6/math.sqrt(60))
47 c.insert(t)
48 c.stroke(path.line(6, 2, 4, 2), [deco.earrow.Large()])
49 t = text.text(5, 2, r"$\vec g$")
50 t.linealign(0.1, 0, 1)
51 c.insert(t)
52 c.stroke(path.line(0, 0, -1, 1), [deco.earrow.Large()])
53 t = text.text(-0.5, 0.5, r"$\vec a$")
54 t.linealign(0.1, -1/math.sqrt(2), -1/math.sqrt(2))
55 c.insert(t)
56 c.stroke(path.path(path.arc(0, 0, math.sqrt(2), 0, 360), path.closepath()), [style.linestyle.dotted])
57 c.stroke(path.line(0, 0, 0, math.sqrt(2)), [deco.earrow.Large()])
58 t = text.text(0, 1/math.sqrt(2), r"$\vec b$")
59 t.linealign(0.1, -1, 0)
60 c.insert(t)
61 c.writeEPSfile("boxalignlac")
63 ###############################################################################
65 def drawexample(canvas, corner, linealign):
66 r = 1.5
67 canvas.stroke(path.path(path.arc(0, 0, r, 0, 360)))
68 phi = 0
69 while phi < 2 * math.pi + 1e-10:
70 if corner:
71 b = box.polygon(center=(0, 0), corners=[(0, 0), (1, 0), (0.5, math.sqrt(3)/2)])
72 else:
73 b = box.polygon(center=(0, 0), corners=[(-0.5, -math.sqrt(3)/6), (0.5, -math.sqrt(3)/6), (0, math.sqrt(3)/3)])
74 if linealign:
75 b.linealign(r, math.cos(phi), math.sin(phi))
76 else:
77 b.circlealign(r, math.cos(phi), math.sin(phi))
78 if round(phi / math.pi * 2 * 100) % 100:
79 canvas.stroke(b.path())
80 else:
81 canvas.stroke(b.path(), [color.rgb.red])
82 phi += math.pi / 50
84 d = 6
85 c = canvas.canvas()
86 sc = c.insert(canvas.canvas([trafo.translate(0, d)]))
87 drawexample(sc, 0, 0)
88 sc = c.insert(canvas.canvas([trafo.translate(d, d)]))
89 drawexample(sc, 0, 1)
90 sc = c.insert(canvas.canvas([trafo.translate(0, 0)]))
91 drawexample(sc, 1, 0)
92 sc = c.insert(canvas.canvas([trafo.translate(d, 0)]))
93 drawexample(sc, 1, 1)
94 c.text(0, 1.5*d, "align at a circle", [text.halign.center])
95 c.text(d, 1.5*d, "align at tangents", [text.halign.center])
96 c.text(-0.5*d, d, "reference point at the triangle center", [text.halign.center, trafo.rotate(90)])
97 c.text(-0.5*d, 0, "reference point at a triangle corner", [text.halign.center, trafo.rotate(90)])
98 c.writeEPSfile("boxalignexample")