Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RotationZ.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_RotationZ
18#define ROOT_Math_GenVector_RotationZ 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 Z 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 RotationZ {
46
47public:
48
49 typedef double Scalar;
50
51
52 // ========== Constructors and Assignment =====================
53
54 /**
55 Default constructor (identity rotation)
56 */
57 RotationZ() : 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
121// ( fCos*v.x()-fSin*v.y(), fCos*v.y()+fSin*v.x(), v.z() );
122// }
123
124 /**
125 Rotation operation on a displacement vector in any coordinate system
126 */
127 template <class CoordSystem, class U>
131 xyz.SetXYZ( fCos*v.x()-fSin*v.y(), fCos*v.y()+fSin*v.x(), v.z() );
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 RotationZ Inverse() const { RotationZ t(*this); t.Invert(); return t; }
190
191 // ========= Multi-Rotation Operations ===============
192
193 /**
194 Multiply (combine) two rotations
195 */
197 RotationZ 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 RotationZ & operator *= (const RotationZ & r) { return *this = (*this)*r; }
209
210 /**
211 Equality/inequality operators
212 */
213 bool operator == (const RotationZ & rhs) const {
214 if( fAngle != rhs.fAngle ) return false;
215 return true;
216 }
217 bool operator != (const RotationZ & 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}; // RotationZ
228
229// ============ Class RotationZ ends here ============
230
231/**
232 Distance between two rotations
233 */
234template <class R>
235inline
236typename RotationZ::Scalar
237Distance ( const RotationZ& 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 RotationZ & r) {
246 os << " RotationZ(" << r.Angle() << ") ";
247 return os;
248}
249
250
251} // namespace Math
252} // namespace ROOT
253
254#endif // ROOT_Math_GenVector_RotationZ
#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 Z axis by the angle of rotation.
Definition RotationZ.h:45
Scalar CosAngle() const
Definition RotationZ.h:111
bool operator==(const RotationZ &rhs) const
Equality/inequality operators.
Definition RotationZ.h:213
RotationZ & operator*=(const RotationZ &r)
Post-Multiply (on right) by another rotation : T = T*R.
Definition RotationZ.h:208
RotationZ(Scalar angle)
Construct from an angle.
Definition RotationZ.h:62
RotationZ Inverse() const
Return inverse of a rotation.
Definition RotationZ.h:189
bool operator!=(const RotationZ &rhs) const
Definition RotationZ.h:217
void SetAngle(Scalar angle)
Set given the angle.
Definition RotationZ.h:88
void Rectify()
Rectify makes sure the angle is in (-pi,pi].
Definition RotationZ.h:74
DisplacementVector3D< CoordSystem, U > operator()(const DisplacementVector3D< CoordSystem, U > &v) const
Rotation operation on a displacement vector in any coordinate system.
Definition RotationZ.h:129
RotationZ()
Default constructor (identity rotation)
Definition RotationZ.h:57
AVector operator*(const AVector &v) const
Overload operator * for rotation on a vector.
Definition RotationZ.h:176
Scalar Angle() const
Angle of rotation.
Definition RotationZ.h:105
void Invert()
Invert a rotation in place.
Definition RotationZ.h:184
void GetComponents(Scalar &angle) const
Definition RotationZ.h:100
void GetAngle(Scalar &angle) const
Get the angle.
Definition RotationZ.h:99
void SetComponents(Scalar angle)
Definition RotationZ.h:94
Scalar SinAngle() const
Sine or Cosine of the rotation angle.
Definition RotationZ.h:110
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...