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