move symbol before line
[PyX/mjg.git] / examples / vector.py
blob82b9fb56edefdec5237767deb70892f4e1766249
1 from math import pi, sin, cos
2 from pyx import *
4 def vector(x1, y1, x2, y2, t, pos=0.5, distance=0.1):
5 c = canvas.canvas()
6 c.stroke(path.line(x1, y1, x2, y2), [deco.earrow.normal])
7 textbox = text.text((1-pos)*x1 + pos*x2, (1-pos)*y1 + pos*y2, t,
8 [text.halign.center, text.vshift.mathaxis])
9 if distance < 0:
10 textbox.linealign(-distance, y1 - y2, x2 - x1)
11 else:
12 textbox.linealign(distance, y2 - y1, x1 - x2)
13 c.insert(textbox)
14 return c
16 r = 1.5
17 a = 150
19 c = canvas.canvas()
20 dx, dy = cos(a * pi / 180), sin(a * pi / 180)
21 x, y = r * dx, r * dy
22 c.stroke(path.circle(0, 0, r))
23 c.insert(vector(0, 0, x, y, r"$\vec r$"))
24 c.insert(vector(x, y, x - dy, y + dx, r"$\vec t$", pos=0.7))
25 c.insert(vector(x, y, x + dx, y + dy, r"$\vec n$", pos=0.7))
26 c.writeEPSfile("vector")