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_Math_GenVector_RotationY
18#define ROOT_Math_GenVector_RotationY 1
19
20
26
28
29#include <cmath>
30#include <TMath.h>
31
32namespace ROOT {
33namespace Math {
34
35
36//__________________________________________________________________________________________
37 /**
38 Rotation class representing a 3D rotation about the Y 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 RotationY {
47
48public:
49
50 typedef double Scalar;
51
52
53 // ========== Constructors and Assignment =====================
54
55 /**
56 Default constructor (identity rotation)
57 */
58 RotationY() : 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
122// ( fCos*v.x()+fSin*v.z(), v.y(), fCos*v.z()-fSin*v.x() );
123// }
124
125 /**
126 Rotation operation on a displacement vector in any coordinate system
127 */
128 template <class CoordSystem, class U>
132 xyz.SetXYZ( fCos*v.x()+fSin*v.z(), v.y(), fCos*v.z()-fSin*v.x() );
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());
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)
163 */
164 template <class ForeignVector>
171
172 /**
173 Overload operator * for rotation on a vector
174 */
175 template <class AVector>
176 inline
178 {
179 return operator()(v);
180 }
181
182 /**
183 Invert a rotation in place
184 */
185 void Invert() { fAngle = -fAngle; fSin = -fSin; }
186
187 /**
188 Return inverse of a rotation
189 */
190 RotationY Inverse() const { RotationY t(*this); t.Invert(); return t; }
191
192 // ========= Multi-Rotation Operations ===============
193
194 /**
195 Multiply (combine) two rotations
196 */
199 double x = (fAngle + r.fAngle) / TMath::TwoPi();
200 ans.fAngle = TMath::TwoPi() * (x + std::floor(.5 - x));
201 ans.fSin = fSin*r.fCos + fCos*r.fSin;
202 ans.fCos = fCos*r.fCos - fSin*r.fSin;
203 return ans;
204 }
205
206 /**
207 Post-Multiply (on right) by another rotation : T = T*R
208 */
209 RotationY & operator *= (const RotationY & r) { return *this = (*this)*r; }
210
211 /**
212 Equality/inequality operators
213 */
214 bool operator == (const RotationY & rhs) const {
215 if( fAngle != rhs.fAngle ) return false;
216 return true;
217 }
218 bool operator != (const RotationY & rhs) const {
219 return ! operator==(rhs);
220 }
221
222private:
223
224 Scalar fAngle; // rotation angle
225 Scalar fSin; // sine of the rotation angle
226 Scalar fCos; // cosine of the rotation angle
227
228}; // RotationY
229
230// ============ Class RotationY ends here ============
231
232/**
233 Distance between two rotations
234 */
235template <class R>
236inline
237typename RotationY::Scalar
238Distance ( const RotationY& r1, const R & r2) {return gv_detail::dist(r1,r2);}
239
240/**
241 Stream Output and Input
242 */
243 // TODO - I/O should be put in the manipulator form
244
245inline
246std::ostream & operator<< (std::ostream & os, const RotationY & r) {
247 os << " RotationY(" << r.Angle() << ") ";
248 return os;
249}
250
251
252} // namespace Math
253} // namespace ROOT
254
255#endif // ROOT_Math_GenVector_RotationY
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 Y axis by the angle of rotation.
Definition RotationY.h:46
void SetComponents(Scalar angle)
Definition RotationY.h:95
void GetComponents(Scalar &angle) const
Definition RotationY.h:101
RotationY & operator*=(const RotationY &r)
Post-Multiply (on right) by another rotation : T = T*R.
Definition RotationY.h:209
void SetAngle(Scalar angle)
Set given the angle.
Definition RotationY.h:89
void GetAngle(Scalar &angle) const
Get the angle.
Definition RotationY.h:100
Scalar Angle() const
Angle of rotation.
Definition RotationY.h:106
void Invert()
Invert a rotation in place.
Definition RotationY.h:185
RotationY()
Default constructor (identity rotation)
Definition RotationY.h:58
Scalar CosAngle() const
Definition RotationY.h:112
AVector operator*(const AVector &v) const
Overload operator * for rotation on a vector.
Definition RotationY.h:177
DisplacementVector3D< CoordSystem, U > operator()(const DisplacementVector3D< CoordSystem, U > &v) const
Rotation operation on a displacement vector in any coordinate system.
Definition RotationY.h:130
RotationY(Scalar angle)
Construct from an angle.
Definition RotationY.h:63
RotationY Inverse() const
Return inverse of a rotation.
Definition RotationY.h:190
Scalar SinAngle() const
Sine or Cosine of the rotation angle.
Definition RotationY.h:111
void Rectify()
Rectify makes sure the angle is in (-pi,pi].
Definition RotationY.h:75
bool operator==(const RotationY &rhs) const
Equality/inequality operators.
Definition RotationY.h:214
bool operator!=(const RotationY &rhs) const
Definition RotationY.h:218
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:91
AxisAngle::Scalar Distance(const AxisAngle &r1, const R &r2)
Distance between two rotations.
Definition AxisAngle.h:321
Namespace for new ROOT classes and functions.
constexpr Double_t Pi()
Definition TMath.h:38
constexpr Double_t TwoPi()
Definition TMath.h:45