Logo ROOT  
Reference Guide
Loading...
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_MathX_GenVectorX_RotationY
18#define ROOT_MathX_GenVectorX_RotationY 1
19
25
27
29
31
32namespace ROOT {
33namespace ROOT_MATH_ARCH {
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 GenVectorX
41
42 @see GenVectorX
43*/
44
45class RotationY {
46
47public:
48 typedef double Scalar;
49
50 // ========== Constructors and Assignment =====================
51
52 /**
53 Default constructor (identity rotation)
54 */
55 RotationY() : fAngle(0), fSin(0), fCos(1) {}
56
57 /**
58 Construct from an angle
59 */
60 explicit RotationY(Scalar angle) : fAngle(angle), fSin(math_sin(angle)), fCos(math_cos(angle)) { Rectify(); }
61
62 // The compiler-generated copy ctor, copy assignment, and destructor are OK.
63
64 /**
65 Rectify makes sure the angle is in (-pi,pi]
66 */
67 void Rectify()
68 {
69 if (math_fabs(fAngle) >= M_PI) {
70 double x = fAngle / (2.0 * M_PI);
71 fAngle = (2.0 * M_PI) * (x + math_floor(.5 - x));
74 }
75 }
76
77 // ======== Components ==============
78
79 /**
80 Set given the angle.
81 */
82 void SetAngle(Scalar angle)
83 {
84 fSin = math_sin(angle);
85 fCos = math_cos(angle);
86 fAngle = angle;
87 Rectify();
88 }
89 void SetComponents(Scalar angle) { SetAngle(angle); }
90
91 /**
92 Get the angle
93 */
94 void GetAngle(Scalar &angle) const { angle = math_atan2(fSin, fCos); }
95 void GetComponents(Scalar &angle) const { GetAngle(angle); }
96
97 /**
98 Angle of rotation
99 */
100 Scalar Angle() const { return math_atan2(fSin, fCos); }
101
102 /**
103 Sine or Cosine of the rotation angle
104 */
105 Scalar SinAngle() const { return fSin; }
106 Scalar CosAngle() const { return fCos; }
107
108 // =========== operations ==============
109
110 // /**
111 // Rotation operation on a cartesian vector
112 // */
113 // typedef DisplacementVector3D< Cartesian3D<double> > XYZVector;
114 // XYZVector operator() (const XYZVector & v) const {
115 // return XYZVector
116 // ( fCos*v.x()+fSin*v.z(), v.y(), fCos*v.z()-fSin*v.x() );
117 // }
118
119 /**
120 Rotation operation on a displacement vector in any coordinate system
121 */
122 template <class CoordSystem, class U>
129
130 /**
131 Rotation operation on a position vector in any coordinate system
132 */
133 template <class CoordSystem, class U>
140
141 /**
142 Rotation operation on a Lorentz vector in any 4D coordinate system
143 */
144 template <class CoordSystem>
146 {
148 xyz = operator()(xyz);
149 LorentzVector<PxPyPzE4D<double>> xyzt(xyz.X(), xyz.Y(), xyz.Z(), v.E());
150 return LorentzVector<CoordSystem>(xyzt);
151 }
152
153 /**
154 Rotation operation on an arbitrary vector v.
155 Preconditions: v must implement methods x(), y(), and z()
156 and the arbitrary vector type must have a constructor taking (x,y,z)
157 */
158 template <class ForeignVector>
159 ForeignVector operator()(const ForeignVector &v) const
160 {
163 return ForeignVector(rxyz.X(), rxyz.Y(), rxyz.Z());
164 }
165
166 /**
167 Overload operator * for rotation on a vector
168 */
169 template <class AVector>
170 inline AVector operator*(const AVector &v) const
171 {
172 return operator()(v);
173 }
174
175 /**
176 Invert a rotation in place
177 */
178 void Invert()
179 {
180 fAngle = -fAngle;
181 fSin = -fSin;
182 }
183
184 /**
185 Return inverse of a rotation
186 */
188 {
189 RotationY t(*this);
190 t.Invert();
191 return t;
192 }
193
194 // ========= Multi-Rotation Operations ===============
195
196 /**
197 Multiply (combine) two rotations
198 */
200 {
201 RotationY ans;
202 double x = (fAngle + r.fAngle) / (2.0 * M_PI);
203 ans.fAngle = (2.0 * M_PI) * (x + math_floor(.5 - x));
204 ans.fSin = fSin * r.fCos + fCos * r.fSin;
205 ans.fCos = fCos * r.fCos - fSin * r.fSin;
206 return ans;
207 }
208
209 /**
210 Post-Multiply (on right) by another rotation : T = T*R
211 */
212 RotationY &operator*=(const RotationY &r) { return *this = (*this) * r; }
213
214 /**
215 Equality/inequality operators
216 */
217 bool operator==(const RotationY &rhs) const
218 {
219 if (fAngle != rhs.fAngle)
220 return false;
221 return true;
222 }
223 bool operator!=(const RotationY &rhs) const { return !operator==(rhs); }
224
225private:
226 Scalar fAngle; // rotation angle
227 Scalar fSin; // sine of the rotation angle
228 Scalar fCos; // cosine of the rotation angle
229
230}; // RotationY
231
232// ============ Class RotationY ends here ============
233
234/**
235 Distance between two rotations
236 */
237template <class R>
238inline typename RotationY::Scalar Distance(const RotationY &r1, const R &r2)
239{
240 return gv_detail::dist(r1, r2);
241}
242
243/**
244 Stream Output and Input
245 */
246// TODO - I/O should be put in the manipulator form
247
248#if !defined(ROOT_MATH_SYCL) && !defined(ROOT_MATH_CUDA)
249
250inline std::ostream &operator<<(std::ostream &os, const RotationY &r)
251{
252 os << " RotationY(" << r.Angle() << ") ";
253 return os;
254}
255#endif
256
257} // namespace ROOT_MATH_ARCH
258} // namespace ROOT
259
260#endif // ROOT_MathX_GenVectorX_RotationY
ROOT::R::TRInterface & r
Definition Object.C:4
#define M_PI
Definition Rotated.cxx:105
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.
Scalar Z() const
Cartesian Z, 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...
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 GetComponents(Scalar &angle) const
Definition RotationY.h:95
RotationY()
Default constructor (identity rotation).
Definition RotationY.h:55
RotationY(Scalar angle)
Construct from an angle.
Definition RotationY.h:60
ForeignVector operator()(const ForeignVector &v) const
Rotation operation on an arbitrary vector v.
Definition RotationY.h:159
DisplacementVector3D< CoordSystem, U > operator()(const DisplacementVector3D< CoordSystem, U > &v) const
Rotation operation on a cartesian vector.
Definition RotationY.h:123
RotationY Inverse() const
Return inverse of a rotation.
Definition RotationY.h:187
void SetAngle(Scalar angle)
Set given the angle.
Definition RotationY.h:82
bool operator==(const RotationY &rhs) const
Equality/inequality operators.
Definition RotationY.h:217
RotationY operator*(const RotationY &r) const
Multiply (combine) two rotations.
Definition RotationY.h:199
Scalar Angle() const
Angle of rotation.
Definition RotationY.h:100
void SetComponents(Scalar angle)
Definition RotationY.h:89
void Rectify()
Rectify makes sure the angle is in (-pi,pi].
Definition RotationY.h:67
void GetAngle(Scalar &angle) const
Get the angle.
Definition RotationY.h:94
LorentzVector< CoordSystem > operator()(const LorentzVector< CoordSystem > &v) const
Rotation operation on a Lorentz vector in any 4D coordinate system.
Definition RotationY.h:145
RotationY & operator*=(const RotationY &r)
Post-Multiply (on right) by another rotation : T = T*R.
Definition RotationY.h:212
void Invert()
Invert a rotation in place.
Definition RotationY.h:178
PositionVector3D< CoordSystem, U > operator()(const PositionVector3D< CoordSystem, U > &v) const
Rotation operation on a position vector in any coordinate system.
Definition RotationY.h:134
Scalar SinAngle() const
Sine or Cosine of the rotation angle.
Definition RotationY.h:105
AVector operator*(const AVector &v) const
Overload operator * for rotation on a vector.
Definition RotationY.h:170
bool operator!=(const RotationY &rhs) const
Definition RotationY.h:223
Double_t x[n]
Definition legend1.C:17
double dist(Rotation3D const &r1, Rotation3D const &r2)
Scalar math_floor(Scalar x)
Scalar math_cos(Scalar x)
AxisAngle::Scalar Distance(const AxisAngle &r1, const R &r2)
Distance between two rotations.
Definition AxisAngle.h:346
std::ostream & operator<<(std::ostream &os, const AxisAngle &a)
Stream Output and Input.
Definition AxisAngle.cxx:84
Scalar math_atan2(Scalar x, Scalar y)
Scalar math_fabs(Scalar x)
Scalar math_sin(Scalar x)
namespace associated R package for ROOT.
Definition RExports.h:72