1 from math
import pi
, sin
, cos
4 def vector(x1
, y1
, x2
, y2
, t
, pos
=0.5, distance
=0.1,
5 texrunner
=text
.defaulttexrunner
):
7 c
.stroke(path
.line(x1
, y1
, x2
, y2
), [deco
.earrow
.normal
])
8 textbox
= texrunner
.text((1-pos
)*x1
+ pos
*x2
, (1-pos
)*y1
+ pos
*y2
, t
,
9 [text
.halign
.center
, text
.vshift
.mathaxis
])
11 textbox
.linealign(-distance
, y1
- y2
, x2
- x1
)
13 textbox
.linealign(distance
, y2
- y1
, x1
- x2
)
21 dx
, dy
= cos(a
* pi
/ 180), sin(a
* pi
/ 180)
23 c
.stroke(path
.circle(0, 0, r
))
24 c
.insert(vector(0, 0, x
, y
, r
"$\vec r$"))
25 c
.insert(vector(x
, y
, x
- dy
, y
+ dx
, r
"$\vec t$", pos
=0.7))
26 c
.insert(vector(x
, y
, x
+ dx
, y
+ dy
, r
"$\vec n$", pos
=0.7))
27 c
.writetofile("vector")