Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

TRotation.h

Go to the documentation of this file.
00001 // @(#)root/physics:$Name:  $:$Id: TRotation.h,v 1.2 2003/04/11 06:44:39 brun Exp $
00002 // Author: Peter Malzacher   19/06/99
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 #ifndef ROOT_TRotation
00012 #define ROOT_TRotation
00013 
00014 #include "TObject.h"
00015 
00016 #ifndef ROOT_TVector3
00017 #include "TVector3.h"
00018 #endif
00019 
00020 class TRotation : public TObject {
00021     
00022 public:
00023     
00024   class TRotationRow {
00025   public:
00026     inline TRotationRow(const TRotation &, int);
00027     inline Double_t operator [] (int) const;
00028   private:
00029     const TRotation * rr;
00030     //    const TRotation & rr;
00031     int ii;
00032   };
00033   // Helper class for implemention of C-style subscripting r[i][j]
00034 
00035   TRotation();
00036   // Default constructor. Gives a unit matrix.
00037 
00038   TRotation(const TRotation &);
00039   // Copy constructor.
00040 
00041   virtual ~TRotation() {;};
00042 
00043   inline Double_t XX() const;
00044   inline Double_t XY() const;
00045   inline Double_t XZ() const;
00046   inline Double_t YX() const;
00047   inline Double_t YY() const;
00048   inline Double_t YZ() const;
00049   inline Double_t ZX() const;
00050   inline Double_t ZY() const;
00051   inline Double_t ZZ() const;
00052   // Elements of the rotation matrix (Geant4).
00053 
00054   inline TRotationRow operator [] (int) const;
00055   // Returns object of the helper class for C-style subscripting r[i][j]
00056 
00057   Double_t operator () (int, int) const;
00058   // Fortran-style subscripting: returns (i,j) element of the rotation matrix.
00059 
00060   inline TRotation & operator = (const TRotation &);
00061   // Assignment.
00062 
00063   inline Bool_t operator == (const TRotation &) const;
00064   inline Bool_t operator != (const TRotation &) const;
00065   // Comparisons (Geant4).
00066 
00067   inline Bool_t IsIdentity() const;
00068   // Returns true if the identity matrix (Geant4).
00069 
00070   inline TVector3 operator * (const TVector3 &) const;
00071   // Multiplication with a TVector3.
00072 
00073   TRotation operator * (const TRotation &) const;
00074   inline TRotation & operator *= (const TRotation &);
00075   inline TRotation & Transform(const TRotation &);
00076   // Matrix multiplication.
00077   // Note a *= b; <=> a = a * b; while a.transform(b); <=> a = b * a;
00078 
00079   inline TRotation Inverse() const;
00080   // Returns the inverse.
00081 
00082   inline TRotation & Invert();
00083   // Inverts the Rotation matrix.
00084 
00085   TRotation & RotateX(Double_t);
00086   // Rotation around the x-axis.
00087 
00088   TRotation & RotateY(Double_t);
00089   // Rotation around the y-axis.
00090 
00091   TRotation & RotateZ(Double_t);
00092   // Rotation around the z-axis.
00093 
00094   TRotation & Rotate(Double_t, const TVector3 &);
00095   inline TRotation & Rotate(Double_t, const TVector3 *);
00096   // Rotation around a specified vector.
00097 
00098   TRotation & RotateAxes(const TVector3 & newX,
00099                            const TVector3 & newY,
00100                            const TVector3 & newZ);
00101   // Rotation of local axes (Geant4).
00102 
00103   Double_t PhiX() const;
00104   Double_t PhiY() const;
00105   Double_t PhiZ() const;
00106   Double_t ThetaX() const;
00107   Double_t ThetaY() const;
00108   Double_t ThetaZ() const;
00109   // Return angles (RADS) made by rotated axes against original axes (Geant4).
00110 
00111   void AngleAxis(Double_t &, TVector3 &) const;
00112   // Returns the rotation angle and rotation axis (Geant4).
00113 
00114   inline TRotation & SetToIdentity();
00115   // Set equal to the identity rotation.
00116 
00117   TRotation & SetXEulerAngles(Double_t phi, Double_t theta, Double_t psi);
00118   void SetXPhi(Double_t);
00119   void SetXTheta(Double_t);
00120   void SetXPsi(Double_t);
00121   // Set the euler angles of the rotation.  The angles are defined using the
00122   // y-convention which rotates around the Z axis, around the new X axis, and
00123   // then around the new Z axis.  The x-convention is used Goldstein, Landau
00124   // and Lifshitz, and other common physics texts.  Contrast this with
00125   // SetYEulerAngles.
00126 
00127   TRotation & RotateXEulerAngles(Double_t phi, Double_t theta, Double_t psi);
00128   // Adds a rotation of the local axes defined by the Euler angle to the
00129   // current rotation.  See SetXEulerAngles for a note about conventions.
00130 
00131   Double_t GetXPhi(void) const;
00132   Double_t GetXTheta(void) const;
00133   Double_t GetXPsi(void) const;
00134   // Return the euler angles of the rotation.  See SetYEulerAngles for a
00135   // note about conventions.
00136 
00137   TRotation & SetYEulerAngles(Double_t phi, Double_t theta, Double_t psi);
00138   void SetYPhi(Double_t);
00139   void SetYTheta(Double_t);
00140   void SetYPsi(Double_t);
00141   // Set the euler angles of the rotation.  The angles are defined using the
00142   // y-convention which rotates around the Z axis, around the new Y axis, and
00143   // then around the new Z axis.  The x-convention is used Goldstein, Landau
00144   // and Lifshitz, and other common physics texts and is a rotation around the
00145   // Z axis, around the new X axis, and then around the new Z axis.
00146 
00147   TRotation & RotateYEulerAngles(Double_t phi, Double_t theta, Double_t psi);
00148   // Adds a rotation of the local axes defined by the Euler angle to the
00149   // current rotation.  See SetYEulerAngles for a note about conventions.
00150 
00151   Double_t GetYPhi(void) const;
00152   Double_t GetYTheta(void) const;
00153   Double_t GetYPsi(void) const;
00154   // Return the euler angles of the rotation.  See SetYEulerAngles for a
00155   // note about conventions.
00156 
00157   TRotation & SetXAxis(const TVector3& axis);
00158   TRotation & SetXAxis(const TVector3& axis, const TVector3& xyPlane);
00159   TRotation & SetYAxis(const TVector3& axis);
00160   TRotation & SetYAxis(const TVector3& axis, const TVector3& yzPlane);
00161   TRotation & SetZAxis(const TVector3& axis);
00162   TRotation & SetZAxis(const TVector3& axis, const TVector3& zxPlane);
00163   // Create a rotation with the axis vector parallel to the rotated coordinate
00164   // system.  If a second vector is provided it defines a plane passing
00165   // through the axis.
00166 
00167   void MakeBasis(TVector3& xAxis, TVector3& yAxis, TVector3& zAxis) const;
00168   // Take two input vectors (in xAxis, and zAxis) and turn them into an
00169   // orthogonal basis.  This is an internal helper function used to implement
00170   // the Set?Axis functions, but is exposed because the functionality is 
00171   // often useful.
00172 
00173 protected:
00174 
00175   TRotation(Double_t, Double_t, Double_t, Double_t, Double_t,
00176                      Double_t, Double_t, Double_t, Double_t);
00177   // Protected constructor.
00178 
00179   Double_t fxx, fxy, fxz, fyx, fyy, fyz, fzx, fzy, fzz;
00180   // The matrix elements.
00181 
00182   ClassDef(TRotation,1) // Rotations of TVector3 objects
00183 
00184 };
00185 
00186 
00187 inline Double_t TRotation::XX() const { return fxx; }
00188 inline Double_t TRotation::XY() const { return fxy; }
00189 inline Double_t TRotation::XZ() const { return fxz; }
00190 inline Double_t TRotation::YX() const { return fyx; }
00191 inline Double_t TRotation::YY() const { return fyy; }
00192 inline Double_t TRotation::YZ() const { return fyz; }
00193 inline Double_t TRotation::ZX() const { return fzx; }
00194 inline Double_t TRotation::ZY() const { return fzy; }
00195 inline Double_t TRotation::ZZ() const { return fzz; }
00196 
00197 inline TRotation::TRotationRow::TRotationRow
00198 (const TRotation & r, int i) : rr(&r), ii(i) {}
00199 
00200 inline Double_t TRotation::TRotationRow::operator [] (int jj) const {
00201   return rr->operator()(ii,jj);
00202 }
00203 
00204 inline TRotation::TRotationRow TRotation::operator [] (int i) const {
00205   return TRotationRow(*this, i);
00206 }
00207 
00208 inline TRotation & TRotation::operator = (const TRotation & m) {
00209   fxx = m.fxx;
00210   fxy = m.fxy;
00211   fxz = m.fxz;
00212   fyx = m.fyx;
00213   fyy = m.fyy;
00214   fyz = m.fyz;
00215   fzx = m.fzx;
00216   fzy = m.fzy;
00217   fzz = m.fzz;
00218   return *this;
00219 }
00220 
00221 inline Bool_t TRotation::operator == (const TRotation& m) const {
00222   return (fxx == m.fxx && fxy == m.fxy && fxz == m.fxz &&
00223           fyx == m.fyx && fyy == m.fyy && fyz == m.fyz &&
00224           fzx == m.fzx && fzy == m.fzy && fzz == m.fzz) ? kTRUE : kFALSE;
00225 }
00226 
00227 inline Bool_t TRotation::operator != (const TRotation &m) const {
00228   return (fxx != m.fxx || fxy != m.fxy || fxz != m.fxz ||
00229           fyx != m.fyx || fyy != m.fyy || fyz != m.fyz ||
00230           fzx != m.fzx || fzy != m.fzy || fzz != m.fzz) ? kTRUE : kFALSE;
00231 }
00232 
00233 inline Bool_t TRotation::IsIdentity() const {
00234   return  (fxx == 1.0 && fxy == 0.0 && fxz == 0.0 &&
00235            fyx == 0.0 && fyy == 1.0 && fyz == 0.0 &&
00236            fzx == 0.0 && fzy == 0.0 && fzz == 1.0) ? kTRUE : kFALSE;
00237 }
00238 
00239 inline TRotation & TRotation::SetToIdentity() {
00240     fxx = fyy = fzz = 1.0;
00241     fxy = fxz = fyx = fyz = fzx = fzy = 0.0;
00242     return *this;
00243 }
00244 
00245 inline TVector3 TRotation::operator * (const TVector3 & p) const {
00246   return TVector3(fxx*p.X() + fxy*p.Y() + fxz*p.Z(),
00247                     fyx*p.X() + fyy*p.Y() + fyz*p.Z(),
00248                     fzx*p.X() + fzy*p.Y() + fzz*p.Z());
00249 }
00250 
00251 inline TRotation & TRotation::operator *= (const TRotation & m) {
00252   return *this = operator * (m);
00253 }
00254 
00255 inline TRotation & TRotation::Transform(const TRotation & m) {
00256   return *this = m.operator * (*this);
00257 }
00258 
00259 inline TRotation TRotation::Inverse() const {
00260   return TRotation(fxx, fyx, fzx, fxy, fyy, fzy, fxz, fyz, fzz);
00261 }
00262 
00263 inline TRotation & TRotation::Invert() {
00264   return *this=Inverse();
00265 }
00266 
00267 inline TRotation & TRotation::Rotate(Double_t psi, const TVector3 * p) {
00268   return Rotate(psi, *p);
00269 }
00270 
00271 
00272 
00273 #endif

Generated on Thu Dec 18 14:52:23 2003 for ROOT by doxygen1.2.16