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 <TMath.h>
30#include <cmath>
31
32namespace ROOT {
33namespace Math {
34
35
36//__________________________________________________________________________________________
37 /**
38 Rotation class representing a 3D rotation about the X axis by the angle of rotation.
39 For efficiency reason, in addition to the angle, the sine and cosine of the angle are held
40
41 @ingroup GenVector
42
43 @see GenVector
44 */
45
46class RotationX {
47
48public:
49
50 typedef double Scalar;
51
52
53 // ========== Constructors and Assignment =====================
54
55 /**
56 Default constructor (identity rotation)
57 */
58 RotationX() : fAngle(0), fSin(0), fCos(1) { }
59
60 /**
61 Construct from an angle
62 */
64 fSin(std::sin(angle)),
65 fCos(std::cos(angle))
66 {
67 Rectify();
68 }
69
70 // The compiler-generated copy ctor, copy assignment, and destructor are OK.
71
72 /**
73 Rectify makes sure the angle is in (-pi,pi]
74 */
75 void Rectify() {
76 if (std::fabs(fAngle) >= TMath::Pi()) {
77 double x = fAngle / TMath::TwoPi();
78 fAngle = TMath::TwoPi() * (x + std::floor(.5 - x));
79 fSin = std::sin(fAngle);
80 fCos = std::cos(fAngle);
81 }
82 }
83
84 // ======== Components ==============
85
86 /**
87 Set given the angle.
88 */
90 fSin=std::sin(angle);
91 fCos=std::cos(angle);
93 Rectify();
94 }
96
97 /**
98 Get the angle
99 */
100 void GetAngle(Scalar &angle) const { using std::atan2; angle = atan2(fSin, fCos); }
101 void GetComponents ( Scalar & angle ) const { GetAngle(angle); }
102
103 /**
104 Angle of rotation
105 */
106 Scalar Angle() const { using std::atan2; return atan2(fSin, fCos); }
107
108 /**
109 Sine or Cosine of the rotation angle
110 */
111 Scalar SinAngle () const { return fSin; }
112 Scalar CosAngle () const { return fCos; }
113
114 // =========== operations ==============
115
116 /**
117 Rotation operation on a cartesian vector
118 */
119// typedef DisplacementVector3D< Cartesian3D<double> > XYZVector;
120// XYZVector operator() (const XYZVector & v) const {
121// return XYZVector ( v.x(), fCos*v.y()-fSin*v.z(), fCos*v.z()+fSin*v.y() );
122// }
123
124
125 /**
126 Rotation operation on a displacement vector in any coordinate system
127 */
128 template <class CoordSystem, class U>
132 xyz.SetXYZ( v.X(), fCos*v.Y()-fSin*v.Z(), fCos*v.Z()+fSin*v.Y() );
134 }
135
136 /**
137 Rotation operation on a position vector in any coordinate system
138 */
139 template <class CoordSystem, class U>
146
147 /**
148 Rotation operation on a Lorentz vector in any 4D coordinate system
149 */
150 template <class CoordSystem>
154 xyz = operator()(xyz);
155 LorentzVector< PxPyPzE4D<double> > xyzt (xyz.X(), xyz.Y(), xyz.Z(), v.E());
156 return LorentzVector<CoordSystem> ( xyzt );
157 }
158
159 /**
160 Rotation operation on an arbitrary vector v.
161 Preconditions: v must implement methods x(), y(), and z()
162 and the arbitrary vector type must have a constructor taking (x,y,z). GenVector coordinate systems whose
163 constructors take other coordinates use SetXYZ() instead.
164 */
165 template <class ForeignVector>
166 ForeignVector
167 operator() (const ForeignVector & v) const {
170 return Impl::MakeFromXYZ<ForeignVector>(rxyz.X(), rxyz.Y(), rxyz.Z());
171 }
172
173 /**
174 Overload operator * for rotation on a vector
175 */
176 template <class AVector>
177 inline
178 AVector operator* (const AVector & v) const
179 {
180 return operator()(v);
181 }
182
183 /**
184 Invert a rotation in place
185 */
186 void Invert() { fAngle = -fAngle; fSin = -fSin; }
187
188 /**
189 Return inverse of a rotation
190 */
191 RotationX Inverse() const { RotationX t(*this); t.Invert(); return t; }
192
193 // ========= Multi-Rotation Operations ===============
194
195 /**
196 Multiply (combine) two rotations
197 */
199 RotationX ans;
200 double x = (fAngle + r.fAngle) / TMath::TwoPi();
201 ans.fAngle = TMath::TwoPi() * (x + std::floor(.5 - x));
202 ans.fSin = fSin*r.fCos + fCos*r.fSin;
203 ans.fCos = fCos*r.fCos - fSin*r.fSin;
204 return ans;
205 }
206
207 /**
208 Post-Multiply (on right) by another rotation : T = T*R
209 */
210 RotationX & operator *= (const RotationX & r) { return *this = (*this)*r; }
211
212 /**
213 Equality/inequality operators
214 */
215 bool operator == (const RotationX & rhs) const {
216 if( fAngle != rhs.fAngle ) return false;
217 return true;
218 }
219 bool operator != (const RotationX & rhs) const {
220 return ! operator==(rhs);
221 }
222
223private:
224
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
238typename RotationX::Scalar
239Distance ( const RotationX& r1, const R & r2) {return gv_detail::dist(r1,r2);}
240
241/**
242 Stream Output and Input
243 */
244 // TODO - I/O should be put in the manipulator form
245
246inline
247std::ostream & operator<< (std::ostream & os, const RotationX & r) {
248 os << " RotationX(" << r.Angle() << ") ";
249 return os;
250}
251
252
253} // namespace Math
254} // namespace ROOT
255
256#endif // ROOT_Math_GenVector_RotationX
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:46
Scalar CosAngle() const
Definition RotationX.h:112
AVector operator*(const AVector &v) const
Overload operator * for rotation on a vector.
Definition RotationX.h:178
RotationX & operator*=(const RotationX &r)
Post-Multiply (on right) by another rotation : T = T*R.
Definition RotationX.h:210
void GetAngle(Scalar &angle) const
Get the angle.
Definition RotationX.h:100
void SetAngle(Scalar angle)
Set given the angle.
Definition RotationX.h:89
void GetComponents(Scalar &angle) const
Definition RotationX.h:101
void Invert()
Invert a rotation in place.
Definition RotationX.h:186
RotationX Inverse() const
Return inverse of a rotation.
Definition RotationX.h:191
RotationX(Scalar angle)
Construct from an angle.
Definition RotationX.h:63
DisplacementVector3D< CoordSystem, U > operator()(const DisplacementVector3D< CoordSystem, U > &v) const
Rotation operation on a cartesian vector.
Definition RotationX.h:130
bool operator!=(const RotationX &rhs) const
Definition RotationX.h:219
Scalar SinAngle() const
Sine or Cosine of the rotation angle.
Definition RotationX.h:111
bool operator==(const RotationX &rhs) const
Equality/inequality operators.
Definition RotationX.h:215
Scalar Angle() const
Angle of rotation.
Definition RotationX.h:106
void SetComponents(Scalar angle)
Definition RotationX.h:95
RotationX()
Default constructor (identity rotation)
Definition RotationX.h:58
void Rectify()
Rectify makes sure the angle is in (-pi,pi].
Definition RotationX.h:75
Double_t x[n]
Definition legend1.C:17
Namespace for new Math classes and functions.
double dist(Rotation3D const &r1, Rotation3D const &r2)
std::ostream & operator<<(std::ostream &os, const AxisAngle &a)
Stream Output and Input.
Definition AxisAngle.cxx:81
AxisAngle::Scalar Distance(const AxisAngle &r1, const R &r2)
Distance between two rotations.
Definition AxisAngle.h:321
constexpr Double_t Pi()
Definition TMath.h:40
constexpr Double_t TwoPi()
Definition TMath.h:47