Logo ROOT   6.13/01
Reference Guide
List of all members | Classes | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
TRotation Class Reference

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 describe 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 arbitrary axis

The member function Rotate() allows to rotate around an arbitrary vector (not necessary 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

...
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:

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

Definition at line 20 of file TRotation.h.

Classes

class  TRotationRow
 

Public Member Functions

 TRotation ()
 Constructor. More...
 
 TRotation (const TRotation &)
 Constructor. More...
 
 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. More...
 
virtual ~TRotation ()
 
void AngleAxis (Double_t &, TVector3 &) const
 Rotation defined by an angle and a vector. More...
 
Double_t GetXPhi (void) const
 Return phi angle. More...
 
Double_t GetXPsi (void) const
 Get psi angle. More...
 
Double_t GetXTheta (void) const
 Return XTheta. More...
 
Double_t GetYPhi (void) const
 Return YPhi. More...
 
Double_t GetYPsi (void) const
 Return YPsi. More...
 
Double_t GetYTheta (void) const
 Return YTheta. More...
 
TRotation Inverse () const
 
TRotationInvert ()
 
Bool_t IsIdentity () const
 
void MakeBasis (TVector3 &xAxis, TVector3 &yAxis, TVector3 &zAxis) const
 Make the Z axis into a unit variable. More...
 
Bool_t operator!= (const TRotation &) const
 
Double_t operator() (int, int) const
 Dereferencing operator const. More...
 
TVector3 operator* (const TVector3 &) const
 
TRotation operator* (const TRotation &) const
 Multiplication operator. More...
 
TRotationoperator*= (const TRotation &)
 
TRotationoperator= (const TRotation &)
 
Bool_t operator== (const TRotation &) const
 
TRotationRow operator[] (int) const
 
Double_t PhiX () const
 Return Phi. More...
 
Double_t PhiY () const
 Return Phi. More...
 
Double_t PhiZ () const
 Return Phi. More...
 
TRotationRotate (Double_t, const TVector3 &)
 Rotate along an axis. More...
 
TRotationRotate (Double_t, const TVector3 *)
 
TRotationRotateAxes (const TVector3 &newX, const TVector3 &newY, const TVector3 &newZ)
 Rotate axes. More...
 
TRotationRotateX (Double_t)
 Rotate around x. More...
 
TRotationRotateXEulerAngles (Double_t phi, Double_t theta, Double_t psi)
 Rotate using the x-convention. More...
 
TRotationRotateY (Double_t)
 Rotate around y. More...
 
TRotationRotateYEulerAngles (Double_t phi, Double_t theta, Double_t psi)
 Rotate using the y-convention. More...
 
TRotationRotateZ (Double_t)
 Rotate around z. More...
 
TRotationSetToIdentity ()
 
TRotationSetXAxis (const TVector3 &axis)
 Set X axis. More...
 
TRotationSetXAxis (const TVector3 &axis, const TVector3 &xyPlane)
 Set X axis. More...
 
TRotationSetXEulerAngles (Double_t phi, Double_t theta, Double_t psi)
 Rotate using the x-convention (Landau and Lifshitz, Goldstein, &c) by doing the explicit rotations. More...
 
void SetXPhi (Double_t)
 Set XPhi. More...
 
void SetXPsi (Double_t)
 Set XPsi. More...
 
void SetXTheta (Double_t)
 Set XTheta. More...
 
TRotationSetYAxis (const TVector3 &axis)
 Set Y axis. More...
 
TRotationSetYAxis (const TVector3 &axis, const TVector3 &yzPlane)
 Set Y axis. More...
 
TRotationSetYEulerAngles (Double_t phi, Double_t theta, Double_t psi)
 Rotate using the y-convention. More...
 
void SetYPhi (Double_t)
 Set YPhi. More...
 
void SetYPsi (Double_t)
 Set YPsi. More...
 
void SetYTheta (Double_t)
 Set YTheta. More...
 
TRotationSetZAxis (const TVector3 &axis)
 Set Z axis. More...
 
TRotationSetZAxis (const TVector3 &axis, const TVector3 &zxPlane)
 Set Z axis. More...
 
Double_t ThetaX () const
 Return Theta. More...
 
Double_t ThetaY () const
 Return Theta. More...
 
Double_t ThetaZ () const
 Return Theta. More...
 
TRotationTransform (const TRotation &)
 
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 Member Functions

 TRotation (Double_t, Double_t, Double_t, Double_t, Double_t, Double_t, Double_t, Double_t, Double_t)
 Constructor. More...
 

Protected Attributes

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
 

#include <TRotation.h>

Inheritance diagram for TRotation:
[legend]

Constructor & Destructor Documentation

◆ TRotation() [1/4]

TRotation::TRotation ( )

Constructor.

Definition at line 195 of file TRotation.cxx.

◆ TRotation() [2/4]

TRotation::TRotation ( const TRotation m)

Constructor.

Definition at line 202 of file TRotation.cxx.

◆ TRotation() [3/4]

TRotation::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.

Definition at line 258 of file TRotation.cxx.

◆ ~TRotation()

virtual TRotation::~TRotation ( )
inlinevirtual

Definition at line 44 of file TRotation.h.

◆ TRotation() [4/4]

TRotation::TRotation ( Double_t  mxx,
Double_t  mxy,
Double_t  mxz,
Double_t  myx,
Double_t  myy,
Double_t  myz,
Double_t  mzx,
Double_t  mzy,
Double_t  mzz 
)
protected

Constructor.

Definition at line 209 of file TRotation.cxx.

Member Function Documentation

◆ AngleAxis()

void TRotation::AngleAxis ( Double_t &  angle,
TVector3 axis 
) const

Rotation defined by an angle and a vector.

Definition at line 462 of file TRotation.cxx.

◆ GetXPhi()

Double_t TRotation::GetXPhi ( void  ) const

Return phi angle.

Definition at line 578 of file TRotation.cxx.

◆ GetXPsi()

Double_t TRotation::GetXPsi ( void  ) const

Get psi angle.

Definition at line 644 of file TRotation.cxx.

◆ GetXTheta()

Double_t TRotation::GetXTheta ( void  ) const

Return XTheta.

Definition at line 630 of file TRotation.cxx.

◆ GetYPhi()

Double_t TRotation::GetYPhi ( void  ) const

Return YPhi.

Definition at line 623 of file TRotation.cxx.

◆ GetYPsi()

Double_t TRotation::GetYPsi ( void  ) const

Return YPsi.

Definition at line 690 of file TRotation.cxx.

◆ GetYTheta()

Double_t TRotation::GetYTheta ( void  ) const

Return YTheta.

Definition at line 637 of file TRotation.cxx.

◆ Inverse()

TRotation TRotation::Inverse ( ) const
inline

Definition at line 271 of file TRotation.h.

◆ Invert()

TRotation & TRotation::Invert ( )
inline

Definition at line 275 of file TRotation.h.

◆ IsIdentity()

Bool_t TRotation::IsIdentity ( ) const
inline

Definition at line 245 of file TRotation.h.

◆ MakeBasis()

void TRotation::MakeBasis ( TVector3 xAxis,
TVector3 yAxis,
TVector3 zAxis 
) const

Make the Z axis into a unit variable.

Definition at line 766 of file TRotation.cxx.

◆ operator!=()

Bool_t TRotation::operator!= ( const TRotation m) const
inline

Definition at line 239 of file TRotation.h.

◆ operator()()

Double_t TRotation::operator() ( int  i,
int  j 
) const

Dereferencing operator const.

Definition at line 218 of file TRotation.cxx.

◆ operator*() [1/2]

TVector3 TRotation::operator* ( const TVector3 p) const
inline

Definition at line 257 of file TRotation.h.

◆ operator*() [2/2]

TRotation TRotation::operator* ( const TRotation b) const

Multiplication operator.

Definition at line 241 of file TRotation.cxx.

◆ operator*=()

TRotation & TRotation::operator*= ( const TRotation m)
inline

Definition at line 263 of file TRotation.h.

◆ operator=()

TRotation & TRotation::operator= ( const TRotation m)
inline

Definition at line 220 of file TRotation.h.

◆ operator==()

Bool_t TRotation::operator== ( const TRotation m) const
inline

Definition at line 233 of file TRotation.h.

◆ operator[]()

TRotation::TRotationRow TRotation::operator[] ( int  i) const
inline

Definition at line 216 of file TRotation.h.

◆ PhiX()

Double_t TRotation::PhiX ( ) const

Return Phi.

Definition at line 420 of file TRotation.cxx.

◆ PhiY()

Double_t TRotation::PhiY ( ) const

Return Phi.

Definition at line 427 of file TRotation.cxx.

◆ PhiZ()

Double_t TRotation::PhiZ ( ) const

Return Phi.

Definition at line 434 of file TRotation.cxx.

◆ Rotate() [1/2]

TRotation & TRotation::Rotate ( Double_t  a,
const TVector3 axis 
)

Rotate along an axis.

Definition at line 324 of file TRotation.cxx.

◆ Rotate() [2/2]

TRotation & TRotation::Rotate ( Double_t  psi,
const TVector3 p 
)
inline

Definition at line 279 of file TRotation.h.

◆ RotateAxes()

TRotation & TRotation::RotateAxes ( const TVector3 newX,
const TVector3 newY,
const TVector3 newZ 
)

Rotate axes.

Definition at line 393 of file TRotation.cxx.

◆ RotateX()

TRotation & TRotation::RotateX ( Double_t  a)

Rotate around x.

Definition at line 345 of file TRotation.cxx.

◆ RotateXEulerAngles()

TRotation & TRotation::RotateXEulerAngles ( Double_t  phi,
Double_t  theta,
Double_t  psi 
)

Rotate using the x-convention.

Definition at line 514 of file TRotation.cxx.

◆ RotateY()

TRotation & TRotation::RotateY ( Double_t  a)

Rotate around y.

Definition at line 361 of file TRotation.cxx.

◆ RotateYEulerAngles()

TRotation & TRotation::RotateYEulerAngles ( Double_t  phi,
Double_t  theta,
Double_t  psi 
)

Rotate using the y-convention.

Definition at line 525 of file TRotation.cxx.

◆ RotateZ()

TRotation & TRotation::RotateZ ( Double_t  a)

Rotate around z.

Definition at line 377 of file TRotation.cxx.

◆ SetToIdentity()

TRotation & TRotation::SetToIdentity ( )
inline

Definition at line 251 of file TRotation.h.

◆ SetXAxis() [1/2]

TRotation & TRotation::SetXAxis ( const TVector3 axis)

Set X axis.

Definition at line 712 of file TRotation.cxx.

◆ SetXAxis() [2/2]

TRotation & TRotation::SetXAxis ( const TVector3 axis,
const TVector3 xyPlane 
)

Set X axis.

Definition at line 697 of file TRotation.cxx.

◆ SetXEulerAngles()

TRotation & 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.

Definition at line 487 of file TRotation.cxx.

◆ SetXPhi()

void TRotation::SetXPhi ( Double_t  phi)

Set XPhi.

Definition at line 536 of file TRotation.cxx.

◆ SetXPsi()

void TRotation::SetXPsi ( Double_t  psi)

Set XPsi.

Definition at line 550 of file TRotation.cxx.

◆ SetXTheta()

void TRotation::SetXTheta ( Double_t  theta)

Set XTheta.

Definition at line 543 of file TRotation.cxx.

◆ SetYAxis() [1/2]

TRotation & TRotation::SetYAxis ( const TVector3 axis)

Set Y axis.

Definition at line 735 of file TRotation.cxx.

◆ SetYAxis() [2/2]

TRotation & TRotation::SetYAxis ( const TVector3 axis,
const TVector3 yzPlane 
)

Set Y axis.

Definition at line 720 of file TRotation.cxx.

◆ SetYEulerAngles()

TRotation & TRotation::SetYEulerAngles ( Double_t  phi,
Double_t  theta,
Double_t  psi 
)

Rotate using the y-convention.

Definition at line 501 of file TRotation.cxx.

◆ SetYPhi()

void TRotation::SetYPhi ( Double_t  phi)

Set YPhi.

Definition at line 557 of file TRotation.cxx.

◆ SetYPsi()

void TRotation::SetYPsi ( Double_t  psi)

Set YPsi.

Definition at line 571 of file TRotation.cxx.

◆ SetYTheta()

void TRotation::SetYTheta ( Double_t  theta)

Set YTheta.

Definition at line 564 of file TRotation.cxx.

◆ SetZAxis() [1/2]

TRotation & TRotation::SetZAxis ( const TVector3 axis)

Set Z axis.

Definition at line 758 of file TRotation.cxx.

◆ SetZAxis() [2/2]

TRotation & TRotation::SetZAxis ( const TVector3 axis,
const TVector3 zxPlane 
)

Set Z axis.

Definition at line 743 of file TRotation.cxx.

◆ ThetaX()

Double_t TRotation::ThetaX ( ) const

Return Theta.

Definition at line 441 of file TRotation.cxx.

◆ ThetaY()

Double_t TRotation::ThetaY ( ) const

Return Theta.

Definition at line 448 of file TRotation.cxx.

◆ ThetaZ()

Double_t TRotation::ThetaZ ( ) const

Return Theta.

Definition at line 455 of file TRotation.cxx.

◆ Transform()

TRotation & TRotation::Transform ( const TRotation m)
inline

Definition at line 267 of file TRotation.h.

◆ XX()

Double_t TRotation::XX ( ) const
inline

Definition at line 190 of file TRotation.h.

◆ XY()

Double_t TRotation::XY ( ) const
inline

Definition at line 191 of file TRotation.h.

◆ XZ()

Double_t TRotation::XZ ( ) const
inline

Definition at line 192 of file TRotation.h.

◆ YX()

Double_t TRotation::YX ( ) const
inline

Definition at line 193 of file TRotation.h.

◆ YY()

Double_t TRotation::YY ( ) const
inline

Definition at line 194 of file TRotation.h.

◆ YZ()

Double_t TRotation::YZ ( ) const
inline

Definition at line 195 of file TRotation.h.

◆ ZX()

Double_t TRotation::ZX ( ) const
inline

Definition at line 196 of file TRotation.h.

◆ ZY()

Double_t TRotation::ZY ( ) const
inline

Definition at line 197 of file TRotation.h.

◆ ZZ()

Double_t TRotation::ZZ ( ) const
inline

Definition at line 198 of file TRotation.h.

Member Data Documentation

◆ fxx

Double_t TRotation::fxx
protected

Definition at line 182 of file TRotation.h.

◆ fxy

Double_t TRotation::fxy
protected

Definition at line 182 of file TRotation.h.

◆ fxz

Double_t TRotation::fxz
protected

Definition at line 182 of file TRotation.h.

◆ fyx

Double_t TRotation::fyx
protected

Definition at line 182 of file TRotation.h.

◆ fyy

Double_t TRotation::fyy
protected

Definition at line 182 of file TRotation.h.

◆ fyz

Double_t TRotation::fyz
protected

Definition at line 182 of file TRotation.h.

◆ fzx

Double_t TRotation::fzx
protected

Definition at line 182 of file TRotation.h.

◆ fzy

Double_t TRotation::fzy
protected

Definition at line 182 of file TRotation.h.

◆ fzz

Double_t TRotation::fzz
protected

Definition at line 182 of file TRotation.h.

Libraries for TRotation:
[legend]

The documentation for this class was generated from the following files: