# 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 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() void TObject::AbstractMethod(const char* method) const void AngleAxis(Double_t&, TVector3&) const virtual void TObject::AppendPad(Option_t* option = "") virtual void TObject::Browse(TBrowser* b) static TClass* Class() virtual const char* TObject::ClassName() const virtual void TObject::Clear(Option_t* = "") virtual TObject* TObject::Clone(const char* newname = "") const virtual Int_t TObject::Compare(const TObject* obj) const virtual void TObject::Copy(TObject& object) const virtual void TObject::Delete(Option_t* option = "") virtual Int_t TObject::DistancetoPrimitive(Int_t px, Int_t py) virtual void TObject::Draw(Option_t* option = "") virtual void TObject::DrawClass() const virtual TObject* TObject::DrawClone(Option_t* option = "") const virtual void TObject::Dump() const virtual void TObject::Error(const char* method, const char* msgfmt) const virtual void TObject::Execute(const char* method, const char* params, Int_t* error = 0) virtual void TObject::Execute(TMethod* method, TObjArray* params, Int_t* error = 0) virtual void TObject::ExecuteEvent(Int_t event, Int_t px, Int_t py) virtual void TObject::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_t TObject::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_t TObject::GetObjectStat() virtual Option_t* TObject::GetOption() const virtual const char* TObject::GetTitle() const virtual UInt_t TObject::GetUniqueID() const Double_t GetXPhi() const Double_t GetXPsi() const Double_t GetXTheta() const Double_t GetYPhi() const Double_t GetYPsi() const Double_t GetYTheta() const virtual Bool_t TObject::HandleTimer(TTimer* timer) virtual ULong_t TObject::Hash() const virtual void TObject::Info(const char* method, const char* msgfmt) const virtual Bool_t TObject::InheritsFrom(const char* classname) const virtual Bool_t TObject::InheritsFrom(const TClass* cl) const virtual void TObject::Inspect() const TRotation Inverse() const TRotation& Invert() void TObject::InvertBit(UInt_t f) virtual TClass* IsA() const virtual Bool_t TObject::IsEqual(const TObject* obj) const virtual Bool_t TObject::IsFolder() const Bool_t IsIdentity() const Bool_t TObject::IsOnHeap() const virtual Bool_t TObject::IsSortable() const Bool_t TObject::IsZombie() const virtual void TObject::ls(Option_t* option = "") const void MakeBasis(TVector3& xAxis, TVector3& yAxis, TVector3& zAxis) const void TObject::MayNotUse(const char* method) const virtual Bool_t TObject::Notify() static void TObject::operator delete(void* ptr) static void TObject::operator delete(void* ptr, void* vp) static void TObject::operator delete[](void* ptr) static void TObject::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_t operator!=(const TRotation& m) const Double_t operator()(int, int) const TVector3 operator*(const TVector3& p) const TRotation operator*(const TRotation&) const TRotation& operator*=(const TRotation& m) TRotation& operator=(const TRotation& m) Bool_t operator==(const TRotation& m) const TRotation::TRotationRow operator[](int i) const virtual void TObject::Paint(Option_t* option = "") Double_t PhiX() const Double_t PhiY() const Double_t PhiZ() const virtual void TObject::Pop() virtual void TObject::Print(Option_t* option = "") const virtual Int_t TObject::Read(const char* name) virtual void TObject::RecursiveRemove(TObject* obj) void TObject::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 void TObject::SaveAs(const char* filename = "", Option_t* option = "") const virtual void TObject::SavePrimitive(basic_ostream >& out, Option_t* option = "") void TObject::SetBit(UInt_t f) void TObject::SetBit(UInt_t f, Bool_t set) virtual void TObject::SetDrawOption(Option_t* option = "") static void TObject::SetDtorOnly(void* obj) static void TObject::SetObjectStat(Bool_t stat) TRotation& SetToIdentity() virtual void TObject::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) void SetXPhi(Double_t) void SetXPsi(Double_t) void SetXTheta(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) void SetYPhi(Double_t) void SetYPsi(Double_t) void SetYTheta(Double_t) TRotation& SetZAxis(const TVector3& axis) TRotation& SetZAxis(const TVector3& axis, const TVector3& zxPlane) virtual void ShowMembers(TMemberInspector& insp, char* parent) virtual void Streamer(TBuffer& b) void StreamerNVirtual(TBuffer& b) virtual void TObject::SysError(const char* method, const char* msgfmt) const Bool_t TObject::TestBit(UInt_t f) const Int_t TObject::TestBits(UInt_t f) const Double_t ThetaX() const Double_t ThetaY() const Double_t ThetaZ() const TRotation& Transform(const TRotation& m) virtual void TObject::UseCurrentStyle() virtual void TObject::Warning(const char* method, const char* msgfmt) const virtual Int_t TObject::Write(const char* name = 0, Int_t option = 0, Int_t bufsize = 0) virtual Int_t TObject::Write(const char* name = 0, Int_t option = 0, Int_t bufsize = 0) const Double_t XX() const Double_t XY() const Double_t XZ() const Double_t YX() const Double_t YY() const Double_t YZ() const Double_t ZX() const Double_t ZY() const Double_t ZZ() const
protected:
 TRotation(Double_t, Double_t, Double_t, Double_t, Double_t, Double_t, Double_t, Double_t, Double_t) virtual void TObject::DoError(int level, const char* location, const char* fmt, va_list va) const void TObject::MakeZombie()

## Data Members

public:
 enum TObject::EStatusBits { kCanDelete kMustCleanup kObjInCanvas kIsReferenced kHasUUID kCannotPick kNoContextMenu kInvalidObject }; enum TObject::[unnamed] { kIsOnHeap kNotDeleted kZombie kBitMask kSingleKey kOverwrite kWriteDelete };
protected:
 Double_t fxx Double_t fxy Double_t fxz Double_t fyx Double_t fyy Double_t fyz Double_t fzx Double_t fzy Double_t fzz

## Function documentation

`{}`
TRotation(const TRotation & m)
`{}`

`{}`
Double_t operator()(int , int ) const
```dereferencing operator const
```
TRotation operator*(const TRotation & b)
```multiplication operator
```
TRotation(const TQuaternion & Q)
``` 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 a, const TVector3& axis)
```rotate along an axis
```

```rotate around x
```

```rotate around y
```

```rotate around z
```
TRotation & RotateAxes(const TVector3& newX, const TVector3& newY, const TVector3& newZ)
```rotate axes
```

```return Phi
```

```return Phi
```

```return Phi
```

```return Phi
```

```return Theta
```

```return Theta
```
void AngleAxis(Double_t& , TVector3& ) const
```ation defined by an angle and a vec
```
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)
```et X axi
```
TRotation & SetXAxis(const TVector3& axis)
```et X axi
```
TRotation & SetYAxis(const TVector3& axis, const TVector3& yzPlane)
```et Y axi
```
TRotation & SetYAxis(const TVector3& axis)
```et Y axi
```
TRotation & SetZAxis(const TVector3& axis, const TVector3& zxPlane)
```et Z axi
```
TRotation & SetZAxis(const TVector3& axis)
```et Z axi
```
void MakeBasis(TVector3& xAxis, TVector3& yAxis, TVector3& zAxis) const
``` Make the Z axis into a unit variable.
```

`{ return fxx; }`

`{ return fxy; }`

`{ return fxz; }`

`{ return fyx; }`

`{ return fyy; }`

`{ return fyz; }`

`{ return fzx; }`

`{ return fzy; }`

`{ return fzz; }`
TRotation & Transform(const TRotation& m)

TRotation & Rotate(Double_t psi, const TVector3 * p)
virtual ~TRotation()
``` Copy constructor.
```
`{;}`

Author: Peter Malzacher 19/06/99
Last update: root/physics:\$Id: TRotation.h 20882 2007-11-19 11:31:26Z rdm \$