source: fact/tools/pyscripts/simulation/old_and_tests/turn.py@ 14963

Last change on this file since 14963 was 14805, checked in by neise, 12 years ago
initial commit
  • Property svn:executable set to *
File size: 3.2 KB
Line 
1#!/usr/bin/python -itt
2
3import struct
4import sys
5import numpy as np
6from pprint import pprint
7import rlcompleter
8import readline
9readline.parse_and_bind('tab: complete')
10
11
12"""
13drehmatrix:
14
151 0 0 also in x-richtung wird gedreht mit phi=90 in 0 1 0
16
17matrix:
18 0 0 0 1 0
19 1 0 0 0 = 1
20 0 0 0 0 0
21
22also
23 cos-p 0 0
24 sin-p 0 0
25 0 0 0
26
270 1 0 also y-richtung wird weiter gedreht in -1 0 0
28
29 0 -1 0
30 0 0 0
31 0 0 0
32
33also:
34 cos-p -sin-p 0 0 -1 0
35 sin-p cos-p 0 --> 1 0 0
36 0 0 0 0 0 0
37
38damit wird gedreht: 1 0 0 -> 0 1 0 -> -1 0 0 -> 0 -1 0 -> 1 0 0
39
40nun mit theta = 90 damit wird 0 0 1 zu 1 0 0
41
42also:
43 0 0 1
44 0 0 0
45 0 0 0
46
47weiter 1 0 0 --> 0 0 -1
48
49also:
50 0 0 1
51 0 0 0
52-1 0 0
53
54und damit klappt auch 0 0 -1 auf -1 0 0 und weiter auf 0 0 1
55
56das waere jetzt also
57 cos-p cos-t -sin-p sin-t
58 sin-p cos-p ?
59 -sin-t ? cos-t
60
61
62wenn theta = 90 muss auch mit dem einheitsvector in y das richtig passieren
63nämlich
640 1 0 --> 0 0 -1 -->
65
66"""
67class Turn( object ):
68
69 def __init__(self, theta, phi):
70 self.last_result = None
71
72 theta = -theta/180.*np.pi
73 phi = -phi/180.*np.pi
74
75 c = np.cos
76 s = np.sin
77 self.phi = phi
78 self.theta = theta
79 p = phi
80 t = theta
81
82 drehmatrix = np.zeros( (3,3) )
83 self.r = drehmatrix
84 r = self.r
85
86 r[0,0] = c(p)*c(t); r[1,0] = -s(p); r[2,0] = s(t)
87 r[0,1] = s(p); r[1,1] = c(p); r[2,1] = 0
88 r[0,2] = -s(t); r[1,2] = 0; r[2,2] = c(t)
89
90 print r
91
92
93 def __call__( self, vector=None):
94
95 if vector is None and not self.last_result is None:
96 vector = self.last_result
97 elif vector is None:
98 raise ValueError("no argument given")
99 turned_vector = vector.copy()
100 t = turned_vector
101
102 for i in range(3):
103 t[i] = (self.r[i,:] * vector).sum()
104
105
106
107
108 self.last_result = turned_vector
109 return turned_vector
110
111
112class Turner( object ):
113 def __init__(self, theta, phi):
114 self.last_result = None
115
116 theta = -theta/180.*np.pi
117 phi = -phi/180.*np.pi
118
119 c = np.cos
120 s = np.sin
121 self.phi = phi
122 self.theta = theta
123 p = phi
124 t = theta
125
126 drehmatrix = np.zeros( (3,3) )
127 self.r = drehmatrix
128 r = self.r
129
130 r[0,0] = c(p)*c(t); r[1,0] = -s(p); r[2,0] = s(t)
131 r[0,1] = s(p); r[1,1] = c(p); r[2,1] = 0
132 r[0,2] = -s(t); r[1,2] = 0; r[2,2] = c(t)
133
134 print r
135
136
137 def __call__( self, vector=None):
138
139 if vector is None and not self.last_result is None:
140 vector = self.last_result
141 elif vector is None:
142 raise ValueError("no argument given")
143 turned_vector = vector.copy()
144 t = turned_vector
145
146 for i in range(3):
147 t[i] = (self.r[i,:] * vector).sum()
148
149
150
151
152 self.last_result = turned_vector
153 return turned_vector
154
Note: See TracBrowser for help on using the repository browser.