Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 
29 
31 
32 namespace ROOT {
33 
34 namespace Math {
35 
36 // ========== Constructors and Assignment =====================
37 
38 
39 
40 // ========== Operations =====================
41 
42 // DisplacementVector3D< Cartesian3D<double> >
43 // RotationZYX::
44 // operator() (const DisplacementVector3D< Cartesian3D<double> > & v) const
45 // {
46 // return Rotation3D(*this)(v);
47 // }
48 
49 
50 RotationZYX RotationZYX::operator * (const Rotation3D & r) const {
51  // combine with a Rotation3D
52  return RotationZYX ( Rotation3D(*this) * r );
53 }
54 
55 RotationZYX RotationZYX::operator * (const AxisAngle & a) const {
56  // combine with a AxisAngle
57  return RotationZYX ( Quaternion(*this) * Quaternion(a) );
58 }
59 
60 RotationZYX RotationZYX::operator * (const EulerAngles & e) const {
61  // combine with EulerAngles
62  return RotationZYX ( Quaternion(*this) * Quaternion(e) );
63 }
64 
65 RotationZYX RotationZYX::operator * (const RotationZYX & e) const {
66  // combine with a RotationZYX
67  //return RotationZYX ( Quaternion(*this) * Quaternion(e) );
68  return RotationZYX ( Rotation3D(*this) * Rotation3D(e) );
69 }
70 RotationZYX RotationZYX::operator * (const Quaternion & q) const {
71  // combination with a Quaternion
72  return RotationZYX ( Quaternion(*this) * q );
73 }
74 
75 RotationZYX RotationZYX::operator * (const RotationX & r) const {
76  // combine with a RotationX
77  return RotationZYX ( Quaternion(*this) * r );
78 }
79 
80 RotationZYX RotationZYX::operator * (const RotationY & r) const {
81  // combine with a RotationY
82  return RotationZYX ( Quaternion(*this) * r );
83 }
84 
85 RotationZYX RotationZYX::operator * (const RotationZ & r) const {
86  // combine with a RotationZ
87  // TODO -- this can be made much faster because it merely adds
88  // the r.Angle() to phi.
89  Scalar newPhi = fPhi + r.Angle();
90  if ( newPhi <= -Pi()|| newPhi > Pi() ) {
91  newPhi = newPhi - std::floor( newPhi/(2*Pi()) +.5 ) * 2*Pi();
92  }
93  return RotationZYX ( newPhi, fTheta, fPsi );
94 }
95 
96 RotationZYX operator * ( RotationX const & r, RotationZYX const & e ) {
97  return RotationZYX(r) * e; // TODO: improve performance
98 }
99 
100 RotationZYX operator * ( RotationY const & r, RotationZYX const & e ) {
101  return RotationZYX(r) * e; // TODO: improve performance
102 }
103 
104 RotationZYX
105 operator * ( RotationZ const & r, RotationZYX const & e ) {
106  return RotationZYX(r) * e; // TODO: improve performance
107 }
108 
109 void RotationZYX::Rectify()
110 {
111  // rectify . The angle theta must be defined between [-PI/2,PI.2]
112  // same as Euler- Angles, just here Theta is shifted by PI/2 with respect to
113  // the theta of the EulerAngles class
114 
115  Scalar theta2 = fTheta + M_PI_2;
116  if ( theta2 < 0 || theta2 > Pi() ) {
117  Scalar t = theta2 - std::floor( theta2/(2*Pi() ) ) * 2*Pi();
118  if ( t <= Pi() ) {
119  theta2 = t;
120  } else {
121  theta2 = 2*Pi() - t;
122  fPhi = fPhi + Pi();
123  fPsi = fPsi + Pi();
124  }
125  // ftheta is shifted of PI/2 w.r.t theta2
126  fTheta = theta2 - M_PI_2;
127  }
128 
129  if ( fPhi <= -Pi()|| fPhi > Pi() ) {
130  fPhi = fPhi - std::floor( fPhi/(2*Pi()) +.5 ) * 2*Pi();
131  }
132 
133  if ( fPsi <= -Pi()|| fPsi > Pi() ) {
134  fPsi = fPsi - std::floor( fPsi/(2*Pi()) +.5 ) * 2*Pi();
135  }
136 
137 } // Rectify()
138 
139 void RotationZYX::Invert()
140 {
141  // invert this rotation.
142  // use Rotation3D. TO Do :have algorithm to invert it directly
143  Rotation3D r(*this);
144  //Quaternion r(*this);
145  r.Invert();
146  *this = r;
147 }
148 
149 // ========== I/O =====================
150 
151 std::ostream & operator<< (std::ostream & os, const RotationZYX & e) {
152  // TODO - this will need changing for machine-readable issues
153  // and even the human readable form may need formatiing improvements
154  os << "\n{phi(Z angle): " << e.Phi() << " theta(Y angle): " << e.Theta()
155  << " psi(X angle): " << e.Psi() << "}\n";
156  return os;
157 }
158 
159 
160 } //namespace Math
161 } //namespace ROOT