23{
24 std::cout << "\n=== Check rotation around specified axes" << std::endl;
25
28
29 std::cout << "Zero rotation - OK" << std::endl;
32 0, 1, 0,
33 0, 0, 1 ));
36
37 std::cout << "Rotation by 180 degrees around X - OK" << std::endl;
40 0,-1, 0,
41 0, 0,-1 ));
44
45 std::cout << "Rotation by 180 degrees around Y - OK" << std::endl;
48 0, 1, 0,
49 0, 0,-1 ));
52
53 std::cout << "Rotation by 180 degrees around Z - OK" << std::endl;
56 0,-1, 0,
57 0, 0, 1 ));
60
61 std::cout << "Rotation by 180 degrees around XY - OK" << std::endl;
64 1, 0, 0,
65 0, 0,-1 ));
68
69 std::cout << "Rotation by 180 degrees around YZ - OK" << std::endl;
72 0, 0, 1,
73 0, 1, 0 ));
76
77 std::cout << "Rotation by 180 degrees around ZX - OK" << std::endl;
80 0,-1, 0,
81 1, 0, 0 ));
84
85
86
89
90 int step = 1;
91 std::cout << "\n=== Check all possible axes and angles (step = " << step << " degree)" << std::endl;
92
93 for ( int the = 0; the <= 180; the += step) {
94 for ( int phi = 0; phi < 360; phi += step) {
95 for (int a = 0; a < 360; a += step) {
96 double z = std::cos(the*deg);
97 double y = std::sin(the*deg)*sin(phi*deg);
98 double x = std::sin(the*deg)*cos(phi*deg);
99 double ang = a*deg;
100
101
103 matrix.
set(vinput, ang);
104
105
106 voutput = matrix.
axis();
107 double del = matrix.
delta();
108 if (a > 180) {
109 del = CLHEP::twopi - del;
110 voutput = -voutput;
111 }
112
113
114 if (a != 180) assert(
equal(ang,del) );
115
116
117 if (a == 0) continue;
118 if (a == 180 ) {
119 assert(
equal(vinput,voutput) ||
equal(-vinput,voutput));
120 } else {
121 assert(
equal(vinput,voutput) );
122 }
123 }
124 }
125 }
126 std::cout << "OK" << std::endl;
127
128
129
130 int istep = 10000;
131 std::cout << "\n=== Check angles near 0 (step = 1/" << istep << " degree)" << std::endl;
132
133 for ( int the = 0; the <= 180; the += 5) {
134 for ( int phi = 0; phi < 360; phi += 5) {
135 for (int a = -istep; a <= istep; a += 1) {
136 double z = std::cos(the*deg);
137 double y = std::sin(the*deg)*sin(phi*deg);
138 double x = std::sin(the*deg)*cos(phi*deg);
139 double ang = 0. + a * (deg/istep);
140
141
143 matrix.
set(vinput, ang);
144
145
146 voutput = matrix.
axis();
147 double del = matrix.
delta();
148 if (a < 0) {
149 del = -del;
150 voutput = -voutput;
151 }
152
153
154 assert(
equal(ang,del) );
155
156
157 if (a == 0) continue;
158 assert(
equal(vinput,voutput) );
159 }
160 }
161 }
162 std::cout << "OK" << std::endl;
163
164
165
166 istep = 10000;
167 std::cout << "\n=== Check angles near 180 (step = 1/" << istep << " degree)" << std::endl;
168
169 for ( int the = 0; the <= 180; the += 5) {
170 for ( int phi = 0; phi < 360; phi += 5) {
171 for (int a = -istep; a <= istep; a += 1) {
172 double z = std::cos(the*deg);
173 double y = std::sin(the*deg)*sin(phi*deg);
174 double x = std::sin(the*deg)*cos(phi*deg);
175 double ang = pi + a * (deg/istep);
176
177
179 matrix.
set(vinput, ang);
180
181
182 voutput = matrix.
axis();
183 double del = matrix.
delta();
184 if (a > 0) {
185 del = CLHEP::twopi - del;
186 voutput = -voutput;
187 }
188
189
190 if (a != 0) assert(
equal(ang,del) );
191
192
193 if (a == 0 ) {
194 assert(
equal(vinput,voutput) ||
equal(-vinput,voutput));
195 } else {
196 assert(
equal(vinput,voutput) );
197 }
198 }
199 }
200 }
201 std::cout << "OK" << std::endl;
202
203 std::cout << std::endl;
204 return 0 ;
205}
void set(double x, double y, double z)
HepRotation & set(const Hep3Vector &axis, double delta)
bool equal(double a, double b)