Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RotationX.h
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// Header file for class RotationZ representing a rotation about the Z axis
12//
13// Created by: Mark Fischler Mon July 18 2005
14//
15// Last update: $Id$
16//
17#ifndef ROOT_Math_GenVector_RotationX
18#define ROOT_Math_GenVector_RotationX 1
19
20
26
28
29#include <cmath>
30
31namespace ROOT {
32namespace Math {
33
34
35//__________________________________________________________________________________________
36 /**
37 Rotation class representing a 3D rotation about the X axis by the angle of rotation.
38 For efficiency reason, in addition to the angle, the sine and cosine of the angle are held
39
40 @ingroup GenVector
41
42 @sa Overview of the @ref GenVector "physics vector library"
43 */
44
45class RotationX {
46
47public:
48
49 typedef double Scalar;
50
51
52 // ========== Constructors and Assignment =====================
53
54 /**
55 Default constructor (identity rotation)
56 */
57 RotationX() : fAngle(0), fSin(0), fCos(1) { }
58
59 /**
60 Construct from an angle
61 */
63 fSin(std::sin(angle)),
64 fCos(std::cos(angle))
65 {
66 Rectify();
67 }
68
69 // The compiler-generated copy ctor, copy assignment, and destructor are OK.
70
71 /**
72 Rectify makes sure the angle is in (-pi,pi]
73 */
74 void Rectify() {
75 if ( std::fabs(fAngle) >= M_PI ) {
76 double x = fAngle / (2.0 * M_PI);
77 fAngle = (2.0 * M_PI) * ( x + std::floor(.5-x) );
78 fSin = std::sin(fAngle);
79 fCos = std::cos(fAngle);
80 }
81 }
82
83 // ======== Components ==============
84
85 /**
86 Set given the angle.
87 */
89 fSin=std::sin(angle);
90 fCos=std::cos(angle);
92 Rectify();
93 }
95
96 /**
97 Get the angle
98 */
99 void GetAngle(Scalar &angle) const { using std::atan2; angle = atan2(fSin, fCos); }
100 void GetComponents ( Scalar & angle ) const { GetAngle(angle); }
101
102 /**
103 Angle of rotation
104 */
105 Scalar Angle() const { using std::atan2; return atan2(fSin, fCos); }
106
107 /**
108 Sine or Cosine of the rotation angle
109 */
110 Scalar SinAngle () const { return fSin; }
111 Scalar CosAngle () const { return fCos; }
112
113 // =========== operations ==============
114
115 /**
116 Rotation operation on a cartesian vector
117 */
118// typedef DisplacementVector3D< Cartesian3D<double> > XYZVector;
119// XYZVector operator() (const XYZVector & v) const {
120// return XYZVector ( v.x(), fCos*v.y()-fSin*v.z(), fCos*v.z()+fSin*v.y() );
121// }
122
123
124 /**
125 Rotation operation on a displacement vector in any coordinate system
126 */
127 template <class CoordSystem, class U>
131 xyz.SetXYZ( v.X(), fCos*v.Y()-fSin*v.Z(), fCos*v.Z()+fSin*v.Y() );
133 }
134
135 /**
136 Rotation operation on a position vector in any coordinate system
137 */
138 template <class CoordSystem, class U>
143 return PositionVector3D<CoordSystem,U> ( rxyz );
144 }
145
146 /**
147 Rotation operation on a Lorentz vector in any 4D coordinate system
148 */
149 template <class CoordSystem>
153 xyz = operator()(xyz);
154 LorentzVector< PxPyPzE4D<double> > xyzt (xyz.X(), xyz.Y(), xyz.Z(), v.E());
155 return LorentzVector<CoordSystem> ( xyzt );
156 }
157
158 /**
159 Rotation operation on an arbitrary vector v.
160 Preconditions: v must implement methods x(), y(), and z()
161 and the arbitrary vector type must have a constructor taking (x,y,z)
162 */
163 template <class ForeignVector>
164 ForeignVector
165 operator() (const ForeignVector & v) const {
168 return ForeignVector ( rxyz.X(), rxyz.Y(), rxyz.Z() );
169 }
170
171 /**
172 Overload operator * for rotation on a vector
173 */
174 template <class AVector>
175 inline
176 AVector operator* (const AVector & v) const
177 {
178 return operator()(v);
179 }
180
181 /**
182 Invert a rotation in place
183 */
184 void Invert() { fAngle = -fAngle; fSin = -fSin; }
185
186 /**
187 Return inverse of a rotation
188 */
189 RotationX Inverse() const { RotationX t(*this); t.Invert(); return t; }
190
191 // ========= Multi-Rotation Operations ===============
192
193 /**
194 Multiply (combine) two rotations
195 */
197 RotationX ans;
198 double x = (fAngle + r.fAngle) / (2.0 * M_PI);
199 ans.fAngle = (2.0 * M_PI) * ( x + std::floor(.5-x) );
200 ans.fSin = fSin*r.fCos + fCos*r.fSin;
201 ans.fCos = fCos*r.fCos - fSin*r.fSin;
202 return ans;
203 }
204
205 /**
206 Post-Multiply (on right) by another rotation : T = T*R
207 */
208 RotationX & operator *= (const RotationX & r) { return *this = (*this)*r; }
209
210 /**
211 Equality/inequality operators
212 */
213 bool operator == (const RotationX & rhs) const {
214 if( fAngle != rhs.fAngle ) return false;
215 return true;
216 }
217 bool operator != (const RotationX & rhs) const {
218 return ! operator==(rhs);
219 }
220
221private:
222
223 Scalar fAngle; // rotation angle
224 Scalar fSin; // sine of the rotation angle
225 Scalar fCos; // cosine of the rotation angle
226
227}; // RotationX
228
229// ============ Class RotationX ends here ============
230
231/**
232 Distance between two rotations
233 */
234template <class R>
235inline
236typename RotationX::Scalar
237Distance ( const RotationX& r1, const R & r2) {return gv_detail::dist(r1,r2);}
238
239/**
240 Stream Output and Input
241 */
242 // TODO - I/O should be put in the manipulator form
243
244inline
245std::ostream & operator<< (std::ostream & os, const RotationX & r) {
246 os << " RotationX(" << r.Angle() << ") ";
247 return os;
248}
249
250
251} // namespace Math
252} // namespace ROOT
253
254#endif // ROOT_Math_GenVector_RotationX
#define M_PI
Definition Rotated.cxx:105
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
Option_t Option_t TPoint TPoint angle
Class describing a generic displacement vector in 3 dimensions.
Scalar X() const
Cartesian X, converting if necessary from internal coordinate system.
Scalar Y() const
Cartesian Y, converting if necessary from internal coordinate system.
DisplacementVector3D< CoordSystem, Tag > & SetXYZ(Scalar a, Scalar b, Scalar c)
set the values of the vector from the cartesian components (x,y,z) (if the vector is held in polar or...
Scalar Z() const
Cartesian Z, converting if necessary from internal coordinate system.
Class describing a generic LorentzVector in the 4D space-time, using the specified coordinate system ...
Class describing a generic position vector (point) in 3 dimensions.
Rotation class representing a 3D rotation about the X axis by the angle of rotation.
Definition RotationX.h:45
Scalar CosAngle() const
Definition RotationX.h:111
AVector operator*(const AVector &v) const
Overload operator * for rotation on a vector.
Definition RotationX.h:176
RotationX & operator*=(const RotationX &r)
Post-Multiply (on right) by another rotation : T = T*R.
Definition RotationX.h:208
void GetAngle(Scalar &angle) const
Get the angle.
Definition RotationX.h:99
void SetAngle(Scalar angle)
Set given the angle.
Definition RotationX.h:88
void GetComponents(Scalar &angle) const
Definition RotationX.h:100
void Invert()
Invert a rotation in place.
Definition RotationX.h:184
RotationX Inverse() const
Return inverse of a rotation.
Definition RotationX.h:189
RotationX(Scalar angle)
Construct from an angle.
Definition RotationX.h:62
DisplacementVector3D< CoordSystem, U > operator()(const DisplacementVector3D< CoordSystem, U > &v) const
Rotation operation on a cartesian vector.
Definition RotationX.h:129
bool operator!=(const RotationX &rhs) const
Definition RotationX.h:217
Scalar SinAngle() const
Sine or Cosine of the rotation angle.
Definition RotationX.h:110
bool operator==(const RotationX &rhs) const
Equality/inequality operators.
Definition RotationX.h:213
Scalar Angle() const
Angle of rotation.
Definition RotationX.h:105
void SetComponents(Scalar angle)
Definition RotationX.h:94
RotationX()
Default constructor (identity rotation)
Definition RotationX.h:57
void Rectify()
Rectify makes sure the angle is in (-pi,pi].
Definition RotationX.h:74
Double_t x[n]
Definition legend1.C:17
Namespace for new Math classes and functions.
double dist(Rotation3D const &r1, Rotation3D const &r2)
AxisAngle::Scalar Distance(const AxisAngle &r1, const R &r2)
Distance between two rotations.
Definition AxisAngle.h:321
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...