TRotation.h

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

Generated on Tue Jul 5 14:28:09 2011 for ROOT_528-00b_version by  doxygen 1.5.1