Debian Codegraph @

examples/tvtk/visual/orbit.py

raw symbols SCIP
1 #!/usr/bin/env python
2 """A simple example demonstrating the creation of actors and animating
3 the in a scene using visual modeule."""
4 # Author: Raashid Baig <[email protected]>
5 # License: BSD Style.
6
7 from math import sqrt
8
9 from tvtk.tools.visual import sphere, iterate, show, vector, curve
10
11 #Creating the actors for the scene
12 giant = sphere(pos=(-1.0e11, 0, 0),
13 radius=2e10,
14 color=(1, 0, 0),
15 mass=2e30)
16
17 dwarf = sphere(pos=(1.5e11, 0, 0),
18 radius=1e10,
19 color=(1, 1, 0),
20 mass=1e30)
21
22 giant.p = vector(0, 0, -1e4) * giant.mass
23 dwarf.p = -1*giant.p
24
25 # creating the curve which will trace the paths of actors
26 for a in [giant, dwarf]:
27 a.orbit = curve(radius=2e9, color=a.color)
28
29 dt = 86400
30
31 def anim():
32 #Creating the animation function which will be called at
33 #uniform timeperiod through the iterate function
34 dist = dwarf.pos - giant.pos
35 force = 6.7e-11 * giant.mass * dwarf.mass * \
36 dist/(sqrt(dist[0]**2 + dist[1]**2 + dist[2]**2))**3
37 giant.p = giant.p + force*dt
38 dwarf.p = dwarf.p - force*dt
39
40 for a in [giant, dwarf]:
41 a.pos = a.pos + (a.p/a.mass)*dt
42 a.orbit.append(a.pos)
43 p = a.orbit.points
44 if len(p) > 1000:
45 a.orbit.points = p[200:]
46
47 a = iterate(50, anim)
48 a.edit_traits()
49 show()