// @(#)root/physics:$Id$
// Author: Peter Malzacher   19/06/99

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/
#ifndef ROOT_TRotation
#define ROOT_TRotation

#include "TObject.h"

#ifndef ROOT_TVector3
#include "TVector3.h"
#endif

class TQuaternion;

class TRotation : public TObject {
    
public:
    
class TRotationRow {
public:
   inline TRotationRow(const TRotation &, int);
   inline TRotationRow(const TRotationRow &);
   inline TRotationRow & operator=(const TRotationRow &);
   inline Double_t operator [] (int) const;
private:
   const TRotation * fRR;
   //    const TRotation & fRR;
   int fII;
};
   // Helper class for implemention of C-style subscripting r[i][j]

   TRotation();
   // Default constructor. Gives a unit matrix.

   TRotation(const TRotation &);
   TRotation(const TQuaternion &);
   // Copy constructor.

   virtual ~TRotation() {;};

   inline Double_t XX() const;
   inline Double_t XY() const;
   inline Double_t XZ() const;
   inline Double_t YX() const;
   inline Double_t YY() const;
   inline Double_t YZ() const;
   inline Double_t ZX() const;
   inline Double_t ZY() const;
   inline Double_t ZZ() const;
   // Elements of the rotation matrix (Geant4).

   inline TRotationRow operator [] (int) const;
   // Returns object of the helper class for C-style subscripting r[i][j]

   Double_t operator () (int, int) const;
   // Fortran-style subscripting: returns (i,j) element of the rotation matrix.

   inline TRotation & operator = (const TRotation &);
   // Assignment.

   inline Bool_t operator == (const TRotation &) const;
   inline Bool_t operator != (const TRotation &) const;
   // Comparisons (Geant4).

   inline Bool_t IsIdentity() const;
   // Returns true if the identity matrix (Geant4).

   inline TVector3 operator * (const TVector3 &) const;
   // Multiplication with a TVector3.

   TRotation operator * (const TRotation &) const;
   inline TRotation & operator *= (const TRotation &);
   inline TRotation & Transform(const TRotation &);
   // Matrix multiplication.
   // Note a *= b; <=> a = a * b; while a.transform(b); <=> a = b * a;

   inline TRotation Inverse() const;
   // Returns the inverse.

   inline TRotation & Invert();
   // Inverts the Rotation matrix.

   TRotation & RotateX(Double_t);
   // Rotation around the x-axis.

   TRotation & RotateY(Double_t);
   // Rotation around the y-axis.

   TRotation & RotateZ(Double_t);
   // Rotation around the z-axis.
 
   TRotation & Rotate(Double_t, const TVector3 &);
   inline TRotation & Rotate(Double_t, const TVector3 *);
   // Rotation around a specified vector.

   TRotation & RotateAxes(const TVector3 & newX,
                          const TVector3 & newY,
                          const TVector3 & newZ);
   // Rotation of local axes (Geant4).

   Double_t PhiX() const;
   Double_t PhiY() const;
   Double_t PhiZ() const;
   Double_t ThetaX() const;
   Double_t ThetaY() const;
   Double_t ThetaZ() const;
   // Return angles (RADS) made by rotated axes against original axes (Geant4).

   void AngleAxis(Double_t &, TVector3 &) const;
   // Returns the rotation angle and rotation axis (Geant4).

   inline TRotation & SetToIdentity();
   // Set equal to the identity rotation.
 
   TRotation & SetXEulerAngles(Double_t phi, Double_t theta, Double_t psi);
   void SetXPhi(Double_t);
   void SetXTheta(Double_t);
   void SetXPsi(Double_t);
   // Set the euler angles of the rotation.  The angles are defined using the
   // y-convention which rotates around the Z axis, around the new X axis, and
   // then around the new Z axis.  The x-convention is used Goldstein, Landau
   // and Lifshitz, and other common physics texts.  Contrast this with
   // SetYEulerAngles.

   TRotation & RotateXEulerAngles(Double_t phi, Double_t theta, Double_t psi);
   // Adds a rotation of the local axes defined by the Euler angle to the
   // current rotation.  See SetXEulerAngles for a note about conventions.

   Double_t GetXPhi(void) const;
   Double_t GetXTheta(void) const;
   Double_t GetXPsi(void) const;
   // Return the euler angles of the rotation.  See SetYEulerAngles for a
   // note about conventions.

   TRotation & SetYEulerAngles(Double_t phi, Double_t theta, Double_t psi);
   void SetYPhi(Double_t);
   void SetYTheta(Double_t);
   void SetYPsi(Double_t);
   // Set the euler angles of the rotation.  The angles are defined using the
   // y-convention which rotates around the Z axis, around the new Y axis, and
   // then around the new Z axis.  The x-convention is used Goldstein, Landau
   // and Lifshitz, and other common physics texts and is a rotation around the
   // Z axis, around the new X axis, and then around the new Z axis.

   TRotation & RotateYEulerAngles(Double_t phi, Double_t theta, Double_t psi);
   // Adds a rotation of the local axes defined by the Euler angle to the
   // current rotation.  See SetYEulerAngles for a note about conventions.

   Double_t GetYPhi(void) const;
   Double_t GetYTheta(void) const;
   Double_t GetYPsi(void) const;
   // Return the euler angles of the rotation.  See SetYEulerAngles for a
   // note about conventions.

   TRotation & SetXAxis(const TVector3& axis);
   TRotation & SetXAxis(const TVector3& axis, const TVector3& xyPlane);
   TRotation & SetYAxis(const TVector3& axis);
   TRotation & SetYAxis(const TVector3& axis, const TVector3& yzPlane);
   TRotation & SetZAxis(const TVector3& axis);
   TRotation & SetZAxis(const TVector3& axis, const TVector3& zxPlane);
   // Create a rotation with the axis vector parallel to the rotated coordinate
   // system.  If a second vector is provided it defines a plane passing
   // through the axis.

   void MakeBasis(TVector3& xAxis, TVector3& yAxis, TVector3& zAxis) const;
   // Take two input vectors (in xAxis, and zAxis) and turn them into an
   // orthogonal basis.  This is an internal helper function used to implement
   // the Set?Axis functions, but is exposed because the functionality is 
   // often useful.

protected:

   TRotation(Double_t, Double_t, Double_t, Double_t, Double_t,
             Double_t, Double_t, Double_t, Double_t);
   // Protected constructor.

   Double_t fxx, fxy, fxz, fyx, fyy, fyz, fzx, fzy, fzz;
   // The matrix elements.

   ClassDef(TRotation,1) // Rotations of TVector3 objects

};


inline Double_t TRotation::XX() const { return fxx; }
inline Double_t TRotation::XY() const { return fxy; }
inline Double_t TRotation::XZ() const { return fxz; }
inline Double_t TRotation::YX() const { return fyx; }
inline Double_t TRotation::YY() const { return fyy; }
inline Double_t TRotation::YZ() const { return fyz; }
inline Double_t TRotation::ZX() const { return fzx; }
inline Double_t TRotation::ZY() const { return fzy; }
inline Double_t TRotation::ZZ() const { return fzz; }

inline TRotation::TRotationRow::TRotationRow
(const TRotation & r, int i) : fRR(&r), fII(i) {}

inline TRotation::TRotationRow::TRotationRow
(const TRotationRow & rr) : fRR(rr.fRR), fII(rr.fII) {}

inline TRotation::TRotationRow & TRotation::TRotationRow::operator = (const TRotation::TRotationRow & rr) {
   fRR = rr.fRR;
   fII = rr.fII;
   return *this;
}

inline Double_t TRotation::TRotationRow::operator [] (int jj) const {
   return fRR->operator()(fII,jj);
}

inline TRotation::TRotationRow TRotation::operator [] (int i) const {
   return TRotationRow(*this, i);
}

inline TRotation & TRotation::operator = (const TRotation & m) {
   fxx = m.fxx;
   fxy = m.fxy;
   fxz = m.fxz;
   fyx = m.fyx;
   fyy = m.fyy;
   fyz = m.fyz;
   fzx = m.fzx;
   fzy = m.fzy;
   fzz = m.fzz;
   return *this;
}

inline Bool_t TRotation::operator == (const TRotation& m) const {
   return (fxx == m.fxx && fxy == m.fxy && fxz == m.fxz &&
           fyx == m.fyx && fyy == m.fyy && fyz == m.fyz &&
           fzx == m.fzx && fzy == m.fzy && fzz == m.fzz) ? kTRUE : kFALSE;
}

inline Bool_t TRotation::operator != (const TRotation &m) const {
   return (fxx != m.fxx || fxy != m.fxy || fxz != m.fxz ||
           fyx != m.fyx || fyy != m.fyy || fyz != m.fyz ||
           fzx != m.fzx || fzy != m.fzy || fzz != m.fzz) ? kTRUE : kFALSE;
}

inline Bool_t TRotation::IsIdentity() const {
   return  (fxx == 1.0 && fxy == 0.0 && fxz == 0.0 &&
            fyx == 0.0 && fyy == 1.0 && fyz == 0.0 &&
            fzx == 0.0 && fzy == 0.0 && fzz == 1.0) ? kTRUE : kFALSE;
}

inline TRotation & TRotation::SetToIdentity() {
   fxx = fyy = fzz = 1.0;
   fxy = fxz = fyx = fyz = fzx = fzy = 0.0;
   return *this;
}

inline TVector3 TRotation::operator * (const TVector3 & p) const {
   return TVector3(fxx*p.X() + fxy*p.Y() + fxz*p.Z(),
                   fyx*p.X() + fyy*p.Y() + fyz*p.Z(),
                   fzx*p.X() + fzy*p.Y() + fzz*p.Z());
}

inline TRotation & TRotation::operator *= (const TRotation & m) {
   return *this = operator * (m);
}

inline TRotation & TRotation::Transform(const TRotation & m) {
   return *this = m.operator * (*this);
}

inline TRotation TRotation::Inverse() const {
   return TRotation(fxx, fyx, fzx, fxy, fyy, fzy, fxz, fyz, fzz);
}

inline TRotation & TRotation::Invert() {
   return *this=Inverse();
}

inline TRotation & TRotation::Rotate(Double_t psi, const TVector3 * p) {
   return Rotate(psi, *p);
}



#endif
 TRotation.h:1
 TRotation.h:2
 TRotation.h:3
 TRotation.h:4
 TRotation.h:5
 TRotation.h:6
 TRotation.h:7
 TRotation.h:8
 TRotation.h:9
 TRotation.h:10
 TRotation.h:11
 TRotation.h:12
 TRotation.h:13
 TRotation.h:14
 TRotation.h:15
 TRotation.h:16
 TRotation.h:17
 TRotation.h:18
 TRotation.h:19
 TRotation.h:20
 TRotation.h:21
 TRotation.h:22
 TRotation.h:23
 TRotation.h:24
 TRotation.h:25
 TRotation.h:26
 TRotation.h:27
 TRotation.h:28
 TRotation.h:29
 TRotation.h:30
 TRotation.h:31
 TRotation.h:32
 TRotation.h:33
 TRotation.h:34
 TRotation.h:35
 TRotation.h:36
 TRotation.h:37
 TRotation.h:38
 TRotation.h:39
 TRotation.h:40
 TRotation.h:41
 TRotation.h:42
 TRotation.h:43
 TRotation.h:44
 TRotation.h:45
 TRotation.h:46
 TRotation.h:47
 TRotation.h:48
 TRotation.h:49
 TRotation.h:50
 TRotation.h:51
 TRotation.h:52
 TRotation.h:53
 TRotation.h:54
 TRotation.h:55
 TRotation.h:56
 TRotation.h:57
 TRotation.h:58
 TRotation.h:59
 TRotation.h:60
 TRotation.h:61
 TRotation.h:62
 TRotation.h:63
 TRotation.h:64
 TRotation.h:65
 TRotation.h:66
 TRotation.h:67
 TRotation.h:68
 TRotation.h:69
 TRotation.h:70
 TRotation.h:71
 TRotation.h:72
 TRotation.h:73
 TRotation.h:74
 TRotation.h:75
 TRotation.h:76
 TRotation.h:77
 TRotation.h:78
 TRotation.h:79
 TRotation.h:80
 TRotation.h:81
 TRotation.h:82
 TRotation.h:83
 TRotation.h:84
 TRotation.h:85
 TRotation.h:86
 TRotation.h:87
 TRotation.h:88
 TRotation.h:89
 TRotation.h:90
 TRotation.h:91
 TRotation.h:92
 TRotation.h:93
 TRotation.h:94
 TRotation.h:95
 TRotation.h:96
 TRotation.h:97
 TRotation.h:98
 TRotation.h:99
 TRotation.h:100
 TRotation.h:101
 TRotation.h:102
 TRotation.h:103
 TRotation.h:104
 TRotation.h:105
 TRotation.h:106
 TRotation.h:107
 TRotation.h:108
 TRotation.h:109
 TRotation.h:110
 TRotation.h:111
 TRotation.h:112
 TRotation.h:113
 TRotation.h:114
 TRotation.h:115
 TRotation.h:116
 TRotation.h:117
 TRotation.h:118
 TRotation.h:119
 TRotation.h:120
 TRotation.h:121
 TRotation.h:122
 TRotation.h:123
 TRotation.h:124
 TRotation.h:125
 TRotation.h:126
 TRotation.h:127
 TRotation.h:128
 TRotation.h:129
 TRotation.h:130
 TRotation.h:131
 TRotation.h:132
 TRotation.h:133
 TRotation.h:134
 TRotation.h:135
 TRotation.h:136
 TRotation.h:137
 TRotation.h:138
 TRotation.h:139
 TRotation.h:140
 TRotation.h:141
 TRotation.h:142
 TRotation.h:143
 TRotation.h:144
 TRotation.h:145
 TRotation.h:146
 TRotation.h:147
 TRotation.h:148
 TRotation.h:149
 TRotation.h:150
 TRotation.h:151
 TRotation.h:152
 TRotation.h:153
 TRotation.h:154
 TRotation.h:155
 TRotation.h:156
 TRotation.h:157
 TRotation.h:158
 TRotation.h:159
 TRotation.h:160
 TRotation.h:161
 TRotation.h:162
 TRotation.h:163
 TRotation.h:164
 TRotation.h:165
 TRotation.h:166
 TRotation.h:167
 TRotation.h:168
 TRotation.h:169
 TRotation.h:170
 TRotation.h:171
 TRotation.h:172
 TRotation.h:173
 TRotation.h:174
 TRotation.h:175
 TRotation.h:176
 TRotation.h:177
 TRotation.h:178
 TRotation.h:179
 TRotation.h:180
 TRotation.h:181
 TRotation.h:182
 TRotation.h:183
 TRotation.h:184
 TRotation.h:185
 TRotation.h:186
 TRotation.h:187
 TRotation.h:188
 TRotation.h:189
 TRotation.h:190
 TRotation.h:191
 TRotation.h:192
 TRotation.h:193
 TRotation.h:194
 TRotation.h:195
 TRotation.h:196
 TRotation.h:197
 TRotation.h:198
 TRotation.h:199
 TRotation.h:200
 TRotation.h:201
 TRotation.h:202
 TRotation.h:203
 TRotation.h:204
 TRotation.h:205
 TRotation.h:206
 TRotation.h:207
 TRotation.h:208
 TRotation.h:209
 TRotation.h:210
 TRotation.h:211
 TRotation.h:212
 TRotation.h:213
 TRotation.h:214
 TRotation.h:215
 TRotation.h:216
 TRotation.h:217
 TRotation.h:218
 TRotation.h:219
 TRotation.h:220
 TRotation.h:221
 TRotation.h:222
 TRotation.h:223
 TRotation.h:224
 TRotation.h:225
 TRotation.h:226
 TRotation.h:227
 TRotation.h:228
 TRotation.h:229
 TRotation.h:230
 TRotation.h:231
 TRotation.h:232
 TRotation.h:233
 TRotation.h:234
 TRotation.h:235
 TRotation.h:236
 TRotation.h:237
 TRotation.h:238
 TRotation.h:239
 TRotation.h:240
 TRotation.h:241
 TRotation.h:242
 TRotation.h:243
 TRotation.h:244
 TRotation.h:245
 TRotation.h:246
 TRotation.h:247
 TRotation.h:248
 TRotation.h:249
 TRotation.h:250
 TRotation.h:251
 TRotation.h:252
 TRotation.h:253
 TRotation.h:254
 TRotation.h:255
 TRotation.h:256
 TRotation.h:257
 TRotation.h:258
 TRotation.h:259
 TRotation.h:260
 TRotation.h:261
 TRotation.h:262
 TRotation.h:263
 TRotation.h:264
 TRotation.h:265
 TRotation.h:266
 TRotation.h:267
 TRotation.h:268
 TRotation.h:269
 TRotation.h:270
 TRotation.h:271
 TRotation.h:272
 TRotation.h:273
 TRotation.h:274
 TRotation.h:275
 TRotation.h:276
 TRotation.h:277
 TRotation.h:278
 TRotation.h:279
 TRotation.h:280
 TRotation.h:281
 TRotation.h:282
 TRotation.h:283
 TRotation.h:284
 TRotation.h:285
 TRotation.h:286
 TRotation.h:287