Logo ROOT  
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#include "TVector3.h"
17
18class TQuaternion;
19
20class TRotation : public TObject {
21
22public:
23
25public:
26 inline TRotationRow(const TRotation &, int);
27 inline TRotationRow(const TRotationRow &);
28 inline TRotationRow & operator=(const TRotationRow &);
29 inline Double_t operator [] (int) const;
30private:
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
89 // Rotation around the x-axis.
90
92 // Rotation around the y-axis.
93
95 // Rotation around the z-axis.
96
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
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
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
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
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
176protected:
177
180 // Protected constructor.
181
183 // The matrix elements.
184
185 ClassDef(TRotation,1) // Rotations of TVector3 objects
186
187};
188
189
190inline Double_t TRotation::XX() const { return fxx; }
191inline Double_t TRotation::XY() const { return fxy; }
192inline Double_t TRotation::XZ() const { return fxz; }
193inline Double_t TRotation::YX() const { return fyx; }
194inline Double_t TRotation::YY() const { return fyy; }
195inline Double_t TRotation::YZ() const { return fyz; }
196inline Double_t TRotation::ZX() const { return fzx; }
197inline Double_t TRotation::ZY() const { return fzy; }
198inline Double_t TRotation::ZZ() const { return fzz; }
199
201(const TRotation & r, int i) : fRR(&r), fII(i) {}
202
204(const TRotationRow & rr) : fRR(rr.fRR), fII(rr.fII) {}
205
207 fRR = rr.fRR;
208 fII = rr.fII;
209 return *this;
210}
211
213 return fRR->operator()(fII,jj);
214}
215
217 return TRotationRow(*this, i);
218}
219
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
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
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
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
252 fxx = fyy = fzz = 1.0;
253 fxy = fxz = fyx = fyz = fzx = fzy = 0.0;
254 return *this;
255}
256
257inline 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
264 return *this = operator * (m);
265}
266
268 return *this = m.operator * (*this);
269}
270
272 return TRotation(fxx, fyx, fzx, fxy, fyy, fzy, fxz, fyz, fzz);
273}
274
276 return *this=Inverse();
277}
278
280 return Rotate(psi, *p);
281}
282
283
284
285#endif
ROOT::R::TRInterface & r
Definition: Object.C:4
const Bool_t kFALSE
Definition: RtypesCore.h:88
bool Bool_t
Definition: RtypesCore.h:59
double Double_t
Definition: RtypesCore.h:55
const Bool_t kTRUE
Definition: RtypesCore.h:87
#define ClassDef(name, id)
Definition: Rtypes.h:326
Mother of all ROOT objects.
Definition: TObject.h:37
Quaternion is a 4-component mathematic object quite convenient when dealing with space rotation (or r...
Definition: TQuaternion.h:11
TRotationRow(const TRotation &, int)
Definition: TRotation.h:201
Double_t operator[](int) const
Definition: TRotation.h:212
TRotationRow & operator=(const TRotationRow &)
Definition: TRotation.h:206
const TRotation * fRR
Definition: TRotation.h:31
The TRotation class describes a rotation of objects of the TVector3 class.
Definition: TRotation.h:20
TRotationRow operator[](int) const
Definition: TRotation.h:216
Double_t fzz
Definition: TRotation.h:182
TRotation & operator*=(const TRotation &)
Definition: TRotation.h:263
Double_t YY() const
Definition: TRotation.h:194
Double_t fyy
Definition: TRotation.h:182
Bool_t IsIdentity() const
Definition: TRotation.h:245
Double_t ZX() const
Definition: TRotation.h:196
TRotation & SetToIdentity()
Definition: TRotation.h:251
TRotation & SetZAxis(const TVector3 &axis)
Set Z axis.
Definition: TRotation.cxx:758
Double_t XY() const
Definition: TRotation.h:191
Double_t PhiY() const
Return Phi.
Definition: TRotation.cxx:427
TRotation & Rotate(Double_t, const TVector3 &)
Rotate along an axis.
Definition: TRotation.cxx:324
Double_t fzy
Definition: TRotation.h:182
void SetXPhi(Double_t)
Set XPhi.
Definition: TRotation.cxx:536
Double_t GetYPhi(void) const
Return YPhi.
Definition: TRotation.cxx:623
TRotation()
Constructor.
Definition: TRotation.cxx:195
TRotation & Invert()
Definition: TRotation.h:275
Double_t YX() const
Definition: TRotation.h:193
Double_t operator()(int, int) const
Dereferencing operator const.
Definition: TRotation.cxx:218
Double_t ThetaY() const
Return Theta.
Definition: TRotation.cxx:448
TRotation Inverse() const
Definition: TRotation.h:271
TRotation & RotateYEulerAngles(Double_t phi, Double_t theta, Double_t psi)
Rotate using the y-convention.
Definition: TRotation.cxx:525
void SetYPhi(Double_t)
Set YPhi.
Definition: TRotation.cxx:557
TRotation & SetYAxis(const TVector3 &axis)
Set Y axis.
Definition: TRotation.cxx:735
Double_t ZZ() const
Definition: TRotation.h:198
Double_t fyx
Definition: TRotation.h:182
Double_t XZ() const
Definition: TRotation.h:192
Double_t GetXPsi(void) const
Get psi angle.
Definition: TRotation.cxx:644
Double_t YZ() const
Definition: TRotation.h:195
void SetXPsi(Double_t)
Set XPsi.
Definition: TRotation.cxx:550
Double_t PhiX() const
Return Phi.
Definition: TRotation.cxx:420
Double_t fxz
Definition: TRotation.h:182
TRotation & Transform(const TRotation &)
Definition: TRotation.h:267
TRotation & RotateY(Double_t)
Rotate around y.
Definition: TRotation.cxx:361
Double_t fyz
Definition: TRotation.h:182
Double_t PhiZ() const
Return Phi.
Definition: TRotation.cxx:434
TRotation & operator=(const TRotation &)
Definition: TRotation.h:220
TRotation & RotateZ(Double_t)
Rotate around z.
Definition: TRotation.cxx:377
TVector3 operator*(const TVector3 &) const
Definition: TRotation.h:257
Double_t GetYPsi(void) const
Return YPsi.
Definition: TRotation.cxx:690
Bool_t operator!=(const TRotation &) const
Definition: TRotation.h:239
virtual ~TRotation()
Definition: TRotation.h:44
Double_t GetYTheta(void) const
Return YTheta.
Definition: TRotation.cxx:637
TRotation & RotateXEulerAngles(Double_t phi, Double_t theta, Double_t psi)
Rotate using the x-convention.
Definition: TRotation.cxx:514
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:487
void AngleAxis(Double_t &, TVector3 &) const
Rotation defined by an angle and a vector.
Definition: TRotation.cxx:462
Double_t ThetaZ() const
Return Theta.
Definition: TRotation.cxx:455
void SetYPsi(Double_t)
Set YPsi.
Definition: TRotation.cxx:571
void SetYTheta(Double_t)
Set YTheta.
Definition: TRotation.cxx:564
Double_t fxx
Definition: TRotation.h:182
Double_t XX() const
Definition: TRotation.h:190
TRotation & SetYEulerAngles(Double_t phi, Double_t theta, Double_t psi)
Rotate using the y-convention.
Definition: TRotation.cxx:501
Double_t ZY() const
Definition: TRotation.h:197
void MakeBasis(TVector3 &xAxis, TVector3 &yAxis, TVector3 &zAxis) const
Make the Z axis into a unit variable.
Definition: TRotation.cxx:766
TRotation & RotateAxes(const TVector3 &newX, const TVector3 &newY, const TVector3 &newZ)
Rotate axes.
Definition: TRotation.cxx:393
void SetXTheta(Double_t)
Set XTheta.
Definition: TRotation.cxx:543
Double_t GetXPhi(void) const
Return phi angle.
Definition: TRotation.cxx:578
TRotation & SetXAxis(const TVector3 &axis)
Set X axis.
Definition: TRotation.cxx:712
Double_t GetXTheta(void) const
Return XTheta.
Definition: TRotation.cxx:630
Double_t fzx
Definition: TRotation.h:182
Bool_t operator==(const TRotation &) const
Definition: TRotation.h:233
Double_t ThetaX() const
Return Theta.
Definition: TRotation.cxx:441
Double_t fxy
Definition: TRotation.h:182
TRotation & RotateX(Double_t)
Rotate around x.
Definition: TRotation.cxx:345
TVector3 is a general three vector class, which can be used for the description of different vectors ...
Definition: TVector3.h:22
Double_t Z() const
Definition: TVector3.h:218
Double_t Y() const
Definition: TVector3.h:217
Double_t X() const
Definition: TVector3.h:216
auto * m
Definition: textangle.C:8