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 */
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
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>
124 {
126 xyz.SetXYZ(fCos * v.x() + fSin * v.z(), v.y(), fCos * v.z() - fSin * v.x());
128 }
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());
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>
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 {
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
#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 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 displacement vector in any coordinate system.
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:98
Scalar math_atan2(Scalar x, Scalar y)
Scalar math_fabs(Scalar x)
Scalar math_sin(Scalar x)