Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/root/TRotation.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // @(#)root/physics:$Id$
0002 // Author: Peter Malzacher   19/06/99
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0010  *************************************************************************/
0011 #ifndef ROOT_TRotation
0012 #define ROOT_TRotation
0013 
0014 #include "TObject.h"
0015 
0016 #include "TVector3.h"
0017 
0018 class TQuaternion;
0019 
0020 class TRotation : public TObject {
0021 
0022 public:
0023 
0024 class TRotationRow {
0025 public:
0026    inline TRotationRow(const TRotation &, int);
0027    inline TRotationRow(const TRotationRow &);
0028    inline TRotationRow & operator=(const TRotationRow &);
0029    inline Double_t operator [] (int) const;
0030 private:
0031    const TRotation * fRR;
0032    //    const TRotation & fRR;
0033    int fII;
0034 };
0035    // Helper class for implementation of C-style subscripting r[i][j]
0036 
0037    TRotation();
0038    // Default constructor. Gives a unit matrix.
0039 
0040    TRotation(const TRotation &);
0041    TRotation(const TQuaternion &);
0042    // Copy constructor.
0043 
0044    ~TRotation() override {}
0045 
0046    inline Double_t XX() const;
0047    inline Double_t XY() const;
0048    inline Double_t XZ() const;
0049    inline Double_t YX() const;
0050    inline Double_t YY() const;
0051    inline Double_t YZ() const;
0052    inline Double_t ZX() const;
0053    inline Double_t ZY() const;
0054    inline Double_t ZZ() const;
0055    // Elements of the rotation matrix (Geant4).
0056 
0057    inline TRotationRow operator [] (int) const;
0058    // Returns object of the helper class for C-style subscripting r[i][j]
0059 
0060    Double_t operator () (int, int) const;
0061    // Fortran-style subscripting: returns (i,j) element of the rotation matrix.
0062 
0063    inline TRotation & operator = (const TRotation &);
0064    // Assignment.
0065 
0066    inline Bool_t operator == (const TRotation &) const;
0067    inline Bool_t operator != (const TRotation &) const;
0068    // Comparisons (Geant4).
0069 
0070    inline Bool_t IsIdentity() const;
0071    // Returns true if the identity matrix (Geant4).
0072 
0073    inline TVector3 operator * (const TVector3 &) const;
0074    // Multiplication with a TVector3.
0075 
0076    TRotation operator * (const TRotation &) const;
0077    inline TRotation & operator *= (const TRotation &);
0078    inline TRotation & Transform(const TRotation &);
0079    // Matrix multiplication.
0080    // Note a *= b; <=> a = a * b; while a.transform(b); <=> a = b * a;
0081 
0082    inline TRotation Inverse() const;
0083    // Returns the inverse.
0084 
0085    inline TRotation & Invert();
0086    // Inverts the Rotation matrix.
0087 
0088    TRotation & RotateX(Double_t);
0089    // Rotation around the x-axis.
0090 
0091    TRotation & RotateY(Double_t);
0092    // Rotation around the y-axis.
0093 
0094    TRotation & RotateZ(Double_t);
0095    // Rotation around the z-axis.
0096 
0097    TRotation & Rotate(Double_t, const TVector3 &);
0098    inline TRotation & Rotate(Double_t, const TVector3 *);
0099    // Rotation around a specified vector.
0100 
0101    TRotation & RotateAxes(const TVector3 & newX,
0102                           const TVector3 & newY,
0103                           const TVector3 & newZ);
0104    // Rotation of local axes (Geant4).
0105 
0106    Double_t PhiX() const;
0107    Double_t PhiY() const;
0108    Double_t PhiZ() const;
0109    Double_t ThetaX() const;
0110    Double_t ThetaY() const;
0111    Double_t ThetaZ() const;
0112    // Return angles (RADS) made by rotated axes against original axes (Geant4).
0113 
0114    void AngleAxis(Double_t &, TVector3 &) const;
0115    // Returns the rotation angle and rotation axis (Geant4).
0116 
0117    inline TRotation & SetToIdentity();
0118    // Set equal to the identity rotation.
0119 
0120    TRotation & SetXEulerAngles(Double_t phi, Double_t theta, Double_t psi);
0121    void SetXPhi(Double_t);
0122    void SetXTheta(Double_t);
0123    void SetXPsi(Double_t);
0124    // Set the euler angles of the rotation.  The angles are defined using the
0125    // y-convention which rotates around the Z axis, around the new X axis, and
0126    // then around the new Z axis.  The x-convention is used Goldstein, Landau
0127    // and Lifshitz, and other common physics texts.  Contrast this with
0128    // SetYEulerAngles.
0129 
0130    TRotation & RotateXEulerAngles(Double_t phi, Double_t theta, Double_t psi);
0131    // Adds a rotation of the local axes defined by the Euler angle to the
0132    // current rotation.  See SetXEulerAngles for a note about conventions.
0133 
0134    Double_t GetXPhi(void) const;
0135    Double_t GetXTheta(void) const;
0136    Double_t GetXPsi(void) const;
0137    // Return the euler angles of the rotation.  See SetYEulerAngles for a
0138    // note about conventions.
0139 
0140    TRotation & SetYEulerAngles(Double_t phi, Double_t theta, Double_t psi);
0141    void SetYPhi(Double_t);
0142    void SetYTheta(Double_t);
0143    void SetYPsi(Double_t);
0144    // Set the euler angles of the rotation.  The angles are defined using the
0145    // y-convention which rotates around the Z axis, around the new Y axis, and
0146    // then around the new Z axis.  The x-convention is used Goldstein, Landau
0147    // and Lifshitz, and other common physics texts and is a rotation around the
0148    // Z axis, around the new X axis, and then around the new Z axis.
0149 
0150    TRotation & RotateYEulerAngles(Double_t phi, Double_t theta, Double_t psi);
0151    // Adds a rotation of the local axes defined by the Euler angle to the
0152    // current rotation.  See SetYEulerAngles for a note about conventions.
0153 
0154    Double_t GetYPhi(void) const;
0155    Double_t GetYTheta(void) const;
0156    Double_t GetYPsi(void) const;
0157    // Return the euler angles of the rotation.  See SetYEulerAngles for a
0158    // note about conventions.
0159 
0160    TRotation & SetXAxis(const TVector3& axis);
0161    TRotation & SetXAxis(const TVector3& axis, const TVector3& xyPlane);
0162    TRotation & SetYAxis(const TVector3& axis);
0163    TRotation & SetYAxis(const TVector3& axis, const TVector3& yzPlane);
0164    TRotation & SetZAxis(const TVector3& axis);
0165    TRotation & SetZAxis(const TVector3& axis, const TVector3& zxPlane);
0166    // Create a rotation with the axis vector parallel to the rotated coordinate
0167    // system.  If a second vector is provided it defines a plane passing
0168    // through the axis.
0169 
0170    void MakeBasis(TVector3& xAxis, TVector3& yAxis, TVector3& zAxis) const;
0171    // Take two input vectors (in xAxis, and zAxis) and turn them into an
0172    // orthogonal basis.  This is an internal helper function used to implement
0173    // the Set?Axis functions, but is exposed because the functionality is
0174    // often useful.
0175 
0176 protected:
0177 
0178    TRotation(Double_t, Double_t, Double_t, Double_t, Double_t,
0179              Double_t, Double_t, Double_t, Double_t);
0180    // Protected constructor.
0181 
0182    Double_t fxx, fxy, fxz, fyx, fyy, fyz, fzx, fzy, fzz;
0183    // The matrix elements.
0184 
0185    ClassDefOverride(TRotation,1) // Rotations of TVector3 objects
0186 
0187 };
0188 
0189 
0190 inline Double_t TRotation::XX() const { return fxx; }
0191 inline Double_t TRotation::XY() const { return fxy; }
0192 inline Double_t TRotation::XZ() const { return fxz; }
0193 inline Double_t TRotation::YX() const { return fyx; }
0194 inline Double_t TRotation::YY() const { return fyy; }
0195 inline Double_t TRotation::YZ() const { return fyz; }
0196 inline Double_t TRotation::ZX() const { return fzx; }
0197 inline Double_t TRotation::ZY() const { return fzy; }
0198 inline Double_t TRotation::ZZ() const { return fzz; }
0199 
0200 inline TRotation::TRotationRow::TRotationRow
0201 (const TRotation & r, int i) : fRR(&r), fII(i) {}
0202 
0203 inline TRotation::TRotationRow::TRotationRow
0204 (const TRotationRow & rr) : fRR(rr.fRR), fII(rr.fII) {}
0205 
0206 inline TRotation::TRotationRow & TRotation::TRotationRow::operator = (const TRotation::TRotationRow & rr) {
0207    fRR = rr.fRR;
0208    fII = rr.fII;
0209    return *this;
0210 }
0211 
0212 inline Double_t TRotation::TRotationRow::operator [] (int jj) const {
0213    return fRR->operator()(fII,jj);
0214 }
0215 
0216 inline TRotation::TRotationRow TRotation::operator [] (int i) const {
0217    return TRotationRow(*this, i);
0218 }
0219 
0220 inline TRotation & TRotation::operator = (const TRotation & m) {
0221    fxx = m.fxx;
0222    fxy = m.fxy;
0223    fxz = m.fxz;
0224    fyx = m.fyx;
0225    fyy = m.fyy;
0226    fyz = m.fyz;
0227    fzx = m.fzx;
0228    fzy = m.fzy;
0229    fzz = m.fzz;
0230    return *this;
0231 }
0232 
0233 inline Bool_t TRotation::operator == (const TRotation& m) const {
0234    return (fxx == m.fxx && fxy == m.fxy && fxz == m.fxz &&
0235            fyx == m.fyx && fyy == m.fyy && fyz == m.fyz &&
0236            fzx == m.fzx && fzy == m.fzy && fzz == m.fzz) ? kTRUE : kFALSE;
0237 }
0238 
0239 inline Bool_t TRotation::operator != (const TRotation &m) const {
0240    return (fxx != m.fxx || fxy != m.fxy || fxz != m.fxz ||
0241            fyx != m.fyx || fyy != m.fyy || fyz != m.fyz ||
0242            fzx != m.fzx || fzy != m.fzy || fzz != m.fzz) ? kTRUE : kFALSE;
0243 }
0244 
0245 inline Bool_t TRotation::IsIdentity() const {
0246    return  (fxx == 1.0 && fxy == 0.0 && fxz == 0.0 &&
0247             fyx == 0.0 && fyy == 1.0 && fyz == 0.0 &&
0248             fzx == 0.0 && fzy == 0.0 && fzz == 1.0) ? kTRUE : kFALSE;
0249 }
0250 
0251 inline TRotation & TRotation::SetToIdentity() {
0252    fxx = fyy = fzz = 1.0;
0253    fxy = fxz = fyx = fyz = fzx = fzy = 0.0;
0254    return *this;
0255 }
0256 
0257 inline TVector3 TRotation::operator * (const TVector3 & p) const {
0258    return TVector3(fxx*p.X() + fxy*p.Y() + fxz*p.Z(),
0259                    fyx*p.X() + fyy*p.Y() + fyz*p.Z(),
0260                    fzx*p.X() + fzy*p.Y() + fzz*p.Z());
0261 }
0262 
0263 inline TRotation & TRotation::operator *= (const TRotation & m) {
0264    return *this = operator * (m);
0265 }
0266 
0267 inline TRotation & TRotation::Transform(const TRotation & m) {
0268    return *this = m.operator * (*this);
0269 }
0270 
0271 inline TRotation TRotation::Inverse() const {
0272    return TRotation(fxx, fyx, fzx, fxy, fyy, fzy, fxz, fyz, fzz);
0273 }
0274 
0275 inline TRotation & TRotation::Invert() {
0276    return *this=Inverse();
0277 }
0278 
0279 inline TRotation & TRotation::Rotate(Double_t psi, const TVector3 * p) {
0280    return Rotate(psi, *p);
0281 }
0282 
0283 
0284 
0285 #endif