Logo ROOT  
Reference Guide
RotationZYX.cxx
Go to the documentation of this file.
1 // @(#)root/mathcore:$Id$
2 // Authors: W. Brown, M. Fischler, L. Moneta 2005
3 
4  /**********************************************************************
5  * *
6  * Copyright (c) 2005 , LCG ROOT FNAL MathLib Team *
7  * *
8  * *
9  **********************************************************************/
10 
11 // Implementation file for rotation in 3 dimensions, represented by RotationZYX
12 //
13 // Created by: Lorenzo Moneta, May 23 2007
14 //
15 // Last update: $Id$
16 //
18 
19 #include <cmath>
20 
28 
30 
31 namespace ROOT {
32 
33 namespace Math {
34 
35 // ========== Constructors and Assignment =====================
36 
37 
38 
39 // ========== Operations =====================
40 
41 // DisplacementVector3D< Cartesian3D<double> >
42 // RotationZYX::
43 // operator() (const DisplacementVector3D< Cartesian3D<double> > & v) const
44 // {
45 // return Rotation3D(*this)(v);
46 // }
47 
48 
49 RotationZYX RotationZYX::operator * (const Rotation3D & r) const {
50  // combine with a Rotation3D
51  return RotationZYX ( Rotation3D(*this) * r );
52 }
53 
54 RotationZYX RotationZYX::operator * (const AxisAngle & a) const {
55  // combine with a AxisAngle
56  return RotationZYX ( Quaternion(*this) * Quaternion(a) );
57 }
58 
60  // combine with EulerAngles
61  return RotationZYX ( Quaternion(*this) * Quaternion(e) );
62 }
63 
65  // combine with a RotationZYX
66  //return RotationZYX ( Quaternion(*this) * Quaternion(e) );
67  return RotationZYX ( Rotation3D(*this) * Rotation3D(e) );
68 }
70  // combination with a Quaternion
71  return RotationZYX ( Quaternion(*this) * q );
72 }
73 
75  // combine with a RotationX
76  return RotationZYX ( Quaternion(*this) * r );
77 }
78 
80  // combine with a RotationY
81  return RotationZYX ( Quaternion(*this) * r );
82 }
83 
85  // combine with a RotationZ
86  // TODO -- this can be made much faster because it merely adds
87  // the r.Angle() to phi.
88  Scalar newPhi = fPhi + r.Angle();
89  if ( newPhi <= -Pi()|| newPhi > Pi() ) {
90  newPhi = newPhi - std::floor( newPhi/(2*Pi()) +.5 ) * 2*Pi();
91  }
92  return RotationZYX ( newPhi, fTheta, fPsi );
93 }
94 
95 RotationZYX operator * ( RotationX const & r, RotationZYX const & e ) {
96  return RotationZYX(r) * e; // TODO: improve performance
97 }
98 
99 RotationZYX operator * ( RotationY const & r, RotationZYX const & e ) {
100  return RotationZYX(r) * e; // TODO: improve performance
101 }
102 
103 RotationZYX
104 operator * ( RotationZ const & r, RotationZYX const & e ) {
105  return RotationZYX(r) * e; // TODO: improve performance
106 }
107 
109 {
110  // rectify . The angle theta must be defined between [-PI/2,PI.2]
111  // same as Euler- Angles, just here Theta is shifted by PI/2 with respect to
112  // the theta of the EulerAngles class
113 
114  Scalar theta2 = fTheta + M_PI_2;
115  if ( theta2 < 0 || theta2 > Pi() ) {
116  Scalar t = theta2 - std::floor( theta2/(2*Pi() ) ) * 2*Pi();
117  if ( t <= Pi() ) {
118  theta2 = t;
119  } else {
120  theta2 = 2*Pi() - t;
121  fPhi = fPhi + Pi();
122  fPsi = fPsi + Pi();
123  }
124  // ftheta is shifted of PI/2 w.r.t theta2
125  fTheta = theta2 - M_PI_2;
126  }
127 
128  if ( fPhi <= -Pi()|| fPhi > Pi() ) {
129  fPhi = fPhi - std::floor( fPhi/(2*Pi()) +.5 ) * 2*Pi();
130  }
131 
132  if ( fPsi <= -Pi()|| fPsi > Pi() ) {
133  fPsi = fPsi - std::floor( fPsi/(2*Pi()) +.5 ) * 2*Pi();
134  }
135 
136 } // Rectify()
137 
138 void RotationZYX::Invert()
139 {
140  // invert this rotation.
141  // use Rotation3D. TO Do :have algorithm to invert it directly
142  Rotation3D r(*this);
143  //Quaternion r(*this);
144  r.Invert();
145  *this = r;
146 }
147 
148 // ========== I/O =====================
149 
150 std::ostream & operator<< (std::ostream & os, const RotationZYX & e) {
151  // TODO - this will need changing for machine-readable issues
152  // and even the human readable form may need formatiing improvements
153  os << "\n{phi(Z angle): " << e.Phi() << " theta(Y angle): " << e.Theta()
154  << " psi(X angle): " << e.Psi() << "}\n";
155  return os;
156 }
157 
158 
159 } //namespace Math
160 } //namespace ROOT
M_PI_2
#define M_PI_2
Definition: Math.h:40
e
#define e(i)
Definition: RSha256.hxx:121
ROOT::Math::RotationZYX::fTheta
double fTheta
Definition: RotationZYX.h:331
ROOT::Math::RotationZYX::Pi
static double Pi()
Definition: RotationZYX.h:334
floor
double floor(double)
ROOT::Math::RotationZYX::Rectify
void Rectify()
Re-adjust components place angles in canonical ranges.
Definition: RotationZYX.cxx:118
ROOT::Math::RotationZYX
Rotation class with the (3D) rotation represented by angles describing first a rotation of an angle p...
Definition: RotationZYX.h:71
r
ROOT::R::TRInterface & r
Definition: Object.C:4
ROOT::Math::RotationZ
Rotation class representing a 3D rotation about the Z axis by the angle of rotation.
Definition: RotationZ.h:53
ROOT::Math::Rotation3D
Rotation class with the (3D) rotation represented by a 3x3 orthogonal matrix.
Definition: Rotation3D.h:75
RotationZYX.h
ROOT::Math::operator<<
std::ostream & operator<<(std::ostream &os, const AxisAngle &a)
Stream Output and Input.
Definition: AxisAngle.cxx:101
ROOT::Math::RotationZYX::RotationZYX
RotationZYX()
Default constructor.
Definition: RotationZYX.h:88
Quaternion.h
q
float * q
Definition: THbookFile.cxx:89
Cartesian3D.h
ROOT::Math::RotationZYX::fPhi
double fPhi
Definition: RotationZYX.h:330
ROOT::Math::RotationZYX::fPsi
double fPsi
Definition: RotationZYX.h:332
AxisAnglefwd.h
a
auto * a
Definition: textangle.C:12
ROOT::Math::EulerAngles
EulerAngles class describing rotation as three angles (Euler Angles).
Definition: EulerAngles.h:53
ROOT::Math::RotationZYX::Scalar
double Scalar
Definition: RotationZYX.h:80
ROOT::Math::RotationX
Rotation class representing a 3D rotation about the X axis by the angle of rotation.
Definition: RotationX.h:53
RotationZ.h
ROOT::Math::operator*
AxisAngle operator*(RotationX const &r1, AxisAngle const &r2)
Multiplication of an axial rotation by an AxisAngle.
Definition: AxisAngleXother.cxx:191
Rotation3D.h
DisplacementVector3D.h
ROOT::Math::Scalar
Rotation3D::Scalar Scalar
Definition: Rotation3DxAxial.cxx:69
ROOT::Math::RotationZYX::Invert
void Invert()
Invert a rotation in place.
Definition: RotationZYX.cxx:148
ROOT::Math::RotationZYX::operator*
AVector operator*(const AVector &v) const
Overload operator * for rotation on a vector.
Definition: RotationZYX.h:269
ROOT::Math::Quaternion
Rotation class with the (3D) rotation represented by a unit quaternion (u, i, j, k).
Definition: Quaternion.h:57
RotationX.h
RotationY.h
ROOT
VSD Structures.
Definition: StringConv.hxx:21
Math
ROOT::Math::RotationY
Rotation class representing a 3D rotation about the Y axis by the angle of rotation.
Definition: RotationY.h:53