Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 
38 void EulerAngles::Rectify()
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 
73 EulerAngles EulerAngles::operator * (const Rotation3D & r) const {
74  // combine with a Rotation3D
75  return EulerAngles ( Rotation3D(*this) * r );
76 }
77 
78 EulerAngles EulerAngles::operator * (const AxisAngle & a) const {
79  // combine with a AxisAngle
80  return EulerAngles ( Quaternion(*this) * Quaternion(a) );
81 }
82 
83 EulerAngles EulerAngles::operator * (const EulerAngles & e) const {
84  // combine with a EulerAngles
85  return EulerAngles ( Quaternion(*this) * Quaternion(e) );
86 }
87 EulerAngles EulerAngles::operator * (const Quaternion & q) const {
88  // combination with a Quaternion
89  return EulerAngles ( Quaternion(*this) * q );
90 }
91 
92 EulerAngles EulerAngles::operator * (const RotationX & r) const {
93  // combine with a RotationX
94  return EulerAngles ( Quaternion(*this) * r );
95 }
96 
97 EulerAngles EulerAngles::operator * (const RotationY & r) const {
98  // combine with a RotationY
99  return EulerAngles ( Quaternion(*this) * r );
100 }
101 
102 EulerAngles EulerAngles::operator * (const RotationZ & r) const {
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 
113 EulerAngles operator * ( RotationX const & r, EulerAngles const & e ) {
114  return EulerAngles(r) * e; // TODO: improve performance
115 }
116 
117 EulerAngles operator * ( RotationY const & r, EulerAngles const & e ) {
118  return EulerAngles(r) * e; // TODO: improve performance
119 }
120 
121 EulerAngles
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