ROOT logo
ROOT » MATH » PHYSICS » TRotation

class TRotation: public TObject

The Physics Vector package 
-*                    ==========================                       
-* The Physics Vector package consists of five classes:                
-*   - TVector2                                                        
-*   - TVector3                                                        
-*   - TRotation                                                       
-*   - TLorentzVector                                                  
-*   - TLorentzRotation                                                
-* It is a combination of CLHEPs Vector package written by             
-* Leif Lonnblad, Andreas Nilsson and Evgueni Tcherniaev               
-* and a ROOT package written by Pasha Murat.                          
-* for CLHEP see:  http://wwwinfo.cern.ch/asd/lhc++/clhep/             
*

TRotation

The TRotation class describes a rotation of objects of the TVector3 class. It is a 3*3 matrix of Double_t:

| xx  xy  xz |
| yx  yy  yz |
| zx  zy  zz |

It describes a so called active rotation, i.e. rotation of objects inside a static system of coordinates. In case you want to rotate the frame and want to know the coordinates of objects in the rotated system, you should apply the inverse rotation to the objects. If you want to transform coordinates from the rotated frame to the original frame you have to apply the direct transformation.

A rotation around a specified axis means counterclockwise rotation around the positive direction of the axis.
 

Declaration, Access, Comparisons

  TRotation r;    // r initialized as identity
  TRotation m(r); // m = r

There is no direct way to set the matrix elements - to ensure that a TRotation object always describes a real rotation. But you can get the values by the member functions XX()..ZZ() or the (,) operator:

  Double_t xx = r.XX();     //  the same as xx=r(0,0)
           xx = r(0,0);

  if (r==m) {...}          // test for equality
  if (r!=m) {..}           // test for inequality
  if (r.IsIdentity()) {...} // test for identity
 

Rotation around axes

The following matrices desrcibe counterclockwise rotations around coordinate axes

        | 1   0       0    |
Rx(a) = | 0 cos(a) -sin(a) |
        | 0 sin(a) cos(a)  |

        | cos(a)  0 sin(a) |
Ry(a) = |   0     1    0   |
        | -sin(a) 0 cos(a) |

        | cos(a) -sin(a) 0 |
Rz(a) = | sin(a) cos(a) 0 |
        |   0      0     1 |
and are implemented as member functions RotateX(), RotateY() and RotateZ():

  r.RotateX(TMath::Pi()); // rotation around the x-axis

Rotation around arbitary axis

The member function Rotate() allows to rotate around an arbitary vector (not neccessary a unit one) and returns the result.

  r.Rotate(TMath::Pi()/3,TVector3(3,4,5));

It is possible to find a unit vector and an angle, which describe the same rotation as the current one:

  Double_t angle;
  TVector3 axis;
  r.GetAngleAxis(angle,axis);

Rotation of local axes

Member function RotateAxes() adds a rotation of local axes to the current rotation and returns the result:

  TVector3 newX(0,1,0);
  TVector3 newY(0,0,1);
  TVector3 newZ(1,0,0);
  a.RotateAxes(newX,newY,newZ);

Member functions ThetaX(), ThetaY(), ThetaZ(), PhiX(), PhiY(),PhiZ() return azimuth and polar angles of the rotated axes:

  Double_t tx,ty,tz,px,py,pz;
  tx= a.ThetaX();
  ...
  pz= a.PhiZ();

Setting The Rotations

The member function SetToIdentity() will set the rotation object to the identity (no rotation). With a minor caveat, the Euler angles of the rotation may be set using SetXEulerAngles() or individually set with SetXPhi(), SetXTheta(), and SetXPsi(). These routines set the Euler angles using the X-convention which is defined by a rotation about the Z-axis, about the new X-axis, and about the new Z-axis. This is the convention used in Landau and Lifshitz, Goldstein and other common physics texts. The Y-convention euler angles can be set with SetYEulerAngles(), SetYPhi(), SetYTheta(), and SetYPsi(). The caveat is that Euler angles usually define the rotation of the new coordinate system with respect to the original system, however, the TRotation class specifies the rotation of the object in the original system (an active rotation). To recover the usual Euler rotations (ie. rotate the system not the object), you must take the inverse of the rotation. The member functions SetXAxis(), SetYAxis(), and SetZAxis() will create a rotation which rotates the requested axis of the object to be parallel to a vector. If used with one argument, the rotation about that axis is arbitrary. If used with two arguments, the second variable defines the XY, YZ, or ZX respectively.

Inverse rotation

  TRotation a,b;
  ...
  b = a.Inverse();  // b is inverse of a, a is unchanged
  b = a.Invert();   // invert a and set b = a

Compound Rotations

The operator * has been implemented in a way that follows the mathematical notation of a product of the two matrices which describe the two consecutive rotations. Therefore the second rotation should be placed first:

  r = r2 * r1;

Rotation of TVector3

The TRotation class provides an operator * which allows to express a rotation of a TVector3 analog to the mathematical notation

  | x' |   | xx xy xz | | x |
  | y' | = | yx yy yz | | y |
  | z' |   | zx zy zz | | z |

e.g.:

  TVector3 v(1,1,1);
  v = r * v;

You can also use the Transform() member function or the operator *= of the
TVector3 class:

  TVector3 v;
  TRotation r;
  v.Transform(r);
  v *= r;  //Attention v = r * v


Function Members (Methods)

public:
TRotation()
TRotation(const TRotation&)
TRotation(const TQuaternion&)
virtual~TRotation()
voidTObject::AbstractMethod(const char* method) const
voidAngleAxis(Double_t&, TVector3&) const
virtual voidTObject::AppendPad(Option_t* option = "")
virtual voidTObject::Browse(TBrowser* b)
static TClass*Class()
virtual const char*TObject::ClassName() const
virtual voidTObject::Clear(Option_t* = "")
virtual TObject*TObject::Clone(const char* newname = "") const
virtual Int_tTObject::Compare(const TObject* obj) const
virtual voidTObject::Copy(TObject& object) const
virtual voidTObject::Delete(Option_t* option = "")MENU
virtual Int_tTObject::DistancetoPrimitive(Int_t px, Int_t py)
virtual voidTObject::Draw(Option_t* option = "")
virtual voidTObject::DrawClass() constMENU
virtual TObject*TObject::DrawClone(Option_t* option = "") constMENU
virtual voidTObject::Dump() constMENU
virtual voidTObject::Error(const char* method, const char* msgfmt) const
virtual voidTObject::Execute(const char* method, const char* params, Int_t* error = 0)
virtual voidTObject::Execute(TMethod* method, TObjArray* params, Int_t* error = 0)
virtual voidTObject::ExecuteEvent(Int_t event, Int_t px, Int_t py)
virtual voidTObject::Fatal(const char* method, const char* msgfmt) const
virtual TObject*TObject::FindObject(const char* name) const
virtual TObject*TObject::FindObject(const TObject* obj) const
virtual Option_t*TObject::GetDrawOption() const
static Long_tTObject::GetDtorOnly()
virtual const char*TObject::GetIconName() const
virtual const char*TObject::GetName() const
virtual char*TObject::GetObjectInfo(Int_t px, Int_t py) const
static Bool_tTObject::GetObjectStat()
virtual Option_t*TObject::GetOption() const
virtual const char*TObject::GetTitle() const
virtual UInt_tTObject::GetUniqueID() const
Double_tGetXPhi() const
Double_tGetXPsi() const
Double_tGetXTheta() const
Double_tGetYPhi() const
Double_tGetYPsi() const
Double_tGetYTheta() const
virtual Bool_tTObject::HandleTimer(TTimer* timer)
virtual ULong_tTObject::Hash() const
virtual voidTObject::Info(const char* method, const char* msgfmt) const
virtual Bool_tTObject::InheritsFrom(const char* classname) const
virtual Bool_tTObject::InheritsFrom(const TClass* cl) const
virtual voidTObject::Inspect() constMENU
TRotationInverse() const
TRotation&Invert()
voidTObject::InvertBit(UInt_t f)
virtual TClass*IsA() const
virtual Bool_tTObject::IsEqual(const TObject* obj) const
virtual Bool_tTObject::IsFolder() const
Bool_tIsIdentity() const
Bool_tTObject::IsOnHeap() const
virtual Bool_tTObject::IsSortable() const
Bool_tTObject::IsZombie() const
virtual voidTObject::ls(Option_t* option = "") const
voidMakeBasis(TVector3& xAxis, TVector3& yAxis, TVector3& zAxis) const
voidTObject::MayNotUse(const char* method) const
virtual Bool_tTObject::Notify()
voidTObject::Obsolete(const char* method, const char* asOfVers, const char* removedFromVers) const
static voidTObject::operator delete(void* ptr)
static voidTObject::operator delete(void* ptr, void* vp)
static voidTObject::operator delete[](void* ptr)
static voidTObject::operator delete[](void* ptr, void* vp)
void*TObject::operator new(size_t sz)
void*TObject::operator new(size_t sz, void* vp)
void*TObject::operator new[](size_t sz)
void*TObject::operator new[](size_t sz, void* vp)
Bool_toperator!=(const TRotation& m) const
Double_toperator()(int, int) const
TVector3operator*(const TVector3& p) const
TRotationoperator*(const TRotation&) const
TRotation&operator*=(const TRotation& m)
TRotation&operator=(const TRotation& m)
Bool_toperator==(const TRotation& m) const
TRotation::TRotationRowoperator[](int i) const
virtual voidTObject::Paint(Option_t* option = "")
Double_tPhiX() const
Double_tPhiY() const
Double_tPhiZ() const
virtual voidTObject::Pop()
virtual voidTObject::Print(Option_t* option = "") const
virtual Int_tTObject::Read(const char* name)
virtual voidTObject::RecursiveRemove(TObject* obj)
voidTObject::ResetBit(UInt_t f)
TRotation&Rotate(Double_t, const TVector3&)
TRotation&Rotate(Double_t psi, const TVector3* p)
TRotation&RotateAxes(const TVector3& newX, const TVector3& newY, const TVector3& newZ)
TRotation&RotateX(Double_t)
TRotation&RotateXEulerAngles(Double_t phi, Double_t theta, Double_t psi)
TRotation&RotateY(Double_t)
TRotation&RotateYEulerAngles(Double_t phi, Double_t theta, Double_t psi)
TRotation&RotateZ(Double_t)
virtual voidTObject::SaveAs(const char* filename = "", Option_t* option = "") constMENU
virtual voidTObject::SavePrimitive(ostream& out, Option_t* option = "")
voidTObject::SetBit(UInt_t f)
voidTObject::SetBit(UInt_t f, Bool_t set)
virtual voidTObject::SetDrawOption(Option_t* option = "")MENU
static voidTObject::SetDtorOnly(void* obj)
static voidTObject::SetObjectStat(Bool_t stat)
TRotation&SetToIdentity()
virtual voidTObject::SetUniqueID(UInt_t uid)
TRotation&SetXAxis(const TVector3& axis)
TRotation&SetXAxis(const TVector3& axis, const TVector3& xyPlane)
TRotation&SetXEulerAngles(Double_t phi, Double_t theta, Double_t psi)
voidSetXPhi(Double_t)
voidSetXPsi(Double_t)
voidSetXTheta(Double_t)
TRotation&SetYAxis(const TVector3& axis)
TRotation&SetYAxis(const TVector3& axis, const TVector3& yzPlane)
TRotation&SetYEulerAngles(Double_t phi, Double_t theta, Double_t psi)
voidSetYPhi(Double_t)
voidSetYPsi(Double_t)
voidSetYTheta(Double_t)
TRotation&SetZAxis(const TVector3& axis)
TRotation&SetZAxis(const TVector3& axis, const TVector3& zxPlane)
virtual voidShowMembers(TMemberInspector&)
virtual voidStreamer(TBuffer&)
voidStreamerNVirtual(TBuffer& ClassDef_StreamerNVirtual_b)
virtual voidTObject::SysError(const char* method, const char* msgfmt) const
Bool_tTObject::TestBit(UInt_t f) const
Int_tTObject::TestBits(UInt_t f) const
Double_tThetaX() const
Double_tThetaY() const
Double_tThetaZ() const
TRotation&Transform(const TRotation& m)
virtual voidTObject::UseCurrentStyle()
virtual voidTObject::Warning(const char* method, const char* msgfmt) const
virtual Int_tTObject::Write(const char* name = 0, Int_t option = 0, Int_t bufsize = 0)
virtual Int_tTObject::Write(const char* name = 0, Int_t option = 0, Int_t bufsize = 0) const
Double_tXX() const
Double_tXY() const
Double_tXZ() const
Double_tYX() const
Double_tYY() const
Double_tYZ() const
Double_tZX() const
Double_tZY() const
Double_tZZ() const
protected:
TRotation(Double_t, Double_t, Double_t, Double_t, Double_t, Double_t, Double_t, Double_t, Double_t)
virtual voidTObject::DoError(int level, const char* location, const char* fmt, va_list va) const
voidTObject::MakeZombie()

Data Members

Class Charts

Inheritance Inherited Members Includes Libraries
Class Charts

Function documentation

TRotation()
{}
TRotation(const TRotation& )
{}
TRotation(Double_t , Double_t , Double_t , Double_t , Double_t , Double_t , Double_t , Double_t , Double_t )
{}
Double_t operator()(int , int ) const
dereferencing operator const
TRotation operator*(const TRotation& ) const
multiplication operator
TRotation(const TQuaternion& )
 Constructor for a rotation based on a Quaternion
 if magnitude of quaternion is null, creates identity rotation
 if quaternion is non-unit, creates rotation corresponding to the normalized (unit) quaternion
TRotation & Rotate(Double_t , const TVector3& )
rotate along an axis
TRotation & RotateX(Double_t )
rotate around x
TRotation & RotateY(Double_t )
rotate around y
TRotation & RotateZ(Double_t )
rotate around z
TRotation & RotateAxes(const TVector3& newX, const TVector3& newY, const TVector3& newZ)
rotate axes
Double_t PhiX() const
return Phi
Double_t PhiY() const
return Phi
Double_t PhiZ() const
return Phi
Double_t ThetaX() const
return Phi
Double_t ThetaY() const
return Theta
Double_t ThetaZ() const
return Theta
void AngleAxis(Double_t& , TVector3& ) const
rotation defined by an angle and a vector
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.  This is slightly less efficient than
 directly applying the rotation, but makes the code much clearer.  My
 presumption is that this code is not going to be a speed bottle neck.
TRotation & SetYEulerAngles(Double_t phi, Double_t theta, Double_t psi)
 Rotate using the y-convention.
TRotation & RotateXEulerAngles(Double_t phi, Double_t theta, Double_t psi)
 Rotate using the x-convention.
TRotation & RotateYEulerAngles(Double_t phi, Double_t theta, Double_t psi)
 Rotate using the y-convention.
void SetXPhi(Double_t )
set XPhi
void SetXTheta(Double_t )
set XTheta
void SetXPsi(Double_t )
set XPsi
void SetYPhi(Double_t )
set YPhi
void SetYTheta(Double_t )
set YTheta
void SetYPsi(Double_t )
set YPsi
Double_t GetXPhi(void)
return phi angle
Double_t GetYPhi(void)
return YPhi
Double_t GetXTheta(void)
return XTheta
Double_t GetYTheta(void)
return YTheta
Double_t GetXPsi(void)
Get psi angle
Double_t GetYPsi(void)
return YPsi
TRotation & SetXAxis(const TVector3& axis, const TVector3& xyPlane)
set X axis
TRotation & SetXAxis(const TVector3& axis)
set X axis
TRotation & SetYAxis(const TVector3& axis, const TVector3& yzPlane)
set Y axis
TRotation & SetYAxis(const TVector3& axis)
set Y axis
TRotation & SetZAxis(const TVector3& axis, const TVector3& zxPlane)
set Z axis
TRotation & SetZAxis(const TVector3& axis)
set Z axis
void MakeBasis(TVector3& xAxis, TVector3& yAxis, TVector3& zAxis) const
 Make the Z axis into a unit variable.
Double_t XX() const
{ return fxx; }
Double_t XY() const
{ return fxy; }
Double_t XZ() const
{ return fxz; }
Double_t YX() const
{ return fyx; }
Double_t YY() const
{ return fyy; }
Double_t YZ() const
{ return fyz; }
Double_t ZX() const
{ return fzx; }
Double_t ZY() const
{ return fzy; }
Double_t ZZ() const
{ return fzz; }
Bool_t IsIdentity() const
TRotation & SetToIdentity()
TRotation & Transform(const TRotation& m)
TRotation Inverse() const
TRotation & Invert()
TRotation & Rotate(Double_t psi, const TVector3* p)
TRotationRow & operator=(const TRotation& m)
virtual ~TRotation()
 Copy constructor.
{;}