Logo ROOT   6.08/07
Reference Guide
TRotation.h
Go to the documentation of this file.
1 // @(#)root/physics:$Id$
2 // Author: Peter Malzacher 19/06/99
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 #ifndef ROOT_TRotation
12 #define ROOT_TRotation
13 
14 #include "TObject.h"
15 
16 #ifndef ROOT_TVector3
17 #include "TVector3.h"
18 #endif
19 
20 class TQuaternion;
21 
22 class TRotation : public TObject {
23 
24 public:
25 
26 class TRotationRow {
27 public:
28  inline TRotationRow(const TRotation &, int);
29  inline TRotationRow(const TRotationRow &);
30  inline TRotationRow & operator=(const TRotationRow &);
31  inline Double_t operator [] (int) const;
32 private:
33  const TRotation * fRR;
34  // const TRotation & fRR;
35  int fII;
36 };
37  // Helper class for implemention of C-style subscripting r[i][j]
38 
39  TRotation();
40  // Default constructor. Gives a unit matrix.
41 
42  TRotation(const TRotation &);
43  TRotation(const TQuaternion &);
44  // Copy constructor.
45 
46  virtual ~TRotation() {;};
47 
48  inline Double_t XX() const;
49  inline Double_t XY() const;
50  inline Double_t XZ() const;
51  inline Double_t YX() const;
52  inline Double_t YY() const;
53  inline Double_t YZ() const;
54  inline Double_t ZX() const;
55  inline Double_t ZY() const;
56  inline Double_t ZZ() const;
57  // Elements of the rotation matrix (Geant4).
58 
59  inline TRotationRow operator [] (int) const;
60  // Returns object of the helper class for C-style subscripting r[i][j]
61 
62  Double_t operator () (int, int) const;
63  // Fortran-style subscripting: returns (i,j) element of the rotation matrix.
64 
65  inline TRotation & operator = (const TRotation &);
66  // Assignment.
67 
68  inline Bool_t operator == (const TRotation &) const;
69  inline Bool_t operator != (const TRotation &) const;
70  // Comparisons (Geant4).
71 
72  inline Bool_t IsIdentity() const;
73  // Returns true if the identity matrix (Geant4).
74 
75  inline TVector3 operator * (const TVector3 &) const;
76  // Multiplication with a TVector3.
77 
78  TRotation operator * (const TRotation &) const;
79  inline TRotation & operator *= (const TRotation &);
80  inline TRotation & Transform(const TRotation &);
81  // Matrix multiplication.
82  // Note a *= b; <=> a = a * b; while a.transform(b); <=> a = b * a;
83 
84  inline TRotation Inverse() const;
85  // Returns the inverse.
86 
87  inline TRotation & Invert();
88  // Inverts the Rotation matrix.
89 
91  // Rotation around the x-axis.
92 
94  // Rotation around the y-axis.
95 
97  // Rotation around the z-axis.
98 
99  TRotation & Rotate(Double_t, const TVector3 &);
100  inline TRotation & Rotate(Double_t, const TVector3 *);
101  // Rotation around a specified vector.
102 
103  TRotation & RotateAxes(const TVector3 & newX,
104  const TVector3 & newY,
105  const TVector3 & newZ);
106  // Rotation of local axes (Geant4).
107 
108  Double_t PhiX() const;
109  Double_t PhiY() const;
110  Double_t PhiZ() const;
111  Double_t ThetaX() const;
112  Double_t ThetaY() const;
113  Double_t ThetaZ() const;
114  // Return angles (RADS) made by rotated axes against original axes (Geant4).
115 
116  void AngleAxis(Double_t &, TVector3 &) const;
117  // Returns the rotation angle and rotation axis (Geant4).
118 
119  inline TRotation & SetToIdentity();
120  // Set equal to the identity rotation.
121 
123  void SetXPhi(Double_t);
124  void SetXTheta(Double_t);
125  void SetXPsi(Double_t);
126  // Set the euler angles of the rotation. The angles are defined using the
127  // y-convention which rotates around the Z axis, around the new X axis, and
128  // then around the new Z axis. The x-convention is used Goldstein, Landau
129  // and Lifshitz, and other common physics texts. Contrast this with
130  // SetYEulerAngles.
131 
133  // Adds a rotation of the local axes defined by the Euler angle to the
134  // current rotation. See SetXEulerAngles for a note about conventions.
135 
136  Double_t GetXPhi(void) const;
137  Double_t GetXTheta(void) const;
138  Double_t GetXPsi(void) const;
139  // Return the euler angles of the rotation. See SetYEulerAngles for a
140  // note about conventions.
141 
143  void SetYPhi(Double_t);
144  void SetYTheta(Double_t);
145  void SetYPsi(Double_t);
146  // Set the euler angles of the rotation. The angles are defined using the
147  // y-convention which rotates around the Z axis, around the new Y axis, and
148  // then around the new Z axis. The x-convention is used Goldstein, Landau
149  // and Lifshitz, and other common physics texts and is a rotation around the
150  // Z axis, around the new X axis, and then around the new Z axis.
151 
153  // Adds a rotation of the local axes defined by the Euler angle to the
154  // current rotation. See SetYEulerAngles for a note about conventions.
155 
156  Double_t GetYPhi(void) const;
157  Double_t GetYTheta(void) const;
158  Double_t GetYPsi(void) const;
159  // Return the euler angles of the rotation. See SetYEulerAngles for a
160  // note about conventions.
161 
162  TRotation & SetXAxis(const TVector3& axis);
163  TRotation & SetXAxis(const TVector3& axis, const TVector3& xyPlane);
164  TRotation & SetYAxis(const TVector3& axis);
165  TRotation & SetYAxis(const TVector3& axis, const TVector3& yzPlane);
166  TRotation & SetZAxis(const TVector3& axis);
167  TRotation & SetZAxis(const TVector3& axis, const TVector3& zxPlane);
168  // Create a rotation with the axis vector parallel to the rotated coordinate
169  // system. If a second vector is provided it defines a plane passing
170  // through the axis.
171 
172  void MakeBasis(TVector3& xAxis, TVector3& yAxis, TVector3& zAxis) const;
173  // Take two input vectors (in xAxis, and zAxis) and turn them into an
174  // orthogonal basis. This is an internal helper function used to implement
175  // the Set?Axis functions, but is exposed because the functionality is
176  // often useful.
177 
178 protected:
179 
182  // Protected constructor.
183 
185  // The matrix elements.
186 
187  ClassDef(TRotation,1) // Rotations of TVector3 objects
188 
189 };
190 
191 
192 inline Double_t TRotation::XX() const { return fxx; }
193 inline Double_t TRotation::XY() const { return fxy; }
194 inline Double_t TRotation::XZ() const { return fxz; }
195 inline Double_t TRotation::YX() const { return fyx; }
196 inline Double_t TRotation::YY() const { return fyy; }
197 inline Double_t TRotation::YZ() const { return fyz; }
198 inline Double_t TRotation::ZX() const { return fzx; }
199 inline Double_t TRotation::ZY() const { return fzy; }
200 inline Double_t TRotation::ZZ() const { return fzz; }
201 
203 (const TRotation & r, int i) : fRR(&r), fII(i) {}
204 
206 (const TRotationRow & rr) : fRR(rr.fRR), fII(rr.fII) {}
207 
209  fRR = rr.fRR;
210  fII = rr.fII;
211  return *this;
212 }
213 
215  return fRR->operator()(fII,jj);
216 }
217 
219  return TRotationRow(*this, i);
220 }
221 
223  fxx = m.fxx;
224  fxy = m.fxy;
225  fxz = m.fxz;
226  fyx = m.fyx;
227  fyy = m.fyy;
228  fyz = m.fyz;
229  fzx = m.fzx;
230  fzy = m.fzy;
231  fzz = m.fzz;
232  return *this;
233 }
234 
236  return (fxx == m.fxx && fxy == m.fxy && fxz == m.fxz &&
237  fyx == m.fyx && fyy == m.fyy && fyz == m.fyz &&
238  fzx == m.fzx && fzy == m.fzy && fzz == m.fzz) ? kTRUE : kFALSE;
239 }
240 
242  return (fxx != m.fxx || fxy != m.fxy || fxz != m.fxz ||
243  fyx != m.fyx || fyy != m.fyy || fyz != m.fyz ||
244  fzx != m.fzx || fzy != m.fzy || fzz != m.fzz) ? kTRUE : kFALSE;
245 }
246 
248  return (fxx == 1.0 && fxy == 0.0 && fxz == 0.0 &&
249  fyx == 0.0 && fyy == 1.0 && fyz == 0.0 &&
250  fzx == 0.0 && fzy == 0.0 && fzz == 1.0) ? kTRUE : kFALSE;
251 }
252 
254  fxx = fyy = fzz = 1.0;
255  fxy = fxz = fyx = fyz = fzx = fzy = 0.0;
256  return *this;
257 }
258 
259 inline TVector3 TRotation::operator * (const TVector3 & p) const {
260  return TVector3(fxx*p.X() + fxy*p.Y() + fxz*p.Z(),
261  fyx*p.X() + fyy*p.Y() + fyz*p.Z(),
262  fzx*p.X() + fzy*p.Y() + fzz*p.Z());
263 }
264 
266  return *this = operator * (m);
267 }
268 
270  return *this = m.operator * (*this);
271 }
272 
274  return TRotation(fxx, fyx, fzx, fxy, fyy, fzy, fxz, fyz, fzz);
275 }
276 
278  return *this=Inverse();
279 }
280 
281 inline TRotation & TRotation::Rotate(Double_t psi, const TVector3 * p) {
282  return Rotate(psi, *p);
283 }
284 
285 
286 
287 #endif
Double_t X() const
Definition: TVector3.h:224
TRotation & RotateYEulerAngles(Double_t phi, Double_t theta, Double_t psi)
Rotate using the y-convention.
Definition: TRotation.cxx:526
Double_t PhiY() const
Return Phi.
Definition: TRotation.cxx:428
Double_t operator[](int) const
Definition: TRotation.h:214
Double_t ZY() const
Definition: TRotation.h:199
TRotation & RotateZ(Double_t)
Rotate around z.
Definition: TRotation.cxx:378
Double_t fyy
Definition: TRotation.h:184
Double_t XZ() const
Definition: TRotation.h:194
Double_t fzy
Definition: TRotation.h:184
Quaternion is a 4-component mathematic object quite convenient when dealing with space rotation (or r...
Definition: TQuaternion.h:15
TRotation & RotateX(Double_t)
Rotate around x.
Definition: TRotation.cxx:346
Double_t fzx
Definition: TRotation.h:184
Double_t operator()(int, int) const
Dereferencing operator const.
Definition: TRotation.cxx:219
Double_t GetXPsi(void) const
Get psi angle.
Definition: TRotation.cxx:645
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
void SetYPsi(Double_t)
Set YPsi.
Definition: TRotation.cxx:572
TRotation & operator=(const TRotation &)
Definition: TRotation.h:222
Double_t YX() const
Definition: TRotation.h:195
TRotation & SetXAxis(const TVector3 &axis)
Set X axis.
Definition: TRotation.cxx:713
TRotation & RotateAxes(const TVector3 &newX, const TVector3 &newY, const TVector3 &newZ)
Rotate axes.
Definition: TRotation.cxx:394
Double_t fxy
Definition: TRotation.h:184
Double_t PhiX() const
Return Phi.
Definition: TRotation.cxx:421
#define ClassDef(name, id)
Definition: Rtypes.h:254
void SetXPhi(Double_t)
Set XPhi.
Definition: TRotation.cxx:537
Double_t Y() const
Definition: TVector3.h:225
Double_t YZ() const
Definition: TRotation.h:197
TRotation & SetToIdentity()
Definition: TRotation.h:253
Double_t fzz
Definition: TRotation.h:184
void SetYTheta(Double_t)
Set YTheta.
Definition: TRotation.cxx:565
void SetXTheta(Double_t)
Set XTheta.
Definition: TRotation.cxx:544
TRotation & Rotate(Double_t, const TVector3 &)
Rotate along an axis.
Definition: TRotation.cxx:325
Double_t fyx
Definition: TRotation.h:184
TVector3 is a general three vector class, which can be used for the description of different vectors ...
Definition: TVector3.h:30
TRotation & Transform(const TRotation &)
Definition: TRotation.h:269
Double_t Z() const
Definition: TVector3.h:226
The TRotation class describes a rotation of objects of the TVector3 class.
Definition: TRotation.h:22
Double_t YY() const
Definition: TRotation.h:196
TRandom2 r(17)
TRotation & SetYAxis(const TVector3 &axis)
Set Y axis.
Definition: TRotation.cxx:736
TRotationRow & operator=(const TRotationRow &)
Definition: TRotation.h:208
TMarker * m
Definition: textangle.C:8
TRotation & Invert()
Definition: TRotation.h:277
Double_t fxx
Definition: TRotation.h:184
Double_t ZX() const
Definition: TRotation.h:198
TRotation & RotateXEulerAngles(Double_t phi, Double_t theta, Double_t psi)
Rotate using the x-convention.
Definition: TRotation.cxx:515
Double_t PhiZ() const
Return Phi.
Definition: TRotation.cxx:435
Double_t XY() const
Definition: TRotation.h:193
void AngleAxis(Double_t &, TVector3 &) const
Rotation defined by an angle and a vector.
Definition: TRotation.cxx:463
Double_t GetYTheta(void) const
Return YTheta.
Definition: TRotation.cxx:638
Bool_t IsIdentity() const
Definition: TRotation.h:247
void SetYPhi(Double_t)
Set YPhi.
Definition: TRotation.cxx:558
virtual ~TRotation()
Definition: TRotation.h:46
Bool_t operator!=(const TRotation &) const
Definition: TRotation.h:241
Double_t GetYPhi(void) const
Return YPhi.
Definition: TRotation.cxx:624
double Double_t
Definition: RtypesCore.h:55
Double_t GetXPhi(void) const
Return phi angle.
Definition: TRotation.cxx:579
TRotation & RotateY(Double_t)
Rotate around y.
Definition: TRotation.cxx:362
TRotation Inverse() const
Definition: TRotation.h:273
Mother of all ROOT objects.
Definition: TObject.h:37
TRotation()
Constructor.
Definition: TRotation.cxx:196
TRotation & SetYEulerAngles(Double_t phi, Double_t theta, Double_t psi)
Rotate using the y-convention.
Definition: TRotation.cxx:502
Double_t fxz
Definition: TRotation.h:184
void MakeBasis(TVector3 &xAxis, TVector3 &yAxis, TVector3 &zAxis) const
Make the Z axis into a unit variable.
Definition: TRotation.cxx:767
TRotationRow(const TRotation &, int)
Definition: TRotation.h:203
TRotationRow operator[](int) const
Definition: TRotation.h:218
TRotation & SetZAxis(const TVector3 &axis)
Set Z axis.
Definition: TRotation.cxx:759
Double_t ZZ() const
Definition: TRotation.h:200
Double_t XX() const
Definition: TRotation.h:192
TVector3 operator*(const TVector3 &) const
Definition: TRotation.h:259
const TRotation * fRR
Definition: TRotation.h:33
Double_t ThetaX() const
Return Theta.
Definition: TRotation.cxx:442
Double_t ThetaY() const
Return Theta.
Definition: TRotation.cxx:449
const Bool_t kTRUE
Definition: Rtypes.h:91
TRotation & operator*=(const TRotation &)
Definition: TRotation.h:265
Double_t GetXTheta(void) const
Return XTheta.
Definition: TRotation.cxx:631
Bool_t operator==(const TRotation &) const
Definition: TRotation.h:235
Double_t fyz
Definition: TRotation.h:184
void SetXPsi(Double_t)
Set XPsi.
Definition: TRotation.cxx:551
Double_t GetYPsi(void) const
Return YPsi.
Definition: TRotation.cxx:691
TRotation & SetXEulerAngles(Double_t phi, Double_t theta, Double_t psi)
Rotate using the x-convention (Landau and Lifshitz, Goldstein, &c) by doing the explicit rotations...
Definition: TRotation.cxx:488
Double_t ThetaZ() const
Return Theta.
Definition: TRotation.cxx:456