Logo ROOT   6.10/09
Reference Guide
EulerAngles.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 EulerAngles
12 //
13 // Created by: Mark Fischler Thurs June 9 2005
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 
39 {
40  // rectify
41  if ( fTheta < 0 || fTheta > Pi() ) {
42  Scalar t = fTheta - std::floor( fTheta/(2*Pi()) ) * 2*Pi();
43  if ( t <= Pi() ) {
44  fTheta = t;
45  } else {
46  fTheta = 2*Pi() - t;
47  fPhi = fPhi + Pi();
48  fPsi = fPsi + Pi();
49  }
50  }
51 
52  if ( fPhi <= -Pi()|| fPhi > Pi() ) {
53  fPhi = fPhi - std::floor( fPhi/(2*Pi()) +.5 ) * 2*Pi();
54  }
55 
56  if ( fPsi <= -Pi()|| fPsi > Pi() ) {
57  fPsi = fPsi - std::floor( fPsi/(2*Pi()) +.5 ) * 2*Pi();
58  }
59 
60 } // Rectify()
61 
62 
63 // ========== Operations =====================
64 
65 // DisplacementVector3D< Cartesian3D<double> >
66 // EulerAngles::
67 // operator() (const DisplacementVector3D< Cartesian3D<double> > & v) const
68 // {
69 // return Rotation3D(*this)(v);
70 // }
71 
72 
74  // combine with a Rotation3D
75  return EulerAngles ( Rotation3D(*this) * r );
76 }
77 
79  // combine with a AxisAngle
80  return EulerAngles ( Quaternion(*this) * Quaternion(a) );
81 }
82 
84  // combine with a EulerAngles
85  return EulerAngles ( Quaternion(*this) * Quaternion(e) );
86 }
88  // combination with a Quaternion
89  return EulerAngles ( Quaternion(*this) * q );
90 }
91 
93  // combine with a RotationX
94  return EulerAngles ( Quaternion(*this) * r );
95 }
96 
98  // combine with a RotationY
99  return EulerAngles ( Quaternion(*this) * r );
100 }
101 
103  // combine with a RotationZ
104  // TODO -- this can be made much faster because it merely adds
105  // the r.Angle() to phi.
106  Scalar newPhi = fPhi + r.Angle();
107  if ( newPhi <= -Pi()|| newPhi > Pi() ) {
108  newPhi = newPhi - std::floor( newPhi/(2*Pi()) +.5 ) * 2*Pi();
109  }
110  return EulerAngles ( newPhi, fTheta, fPsi );
111 }
112 
114  return EulerAngles(r) * e; // TODO: improve performance
115 }
116 
118  return EulerAngles(r) * e; // TODO: improve performance
119 }
120 
122 operator * ( RotationZ const & r, EulerAngles const & e ) {
123  return EulerAngles(r) * e; // TODO: improve performance
124 }
125 
126 // ========== I/O =====================
127 
128 std::ostream & operator<< (std::ostream & os, const EulerAngles & e) {
129  // TODO - this will need changing for machine-readable issues
130  // and even the human readable form may need formatiing improvements
131  os << "\n{phi: " << e.Phi() << " theta: " << e.Theta()
132  << " psi: " << e.Psi() << "}\n";
133  return os;
134 }
135 
136 
137 } //namespace Math
138 } //namespace ROOT
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
Rotation class representing a 3D rotation about the Z axis by the angle of rotation.
Definition: RotationZ.h:43
void Rectify()
Re-adjust components place angles in canonical ranges.
Definition: EulerAngles.cxx:38
TArc * a
Definition: textangle.C:12
Rotation class with the (3D) rotation represented by a unit quaternion (u, i, j, k).
Definition: Quaternion.h:47
Scalar Phi() const
Return Phi Euler angle.
Definition: EulerAngles.h:212
std::ostream & operator<<(std::ostream &os, const AxisAngle &a)
Stream Output and Input.
Definition: AxisAngle.cxx:91
AxisAngle class describing rotation represented with direction axis (3D Vector) and an angle of rotat...
Definition: AxisAngle.h:41
Scalar Psi() const
Return Psi Euler angle.
Definition: EulerAngles.h:232
Rotation class representing a 3D rotation about the Y axis by the angle of rotation.
Definition: RotationY.h:43
Scalar Theta() const
Return Theta Euler angle.
Definition: EulerAngles.h:222
TRandom2 r(17)
Rotation class representing a 3D rotation about the X axis by the angle of rotation.
Definition: RotationX.h:43
Rotation class with the (3D) rotation represented by a 3x3 orthogonal matrix.
Definition: Rotation3D.h:65
double floor(double)
EulerAngles()
Default constructor.
Definition: EulerAngles.h:52
EulerAngles class describing rotation as three angles (Euler Angles).
Definition: EulerAngles.h:43
you should not use this method at all Int_t Int_t Double_t Double_t Double_t e
Definition: TRolke.cxx:630
Namespace for new Math classes and functions.
AVector operator*(const AVector &v) const
Overload operator * for rotation on a vector.
Definition: EulerAngles.h:287
Scalar Angle() const
Angle of rotation.
Definition: RotationZ.h:103
float * q
Definition: THbookFile.cxx:87
static double Pi()
Definition: EulerAngles.h:352