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_MathX_GenVectorX_RotationX
18#define ROOT_MathX_GenVectorX_RotationX 1
19
25
27
29
31
32namespace ROOT {
33namespace ROOT_MATH_ARCH {
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 GenVectorX
41
42 @see GenVectorX
43*/
44
45class RotationX {
46
47public:
48 typedef double Scalar;
49
50 // ========== Constructors and Assignment =====================
51
52 /**
53 Default constructor (identity rotation)
54 */
55 RotationX() : fAngle(0), fSin(0), fCos(1) {}
56
57 /**
58 Construct from an angle
59 */
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 */
83 {
86 fAngle = angle;
87 Rectify();
88 }
90
91 /**
92 Get the angle
93 */
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 ( v.x(), fCos*v.y()-fSin*v.z(), fCos*v.z()+fSin*v.y() );
116 // }
117
118 /**
119 Rotation operation on a displacement vector in any coordinate system
120 */
121 template <class CoordSystem, class U>
123 {
125 xyz.SetXYZ(v.X(), fCos * v.Y() - fSin * v.Z(), fCos * v.Z() + fSin * v.Y());
127 }
128
129 /**
130 Rotation operation on a position vector in any coordinate system
131 */
132 template <class CoordSystem, class U>
139
140 /**
141 Rotation operation on a Lorentz vector in any 4D coordinate system
142 */
143 template <class CoordSystem>
145 {
147 xyz = operator()(xyz);
148 LorentzVector<PxPyPzE4D<double>> xyzt(xyz.X(), xyz.Y(), xyz.Z(), v.E());
150 }
151
152 /**
153 Rotation operation on an arbitrary vector v.
154 Preconditions: v must implement methods x(), y(), and z()
155 and the arbitrary vector type must have a constructor taking (x,y,z)
156 */
157 template <class ForeignVector>
164
165 /**
166 Overload operator * for rotation on a vector
167 */
168 template <class AVector>
169 inline AVector operator*(const AVector &v) const
170 {
171 return operator()(v);
172 }
173
174 /**
175 Invert a rotation in place
176 */
177 void Invert()
178 {
179 fAngle = -fAngle;
180 fSin = -fSin;
181 }
182
183 /**
184 Return inverse of a rotation
185 */
187 {
188 RotationX t(*this);
189 t.Invert();
190 return t;
191 }
192
193 // ========= Multi-Rotation Operations ===============
194
195 /**
196 Multiply (combine) two rotations
197 */
199 {
201 double x = (fAngle + r.fAngle) / (2.0 * M_PI);
202 ans.fAngle = (2.0 * M_PI) * (x + math_floor(.5 - x));
203 ans.fSin = fSin * r.fCos + fCos * r.fSin;
204 ans.fCos = fCos * r.fCos - fSin * r.fSin;
205 return ans;
206 }
207
208 /**
209 Post-Multiply (on right) by another rotation : T = T*R
210 */
211 RotationX &operator*=(const RotationX &r) { return *this = (*this) * r; }
212
213 /**
214 Equality/inequality operators
215 */
216 bool operator==(const RotationX &rhs) const
217 {
218 if (fAngle != rhs.fAngle)
219 return false;
220 return true;
221 }
222 bool operator!=(const RotationX &rhs) const { return !operator==(rhs); }
223
224private:
225 Scalar fAngle; // rotation angle
226 Scalar fSin; // sine of the rotation angle
227 Scalar fCos; // cosine of the rotation angle
228
229}; // RotationX
230
231// ============ Class RotationX ends here ============
232
233/**
234 Distance between two rotations
235 */
236template <class R>
237inline typename RotationX::Scalar Distance(const RotationX &r1, const R &r2)
238{
239 return gv_detail::dist(r1, r2);
240}
241
242#if !defined(ROOT_MATH_SYCL) && !defined(ROOT_MATH_CUDA)
243
244/**
245 Stream Output and Input
246 */
247// TODO - I/O should be put in the manipulator form
248
249inline std::ostream &operator<<(std::ostream &os, const RotationX &r)
250{
251 os << " RotationX(" << r.Angle() << ") ";
252 return os;
253}
254
255#endif
256
257} // namespace ROOT_MATH_ARCH
258} // namespace ROOT
259
260#endif // ROOT_MathX_GenVectorX_RotationX
#define M_PI
Definition Rotated.cxx:105
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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
Rotation class representing a 3D rotation about the X axis by the angle of rotation.
Definition RotationX.h:45
bool operator==(const RotationX &rhs) const
Equality/inequality operators.
Definition RotationX.h:216
void Rectify()
Rectify makes sure the angle is in (-pi,pi].
Definition RotationX.h:67
void SetAngle(Scalar angle)
Set given the angle.
Definition RotationX.h:82
RotationX(Scalar angle)
Construct from an angle.
Definition RotationX.h:60
Scalar SinAngle() const
Sine or Cosine of the rotation angle.
Definition RotationX.h:105
RotationX & operator*=(const RotationX &r)
Post-Multiply (on right) by another rotation : T = T*R.
Definition RotationX.h:211
LorentzVector< CoordSystem > operator()(const LorentzVector< CoordSystem > &v) const
Rotation operation on a Lorentz vector in any 4D coordinate system.
Definition RotationX.h:144
void GetComponents(Scalar &angle) const
Definition RotationX.h:95
void GetAngle(Scalar &angle) const
Get the angle.
Definition RotationX.h:94
RotationX operator*(const RotationX &r) const
Multiply (combine) two rotations.
Definition RotationX.h:198
ForeignVector operator()(const ForeignVector &v) const
Rotation operation on an arbitrary vector v.
Definition RotationX.h:158
bool operator!=(const RotationX &rhs) const
Definition RotationX.h:222
DisplacementVector3D< CoordSystem, U > operator()(const DisplacementVector3D< CoordSystem, U > &v) const
Rotation operation on a cartesian vector.
Definition RotationX.h:122
PositionVector3D< CoordSystem, U > operator()(const PositionVector3D< CoordSystem, U > &v) const
Rotation operation on a position vector in any coordinate system.
Definition RotationX.h:133
void Invert()
Invert a rotation in place.
Definition RotationX.h:177
void SetComponents(Scalar angle)
Definition RotationX.h:89
AVector operator*(const AVector &v) const
Overload operator * for rotation on a vector.
Definition RotationX.h:169
RotationX()
Default constructor (identity rotation)
Definition RotationX.h:55
Scalar Angle() const
Angle of rotation.
Definition RotationX.h:100
RotationX Inverse() const
Return inverse of a rotation.
Definition RotationX.h:186
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:98
Scalar math_atan2(Scalar x, Scalar y)
Scalar math_fabs(Scalar x)
Scalar math_sin(Scalar x)