CMS 3D CMS Logo

extTkRotation.h
Go to the documentation of this file.
1 #ifndef Geom_newTkRotation_H
2 #define Geom_newTkRotation_H
3 
7 
9 
10 
11 #include <iosfwd>
12 
13 template <class T> class TkRotation;
14 template <class T> class TkRotation2D;
15 
16 template <class T>
17 std::ostream & operator<<( std::ostream& s, const TkRotation<T>& r);
18 template <class T>
19 std::ostream & operator<<( std::ostream& s, const TkRotation2D<T>& r);
20 
21 namespace geometryDetails {
22  void TkRotationErr1();
23  void TkRotationErr2();
24 
25 }
26 
27 
31 template <class T>
32 class TkRotation {
33 public:
34 
37 
39  TkRotation( Rot3<T> const & irot ) : rot(irot){}
40 
41  TkRotation( T xx, T xy, T xz, T yx, T yy, T yz, T zx, T zy, T zz) :
42  rot(xx,xy,xz, yx,yy,yz, zx, zy,zz){}
43 
44  TkRotation( const T* p) :
45  rot(p[0],p[1],p[2],
46  p[3],p[4],p[5],
47  p[6],p[7],p[8]) {}
48 
49  TkRotation( const GlobalVector & aX, const GlobalVector & aY) {
50 
51  GlobalVector uX = aX.unit();
52  GlobalVector uY = aY.unit();
53  GlobalVector uZ(uX.cross(uY));
54 
55  rot.axis[0]= uX.basicVector().v;
56  rot.axis[1]= uY.basicVector().v;
57  rot.axis[2]= uZ.basicVector().v;
58 
59  }
60 
61  TkRotation( const BasicVector & aX, const BasicVector & aY) {
62 
63  BasicVector uX = aX.unit();
64  BasicVector uY = aY.unit();
65  BasicVector uZ(uX.cross(uY));
66 
67  rot.axis[0]= uX.v;
68  rot.axis[1]= uY.v;
69  rot.axis[2]= uZ.v;
70 
71  }
72 
73 
78  TkRotation( const GlobalVector & uX, const GlobalVector & uY,
79  const GlobalVector & uZ) {
80  rot.axis[0]= uX.basicVector().v;
81  rot.axis[1]= uY.basicVector().v;
82  rot.axis[2]= uZ.basicVector().v;
83  }
84 
85  TkRotation( const BasicVector & uX, const BasicVector & uY,
86  const BasicVector & uZ) {
87  rot.axis[0]= uX.v;
88  rot.axis[1]= uY.v;
89  rot.axis[2]= uZ.v;
90  }
91 
92 
101  TkRotation( const Basic3DVector<T>& axis, T phi) :
102  rot( cos(phi), sin(phi), 0,
103  -sin(phi), cos(phi), 0,
104  0, 0, 1) {
105 
106  //rotation around the z-axis by phi
107  TkRotation tmpRotz ( cos(axis.phi()), sin(axis.phi()), 0.,
108  -sin(axis.phi()), cos(axis.phi()), 0.,
109  0., 0., 1. );
110  //rotation around y-axis by theta
111  TkRotation tmpRoty ( cos(axis.theta()), 0.,-sin(axis.theta()),
112  0., 1., 0.,
113  sin(axis.theta()), 0., cos(axis.theta()) );
114  (*this)*=tmpRoty;
115  (*this)*=tmpRotz; // = this * tmpRoty * tmpRotz
116 
117  // (tmpRoty * tmpRotz)^-1 * this * tmpRoty * tmpRotz
118 
119  *this = (tmpRoty*tmpRotz).multiplyInverse(*this);
120 
121  }
122  /* this is the same thing...derived from the CLHEP ... it gives the
123  same results MODULO the sign of the rotation.... but I don't want
124  that... had
125  TkRotation (const Basic3DVector<T>& axis, float phi) {
126  T cx = axis.x();
127  T cy = axis.y();
128  T cz = axis.z();
129 
130  T ll = axis.mag();
131  if (ll == 0) {
132  geometryDetails::TkRotationErr1();
133  }else{
134 
135  float cosa = cos(phi), sina = sin(phi);
136  cx /= ll; cy /= ll; cz /= ll;
137 
138  R11 = cosa + (1-cosa)*cx*cx;
139  R12 = (1-cosa)*cx*cy - sina*cz;
140  R13 = (1-cosa)*cx*cz + sina*cy;
141 
142  R21 = (1-cosa)*cy*cx + sina*cz;
143  R22 = cosa + (1-cosa)*cy*cy;
144  R23 = (1-cosa)*cy*cz - sina*cx;
145 
146  R31 = (1-cosa)*cz*cx - sina*cy;
147  R32 = (1-cosa)*cz*cy + sina*cx;
148  R33 = cosa + (1-cosa)*cz*cz;
149 
150  }
151 
152  }
153  */
154 
155  template <typename U>
157  rot (a.xx(), a.xy(), a.xz(),
158  a.yx(), a.yy(), a.yz(),
159  a.zx(), a.zy(), a.zz()) {}
160 
162  return rot.transpose();
163  }
164 
166  return rot.rotate(v.v);
167  }
168 
170  return rot.rotateBack(v.v);
171  }
172 
173 
175  return rot.rotate(v.v);
176  }
177 
179  return rot.rotateBack(v.v);
180  }
181 
182  template <class Scalar>
184  return Basic3DVector<Scalar>( xx()*v.x() + yx()*v.y() + zx()*v.z(),
185  xy()*v.x() + yy()*v.y() + zy()*v.z(),
186  xz()*v.x() + yz()*v.y() + zz()*v.z());
187  }
188 
190  return Basic3DVector<T>( xx()*v.x() + xy()*v.y(),
191  yx()*v.x() + yy()*v.y(),
192  zx()*v.x() + zy()*v.y());
193  }
195  return Basic3DVector<T>( xx()*v.x() + yx()*v.y(),
196  xy()*v.x() + yy()*v.y(),
197  xz()*v.x() + yz()*v.y());
198  }
199 
200 
201 
202  TkRotation operator*( const TkRotation& b) const {
203  return rot*b.rot;
204  }
206  return rot.transpose()*b.rot;
207  }
208 
210  return *this = operator * (b);
211  }
212 
213  // Note a *= b; <=> a = a * b; while a.transform(b); <=> a = b * a;
215  return *this = b.operator * (*this);
216  }
217 
219  const Basic3DVector<T>& newY,
220  const Basic3DVector<T>& newZ) {
221  T del = 0.001;
222 
223  if (
224 
225  // the check for right-handedness is not needed since
226  // we want to change the handedness when it's left in cmsim
227  //
228  // fabs(newZ.x()-w.x()) > del ||
229  // fabs(newZ.y()-w.y()) > del ||
230  // fabs(newZ.z()-w.z()) > del ||
231  fabs(newX.mag2()-1.) > del ||
232  fabs(newY.mag2()-1.) > del ||
233  fabs(newZ.mag2()-1.) > del ||
234  fabs(newX.dot(newY)) > del ||
235  fabs(newY.dot(newZ)) > del ||
236  fabs(newZ.dot(newX)) > del) {
238  return *this;
239  } else {
240  return transform(TkRotation(newX.x(), newY.x(), newZ.x(),
241  newX.y(), newY.y(), newZ.y(),
242  newX.z(), newY.z(), newZ.z()));
243  }
244  }
245 
246 
247  Basic3DVector<T> x() const { return rot.axis[0];}
248  Basic3DVector<T> y() const { return rot.axis[1];}
249  Basic3DVector<T> z() const { return rot.axis[2];}
250 
251  T xx() const { return rot.axis[0][0];}
252  T xy() const { return rot.axis[0][1];}
253  T xz() const { return rot.axis[0][2];}
254  T yx() const { return rot.axis[1][0];}
255  T yy() const { return rot.axis[1][1];}
256  T yz() const { return rot.axis[1][2];}
257  T zx() const { return rot.axis[2][0];}
258  T zy() const { return rot.axis[2][1];}
259  T zz() const { return rot.axis[2][2];}
260 
261 private:
262 
264 
265 };
266 
267 
268 template<>
269 std::ostream & operator<< <float>( std::ostream& s, const TkRotation<float>& r);
270 
271 template<>
272 std::ostream & operator<< <double>( std::ostream& s, const TkRotation<double>& r);
273 
274 
275 template <class T, class U>
277  return Basic3DVector<U>( r.xx()*v.x() + r.xy()*v.y() + r.xz()*v.z(),
278  r.yx()*v.x() + r.yy()*v.y() + r.yz()*v.z(),
279  r.zx()*v.x() + r.zy()*v.y() + r.zz()*v.z());
280 }
281 
282 template <class T, class U>
286  return RT( a.xx()*b.xx() + a.xy()*b.yx() + a.xz()*b.zx(),
287  a.xx()*b.xy() + a.xy()*b.yy() + a.xz()*b.zy(),
288  a.xx()*b.xz() + a.xy()*b.yz() + a.xz()*b.zz(),
289  a.yx()*b.xx() + a.yy()*b.yx() + a.yz()*b.zx(),
290  a.yx()*b.xy() + a.yy()*b.yy() + a.yz()*b.zy(),
291  a.yx()*b.xz() + a.yy()*b.yz() + a.yz()*b.zz(),
292  a.zx()*b.xx() + a.zy()*b.yx() + a.zz()*b.zx(),
293  a.zx()*b.xy() + a.zy()*b.yy() + a.zz()*b.zy(),
294  a.zx()*b.xz() + a.zy()*b.yz() + a.zz()*b.zz());
295 }
296 
297 
298 template <class T>
299 class TkRotation2D {
300 public:
301 
303 
305  TkRotation2D( Rot2<T> const & irot ) : rot(irot){}
306 
307  TkRotation2D( T xx, T xy, T yx, T yy) :
308  rot(xx,xy, yx,yy){}
309 
310  TkRotation2D( const T* p) :
311  rot(p[0],p[1],
312  p[2],p[3]) {}
313 
314  TkRotation2D( const BasicVector & aX) {
315 
316  BasicVector uX = aX.unit();
317  BasicVector uY(-uX.y(),uX.x());
318 
319  rot.axis[0]= uX.v;
320  rot.axis[1]= uY.v;
321 
322  }
323 
324 
325  TkRotation2D( const BasicVector & uX, const BasicVector & uY) {
326  rot.axis[0]= uX.v;
327  rot.axis[1]= uY.v;
328  }
329 
330  BasicVector x() const { return rot.axis[0];}
331  BasicVector y() const { return rot.axis[1];}
332 
333 
335  return rot.transpose();
336  }
337 
338  BasicVector rotate( const BasicVector& v) const {
339  return rot.rotate(v.v);
340  }
341 
343  return rot.rotateBack(v.v);
344  }
345 
346 
347 
348  private:
349 
351 
352 };
353 
354 
355 template<>
356 std::ostream & operator<< <float>( std::ostream& s, const TkRotation2D<float>& r);
357 
358 template<>
359 std::ostream & operator<< <double>( std::ostream& s, const TkRotation2D<double>& r);
360 
361 
362 #endif
363 
364 
365 
366 
Vector3DBase
Definition: Vector3DBase.h:8
TkRotation
Definition: extTkRotation.h:13
Basic3DVector::theta
Geom::Theta< T > theta() const
Definition: extBasic3DVector.h:139
TkRotation::zy
T zy() const
Definition: extTkRotation.h:258
TkRotation::rotateBack
Basic3DVector< T > rotateBack(const Basic3DVector< T > &v) const
Definition: extTkRotation.h:169
TkRotation2D::TkRotation2D
TkRotation2D(T xx, T xy, T yx, T yy)
Definition: extTkRotation.h:307
TkRotation::TkRotation
TkRotation(const BasicVector &aX, const BasicVector &aY)
Definition: extTkRotation.h:61
TkRotation::operator*=
TkRotation & operator*=(const TkRotation &b)
Definition: extTkRotation.h:209
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
operator<<< double >
std::ostream & operator<<< double >(std::ostream &s, const TkRotation< double > &r)
TkRotation2D::x
BasicVector x() const
Definition: extTkRotation.h:330
Basic2DVector::v
Vec2< T > v
Definition: extBasic2DVector.h:156
Basic3DVector.h
TkRotation::TkRotation
TkRotation(const GlobalVector &uX, const GlobalVector &uY, const GlobalVector &uZ)
Definition: extTkRotation.h:78
operator<<
std::ostream & operator<<(std::ostream &s, const TkRotation< T > &r)
TkRotation2D::rotateBack
BasicVector rotateBack(const BasicVector &v) const
Definition: extTkRotation.h:342
TkRotation::multiplyInverse
Basic3DVector< T > multiplyInverse(const Basic3DVector< T > &v) const
Definition: extTkRotation.h:178
TkRotation2D
Definition: extTkRotation.h:14
TkRotation::operator*
TkRotation operator*(const TkRotation &b) const
Definition: extTkRotation.h:202
findQualityFiles.v
v
Definition: findQualityFiles.py:179
Basic3DVector::mag2
T mag2() const
The vector magnitude squared. Equivalent to vec.dot(vec)
Definition: extBasic3DVector.h:113
funct::sin
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
TkRotation2D::TkRotation2D
TkRotation2D()
Definition: extTkRotation.h:304
alignCSCRings.s
s
Definition: alignCSCRings.py:92
Basic3DVector::y
T y() const
Cartesian y coordinate.
Definition: extBasic3DVector.h:97
Vector3DBase::unit
Vector3DBase unit() const
Definition: Vector3DBase.h:54
funct::cos
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Basic2DVector::y
T y() const
Cartesian y coordinate.
Definition: extBasic2DVector.h:67
TkRotation::operator*
Basic3DVector< T > operator*(const Basic2DVector< T > &v) const
Definition: extTkRotation.h:189
geometryDetails::TkRotationErr2
void TkRotationErr2()
Definition: TkRotation.cc:30
ExtVec.h
TkRotation::xz
T xz() const
Definition: extTkRotation.h:253
Basic3DVector::cross
Basic3DVector cross(const Basic3DVector &lh) const
Vector product, or "cross" product, with a vector of same type.
Definition: extBasic3DVector.h:203
Basic3DVector::dot
T dot(const Basic3DVector &rh) const
Scalar product, or "dot" product, with a vector of same type.
Definition: extBasic3DVector.h:189
Basic2DVector::x
T x() const
Cartesian x coordinate.
Definition: extBasic2DVector.h:64
TkRotation::TkRotation
TkRotation(const BasicVector &uX, const BasicVector &uY, const BasicVector &uZ)
Definition: extTkRotation.h:85
TkRotation::TkRotation
TkRotation(const T *p)
Definition: extTkRotation.h:44
b
double b
Definition: hdecay.h:118
TkRotation::TkRotation
TkRotation(const GlobalVector &aX, const GlobalVector &aY)
Definition: extTkRotation.h:49
TkRotation2D::rotate
BasicVector rotate(const BasicVector &v) const
Definition: extTkRotation.h:338
geometryCSVtoXML.xy
xy
Definition: geometryCSVtoXML.py:19
TkRotation::yx
T yx() const
Definition: extTkRotation.h:254
Basic2DVector
Definition: extBasic2DVector.h:15
TkRotation2D::BasicVector
Basic2DVector< T > BasicVector
Definition: extTkRotation.h:302
TkRotation::multiplyInverse
TkRotation multiplyInverse(const TkRotation &b) const
Definition: extTkRotation.h:205
TkRotation::BasicVector
Basic3DVector< T > BasicVector
Definition: extTkRotation.h:36
a
double a
Definition: hdecay.h:119
TkRotation::xx
T xx() const
Definition: extTkRotation.h:251
TkRotation2D::rot
Rot2< T > rot
Definition: extTkRotation.h:350
geometryCSVtoXML.yy
yy
Definition: geometryCSVtoXML.py:19
TkRotation2D::TkRotation2D
TkRotation2D(Rot2< T > const &irot)
Definition: extTkRotation.h:305
TkRotation::TkRotation
TkRotation(const Basic3DVector< T > &axis, T phi)
Definition: extTkRotation.h:101
TkRotation::xy
T xy() const
Definition: extTkRotation.h:252
Vector3DBase::cross
Vector3DBase< typename PreciseFloatType< T, U >::Type, FrameTag > cross(const Vector3DBase< U, FrameTag > &v) const
Definition: Vector3DBase.h:110
operator<<< float >
std::ostream & operator<<< float >(std::ostream &s, const TkRotation< float > &r)
TkRotation::transform
TkRotation & transform(const TkRotation &b)
Definition: extTkRotation.h:214
TkRotation::zz
T zz() const
Definition: extTkRotation.h:259
TkRotation2D::TkRotation2D
TkRotation2D(const BasicVector &aX)
Definition: extTkRotation.h:314
geometryDetails
Definition: extTkRotation.h:21
TkRotation::GlobalVector
Vector3DBase< T, GlobalTag > GlobalVector
Definition: extTkRotation.h:35
Basic2DVector::unit
Basic2DVector unit() const
Definition: extBasic2DVector.h:88
Basic3DVector::v
Vec4< T > v
Definition: extBasic3DVector.h:217
PV3DBase::basicVector
const BasicVectorType & basicVector() const
Definition: PV3DBase.h:53
TkRotation::y
Basic3DVector< T > y() const
Definition: extTkRotation.h:248
geometryDetails::TkRotationErr1
void TkRotationErr1()
Definition: TkRotation.cc:29
alignCSCRings.r
r
Definition: alignCSCRings.py:93
TkRotation::yz
T yz() const
Definition: extTkRotation.h:256
TkRotation::rotate
Basic3DVector< T > rotate(const Basic3DVector< T > &v) const
Definition: extTkRotation.h:165
DDAxes::phi
TkRotation::TkRotation
TkRotation(const TkRotation< U > &a)
Definition: extTkRotation.h:156
Rot3
Definition: ExtVec.h:181
TkRotation::rotateAxes
TkRotation & rotateAxes(const Basic3DVector< T > &newX, const Basic3DVector< T > &newY, const Basic3DVector< T > &newZ)
Definition: extTkRotation.h:218
Basic2DVector.h
T
long double T
Definition: Basic3DVectorLD.h:48
TkRotation::yy
T yy() const
Definition: extTkRotation.h:255
TkRotation::TkRotation
TkRotation()
Definition: extTkRotation.h:38
Rot2
Definition: ExtVec.h:227
GlobalVector.h
Basic3DVector::x
T x() const
Cartesian x coordinate.
Definition: extBasic3DVector.h:94
TkRotation::transposed
TkRotation transposed() const
Definition: extTkRotation.h:161
operator*
Basic3DVector< U > operator*(const TkRotation< T > &r, const Basic3DVector< U > &v)
Definition: extTkRotation.h:276
TkRotation::x
Basic3DVector< T > x() const
Definition: extTkRotation.h:247
TkRotation2D::y
BasicVector y() const
Definition: extTkRotation.h:331
TkRotation::TkRotation
TkRotation(T xx, T xy, T xz, T yx, T yy, T yz, T zx, T zy, T zz)
Definition: extTkRotation.h:41
TkRotation::rot
Rot3< T > rot
Definition: extTkRotation.h:263
TkRotation::zx
T zx() const
Definition: extTkRotation.h:257
Basic3DVector::z
T z() const
Cartesian z coordinate.
Definition: extBasic3DVector.h:100
Basic3DVector::unit
Basic3DVector unit() const
Definition: extBasic3DVector.h:151
Basic3DVector::phi
Geom::Phi< T > phi() const
Definition: extBasic3DVector.h:132
TkRotation2D::transposed
TkRotation2D transposed() const
Definition: extTkRotation.h:334
TkRotation2D::TkRotation2D
TkRotation2D(const BasicVector &uX, const BasicVector &uY)
Definition: extTkRotation.h:325
TkRotation::TkRotation
TkRotation(Rot3< T > const &irot)
Definition: extTkRotation.h:39
Basic3DVector
Definition: extBasic3DVector.h:30
geometryCSVtoXML.xx
xx
Definition: geometryCSVtoXML.py:19
TkRotation::z
Basic3DVector< T > z() const
Definition: extTkRotation.h:249
TkRotation2D::TkRotation2D
TkRotation2D(const T *p)
Definition: extTkRotation.h:310
TkRotation::multiplyInverse
Basic3DVector< Scalar > multiplyInverse(const Basic3DVector< Scalar > &v) const
Definition: extTkRotation.h:183
TkRotation::operator*
Basic3DVector< T > operator*(const Basic3DVector< T > &v) const
Definition: extTkRotation.h:174
TkRotation::multiplyInverse
Basic3DVector< T > multiplyInverse(const Basic2DVector< T > &v) const
Definition: extTkRotation.h:194