Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 #include "TVector3.h"
17 
18 class TQuaternion;
19 
20 class TRotation : public TObject {
21 
22 public:
23 
24 class TRotationRow {
25 public:
26  inline TRotationRow(const TRotation &, int);
27  inline TRotationRow(const TRotationRow &);
28  inline TRotationRow & operator=(const TRotationRow &);
29  inline Double_t operator [] (int) const;
30 private:
31  const TRotation * fRR;
32  // const TRotation & fRR;
33  int fII;
34 };
35  // Helper class for implemention of C-style subscripting r[i][j]
36 
37  TRotation();
38  // Default constructor. Gives a unit matrix.
39 
40  TRotation(const TRotation &);
41  TRotation(const TQuaternion &);
42  // Copy constructor.
43 
44  virtual ~TRotation() {;};
45 
46  inline Double_t XX() const;
47  inline Double_t XY() const;
48  inline Double_t XZ() const;
49  inline Double_t YX() const;
50  inline Double_t YY() const;
51  inline Double_t YZ() const;
52  inline Double_t ZX() const;
53  inline Double_t ZY() const;
54  inline Double_t ZZ() const;
55  // Elements of the rotation matrix (Geant4).
56 
57  inline TRotationRow operator [] (int) const;
58  // Returns object of the helper class for C-style subscripting r[i][j]
59 
60  Double_t operator () (int, int) const;
61  // Fortran-style subscripting: returns (i,j) element of the rotation matrix.
62 
63  inline TRotation & operator = (const TRotation &);
64  // Assignment.
65 
66  inline Bool_t operator == (const TRotation &) const;
67  inline Bool_t operator != (const TRotation &) const;
68  // Comparisons (Geant4).
69 
70  inline Bool_t IsIdentity() const;
71  // Returns true if the identity matrix (Geant4).
72 
73  inline TVector3 operator * (const TVector3 &) const;
74  // Multiplication with a TVector3.
75 
76  TRotation operator * (const TRotation &) const;
77  inline TRotation & operator *= (const TRotation &);
78  inline TRotation & Transform(const TRotation &);
79  // Matrix multiplication.
80  // Note a *= b; <=> a = a * b; while a.transform(b); <=> a = b * a;
81 
82  inline TRotation Inverse() const;
83  // Returns the inverse.
84 
85  inline TRotation & Invert();
86  // Inverts the Rotation matrix.
87 
88  TRotation & RotateX(Double_t);
89  // Rotation around the x-axis.
90 
91  TRotation & RotateY(Double_t);
92  // Rotation around the y-axis.
93 
94  TRotation & RotateZ(Double_t);
95  // Rotation around the z-axis.
96 
97  TRotation & Rotate(Double_t, const TVector3 &);
98  inline TRotation & Rotate(Double_t, const TVector3 *);
99  // Rotation around a specified vector.
100 
101  TRotation & RotateAxes(const TVector3 & newX,
102  const TVector3 & newY,
103  const TVector3 & newZ);
104  // Rotation of local axes (Geant4).
105 
106  Double_t PhiX() const;
107  Double_t PhiY() const;
108  Double_t PhiZ() const;
109  Double_t ThetaX() const;
110  Double_t ThetaY() const;
111  Double_t ThetaZ() const;
112  // Return angles (RADS) made by rotated axes against original axes (Geant4).
113 
114  void AngleAxis(Double_t &, TVector3 &) const;
115  // Returns the rotation angle and rotation axis (Geant4).
116 
117  inline TRotation & SetToIdentity();
118  // Set equal to the identity rotation.
119 
120  TRotation & SetXEulerAngles(Double_t phi, Double_t theta, Double_t psi);
121  void SetXPhi(Double_t);
122  void SetXTheta(Double_t);
123  void SetXPsi(Double_t);
124  // Set the euler angles of the rotation. The angles are defined using the
125  // y-convention which rotates around the Z axis, around the new X axis, and
126  // then around the new Z axis. The x-convention is used Goldstein, Landau
127  // and Lifshitz, and other common physics texts. Contrast this with
128  // SetYEulerAngles.
129 
130  TRotation & RotateXEulerAngles(Double_t phi, Double_t theta, Double_t psi);
131  // Adds a rotation of the local axes defined by the Euler angle to the
132  // current rotation. See SetXEulerAngles for a note about conventions.
133 
134  Double_t GetXPhi(void) const;
135  Double_t GetXTheta(void) const;
136  Double_t GetXPsi(void) const;
137  // Return the euler angles of the rotation. See SetYEulerAngles for a
138  // note about conventions.
139 
140  TRotation & SetYEulerAngles(Double_t phi, Double_t theta, Double_t psi);
141  void SetYPhi(Double_t);
142  void SetYTheta(Double_t);
143  void SetYPsi(Double_t);
144  // Set the euler angles of the rotation. The angles are defined using the
145  // y-convention which rotates around the Z axis, around the new Y axis, and
146  // then around the new Z axis. The x-convention is used Goldstein, Landau
147  // and Lifshitz, and other common physics texts and is a rotation around the
148  // Z axis, around the new X axis, and then around the new Z axis.
149 
150  TRotation & RotateYEulerAngles(Double_t phi, Double_t theta, Double_t psi);
151  // Adds a rotation of the local axes defined by the Euler angle to the
152  // current rotation. See SetYEulerAngles for a note about conventions.
153 
154  Double_t GetYPhi(void) const;
155  Double_t GetYTheta(void) const;
156  Double_t GetYPsi(void) const;
157  // Return the euler angles of the rotation. See SetYEulerAngles for a
158  // note about conventions.
159 
160  TRotation & SetXAxis(const TVector3& axis);
161  TRotation & SetXAxis(const TVector3& axis, const TVector3& xyPlane);
162  TRotation & SetYAxis(const TVector3& axis);
163  TRotation & SetYAxis(const TVector3& axis, const TVector3& yzPlane);
164  TRotation & SetZAxis(const TVector3& axis);
165  TRotation & SetZAxis(const TVector3& axis, const TVector3& zxPlane);
166  // Create a rotation with the axis vector parallel to the rotated coordinate
167  // system. If a second vector is provided it defines a plane passing
168  // through the axis.
169 
170  void MakeBasis(TVector3& xAxis, TVector3& yAxis, TVector3& zAxis) const;
171  // Take two input vectors (in xAxis, and zAxis) and turn them into an
172  // orthogonal basis. This is an internal helper function used to implement
173  // the Set?Axis functions, but is exposed because the functionality is
174  // often useful.
175 
176 protected:
177 
178  TRotation(Double_t, Double_t, Double_t, Double_t, Double_t,
179  Double_t, Double_t, Double_t, Double_t);
180  // Protected constructor.
181 
182  Double_t fxx, fxy, fxz, fyx, fyy, fyz, fzx, fzy, fzz;
183  // The matrix elements.
184 
185  ClassDef(TRotation,1) // Rotations of TVector3 objects
186 
187 };
188 
189 
190 inline Double_t TRotation::XX() const { return fxx; }
191 inline Double_t TRotation::XY() const { return fxy; }
192 inline Double_t TRotation::XZ() const { return fxz; }
193 inline Double_t TRotation::YX() const { return fyx; }
194 inline Double_t TRotation::YY() const { return fyy; }
195 inline Double_t TRotation::YZ() const { return fyz; }
196 inline Double_t TRotation::ZX() const { return fzx; }
197 inline Double_t TRotation::ZY() const { return fzy; }
198 inline Double_t TRotation::ZZ() const { return fzz; }
199 
200 inline TRotation::TRotationRow::TRotationRow
201 (const TRotation & r, int i) : fRR(&r), fII(i) {}
202 
203 inline TRotation::TRotationRow::TRotationRow
204 (const TRotationRow & rr) : fRR(rr.fRR), fII(rr.fII) {}
205 
206 inline TRotation::TRotationRow & TRotation::TRotationRow::operator = (const TRotation::TRotationRow & rr) {
207  fRR = rr.fRR;
208  fII = rr.fII;
209  return *this;
210 }
211 
212 inline Double_t TRotation::TRotationRow::operator [] (int jj) const {
213  return fRR->operator()(fII,jj);
214 }
215 
216 inline TRotation::TRotationRow TRotation::operator [] (int i) const {
217  return TRotationRow(*this, i);
218 }
219 
220 inline TRotation & TRotation::operator = (const TRotation & m) {
221  fxx = m.fxx;
222  fxy = m.fxy;
223  fxz = m.fxz;
224  fyx = m.fyx;
225  fyy = m.fyy;
226  fyz = m.fyz;
227  fzx = m.fzx;
228  fzy = m.fzy;
229  fzz = m.fzz;
230  return *this;
231 }
232 
233 inline Bool_t TRotation::operator == (const TRotation& m) const {
234  return (fxx == m.fxx && fxy == m.fxy && fxz == m.fxz &&
235  fyx == m.fyx && fyy == m.fyy && fyz == m.fyz &&
236  fzx == m.fzx && fzy == m.fzy && fzz == m.fzz) ? kTRUE : kFALSE;
237 }
238 
239 inline Bool_t TRotation::operator != (const TRotation &m) const {
240  return (fxx != m.fxx || fxy != m.fxy || fxz != m.fxz ||
241  fyx != m.fyx || fyy != m.fyy || fyz != m.fyz ||
242  fzx != m.fzx || fzy != m.fzy || fzz != m.fzz) ? kTRUE : kFALSE;
243 }
244 
245 inline Bool_t TRotation::IsIdentity() const {
246  return (fxx == 1.0 && fxy == 0.0 && fxz == 0.0 &&
247  fyx == 0.0 && fyy == 1.0 && fyz == 0.0 &&
248  fzx == 0.0 && fzy == 0.0 && fzz == 1.0) ? kTRUE : kFALSE;
249 }
250 
251 inline TRotation & TRotation::SetToIdentity() {
252  fxx = fyy = fzz = 1.0;
253  fxy = fxz = fyx = fyz = fzx = fzy = 0.0;
254  return *this;
255 }
256 
257 inline TVector3 TRotation::operator * (const TVector3 & p) const {
258  return TVector3(fxx*p.X() + fxy*p.Y() + fxz*p.Z(),
259  fyx*p.X() + fyy*p.Y() + fyz*p.Z(),
260  fzx*p.X() + fzy*p.Y() + fzz*p.Z());
261 }
262 
263 inline TRotation & TRotation::operator *= (const TRotation & m) {
264  return *this = operator * (m);
265 }
266 
267 inline TRotation & TRotation::Transform(const TRotation & m) {
268  return *this = m.operator * (*this);
269 }
270 
271 inline TRotation TRotation::Inverse() const {
272  return TRotation(fxx, fyx, fzx, fxy, fyy, fzy, fxz, fyz, fzz);
273 }
274 
275 inline TRotation & TRotation::Invert() {
276  return *this=Inverse();
277 }
278 
279 inline TRotation & TRotation::Rotate(Double_t psi, const TVector3 * p) {
280  return Rotate(psi, *p);
281 }
282 
283 
284 
285 #endif