Logo ROOT   6.18/05
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
29
31
32namespace ROOT {
33
34namespace 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
51 // combine with a Rotation3D
52 return RotationZYX ( Rotation3D(*this) * r );
53}
54
56 // combine with a AxisAngle
57 return RotationZYX ( Quaternion(*this) * Quaternion(a) );
58}
59
61 // combine with EulerAngles
62 return RotationZYX ( Quaternion(*this) * Quaternion(e) );
63}
64
66 // combine with a RotationZYX
67 //return RotationZYX ( Quaternion(*this) * Quaternion(e) );
68 return RotationZYX ( Rotation3D(*this) * Rotation3D(e) );
69}
71 // combination with a Quaternion
72 return RotationZYX ( Quaternion(*this) * q );
73}
74
76 // combine with a RotationX
77 return RotationZYX ( Quaternion(*this) * r );
78}
79
81 // combine with a RotationY
82 return RotationZYX ( Quaternion(*this) * r );
83}
84
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
97 return RotationZYX(r) * e; // TODO: improve performance
98}
99
101 return RotationZYX(r) * e; // TODO: improve performance
102}
103
104RotationZYX
105operator * ( RotationZ const & r, RotationZYX const & e ) {
106 return RotationZYX(r) * e; // TODO: improve performance
107}
108
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
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
151std::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
#define M_PI_2
Definition: Math.h:40
ROOT::R::TRInterface & r
Definition: Object.C:4
#define e(i)
Definition: RSha256.hxx:103
float * q
Definition: THbookFile.cxx:87
double floor(double)
AxisAngle class describing rotation represented with direction axis (3D Vector) and an angle of rotat...
Definition: AxisAngle.h:41
EulerAngles class describing rotation as three angles (Euler Angles).
Definition: EulerAngles.h:43
Rotation class with the (3D) rotation represented by a unit quaternion (u, i, j, k).
Definition: Quaternion.h:47
Rotation class with the (3D) rotation represented by a 3x3 orthogonal matrix.
Definition: Rotation3D.h:65
Rotation class representing a 3D rotation about the X axis by the angle of rotation.
Definition: RotationX.h:43
Rotation class representing a 3D rotation about the Y axis by the angle of rotation.
Definition: RotationY.h:43
Rotation class with the (3D) rotation represented by angles describing first a rotation of an angle p...
Definition: RotationZYX.h:61
static double Pi()
Definition: RotationZYX.h:325
RotationZYX()
Default constructor.
Definition: RotationZYX.h:73
void Rectify()
Re-adjust components place angles in canonical ranges.
AVector operator*(const AVector &v) const
Overload operator * for rotation on a vector.
Definition: RotationZYX.h:260
void Invert()
Invert a rotation in place.
Rotation class representing a 3D rotation about the Z axis by the angle of rotation.
Definition: RotationZ.h:43
Namespace for new Math classes and functions.
std::ostream & operator<<(std::ostream &os, const AxisAngle &a)
Stream Output and Input.
Definition: AxisAngle.cxx:91
AxisAngle operator*(RotationX const &r1, AxisAngle const &r2)
Multiplication of an axial rotation by an AxisAngle.
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
auto * a
Definition: textangle.C:12