1 | #!/usr/bin/python -itt
|
---|
2 |
|
---|
3 | import struct
|
---|
4 | import sys
|
---|
5 | import numpy as np
|
---|
6 | from pprint import pprint
|
---|
7 | import rlcompleter
|
---|
8 | import readline
|
---|
9 | readline.parse_and_bind('tab: complete')
|
---|
10 |
|
---|
11 |
|
---|
12 | """
|
---|
13 | drehmatrix:
|
---|
14 |
|
---|
15 | 1 0 0 also in x-richtung wird gedreht mit phi=90 in 0 1 0
|
---|
16 |
|
---|
17 | matrix:
|
---|
18 | 0 0 0 1 0
|
---|
19 | 1 0 0 0 = 1
|
---|
20 | 0 0 0 0 0
|
---|
21 |
|
---|
22 | also
|
---|
23 | cos-p 0 0
|
---|
24 | sin-p 0 0
|
---|
25 | 0 0 0
|
---|
26 |
|
---|
27 | 0 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 |
|
---|
33 | also:
|
---|
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 |
|
---|
38 | damit wird gedreht: 1 0 0 -> 0 1 0 -> -1 0 0 -> 0 -1 0 -> 1 0 0
|
---|
39 |
|
---|
40 | nun mit theta = 90 damit wird 0 0 1 zu 1 0 0
|
---|
41 |
|
---|
42 | also:
|
---|
43 | 0 0 1
|
---|
44 | 0 0 0
|
---|
45 | 0 0 0
|
---|
46 |
|
---|
47 | weiter 1 0 0 --> 0 0 -1
|
---|
48 |
|
---|
49 | also:
|
---|
50 | 0 0 1
|
---|
51 | 0 0 0
|
---|
52 | -1 0 0
|
---|
53 |
|
---|
54 | und damit klappt auch 0 0 -1 auf -1 0 0 und weiter auf 0 0 1
|
---|
55 |
|
---|
56 | das waere jetzt also
|
---|
57 | cos-p cos-t -sin-p sin-t
|
---|
58 | sin-p cos-p ?
|
---|
59 | -sin-t ? cos-t
|
---|
60 |
|
---|
61 |
|
---|
62 | wenn theta = 90 muss auch mit dem einheitsvector in y das richtig passieren
|
---|
63 | nämlich
|
---|
64 | 0 1 0 --> 0 0 -1 -->
|
---|
65 |
|
---|
66 | """
|
---|
67 | class 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 |
|
---|
112 | class 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 |
|
---|