forked from JanisErdmanis/PythonPhysics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
F8.1b.py
90 lines (66 loc) · 2.05 KB
/
F8.1b.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# -*- coding: utf-8 -*-
"""
Created on Sun Aug 18 20:39:36 2013
@author: akels
"""
from __future__ import division, print_function
#from os import sys
#sys.path.append('cpresources')
from pylab import *
from numpy import load
from traits.api import HasTraits,CArray,Float
data = load('F8.1.npy')
teta1 = data[:,0]
teta2 = data[:,1]
from visual import cylinder,sphere,color, rate
class stick(HasTraits):
r_bot = CArray(value=[0,0,0],dtype=float)
r_top = CArray(value=[0,0,0],dtype=float)
def __init__(self):
self.cylinder = cylinder(radius=0.1)
self.sphere = sphere(radius=0.5)
self.sphere.color = color.red
#@on_trait_change('pos_top,pos_bot')
def _r_bot_changed(self,old,new):
#print(' r_bot updated')
self.cylinder.pos = self.r_bot
self.cylinder.axis = self.r_top - self.r_bot #self.pos_axis
def _r_top_changed(self,old,new):
#print('r_top updated')
#print(self.pos_bot + self.pos_axis)
self.sphere.pos = self.r_top#self.pos_bot + self.pos_axis
# Decorator didn't worked
self.cylinder.axis = self.r_top - self.r_bot #self.pos_axis
from cmath import exp
class system(HasTraits):
teta1 = Float()
teta2 = Float()
l = 10
def __init__(self):
self.top = stick()
#self.top.r_top = [5,4,2]
self.bottom = stick()
# How to make it to update automatically
self.bottom.r_bot = self.top.r_top
def _teta1_changed(self,old,new):
r1 = self.l*exp(self.teta1*1j)
r2 = r1 + self.l*exp(self.teta2*1j)
self.top.r_top = r1.imag,-r1.real,0
self.bottom.r_bot = self.top.r_top
self.bottom.r_top = r2.imag,-r2.real,0
def _teta2_changed(self,old,new):
self._teta1_changed(old,new)
#==============================================================================
# test2 = stick()
# test2.pos_axis = [0,4,0]
# test2.pos_bot = [0,5,1]
#==============================================================================
s = system()
s.teta2 = 0.5
s.teta1 = 1
tpoints = linspace(0,100,len(data))
for t,teta1i,teta2i in zip(tpoints,teta1,teta2)[::int(1e3/30)]:
rate(30)
print('t={}'.format(t))
s.teta2 = teta2i
s.teta1 = teta1i