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
31namespace ROOT {
32
33namespace 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
50 // combine with a Rotation3D
51 return RotationZYX ( Rotation3D(*this) * r );
52}
53
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
96 return RotationZYX(r) * e; // TODO: improve performance
97}
98
100 return RotationZYX(r) * e; // TODO: improve performance
101}
102
103RotationZYX
104operator * ( 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
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
150std::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
#define M_PI_2
Definition: Math.h:40
#define e(i)
Definition: RSha256.hxx:103
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
float * q
Definition: THbookFile.cxx:89
AxisAngle class describing rotation represented with direction axis (3D Vector) and an angle of rotat...
Definition: AxisAngle.h:42
EulerAngles class describing rotation as three angles (Euler Angles).
Definition: EulerAngles.h:45
Rotation class with the (3D) rotation represented by a unit quaternion (u, i, j, k).
Definition: Quaternion.h:49
Rotation class with the (3D) rotation represented by a 3x3 orthogonal matrix.
Definition: Rotation3D.h:67
Rotation class representing a 3D rotation about the X axis by the angle of rotation.
Definition: RotationX.h:45
Rotation class representing a 3D rotation about the Y axis by the angle of rotation.
Definition: RotationY.h:45
Rotation class with the (3D) rotation represented by angles describing first a rotation of an angle p...
Definition: RotationZYX.h:63
static double Pi()
Definition: RotationZYX.h:321
RotationZYX()
Default constructor.
Definition: RotationZYX.h:75
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:256
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:45
RVec< PromoteType< T > > floor(const RVec< T > &v)
Definition: RVec.hxx:1773
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.
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.
auto * a
Definition: textangle.C:12