Logo ROOT  
Reference Guide
AxisAngle.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 MathLib Team *
7  * *
8  * *
9  **********************************************************************/
10 
11 // Header file for class AxisAngle
12 //
13 // Created by: Lorenzo Moneta at Wed May 11 10:37:10 2005
14 //
15 // Last update: Wed May 11 10:37:10 2005
16 //
17 #ifndef ROOT_Math_GenVector_AxisAngle
18 #define ROOT_Math_GenVector_AxisAngle 1
19 
25 #include <algorithm>
26 #include <cassert>
27 
28 
29 namespace ROOT {
30 namespace Math {
31 
32 
33 //__________________________________________________________________________________________
34  /**
35  AxisAngle class describing rotation represented with direction axis (3D Vector) and an
36  angle of rotation around that axis.
37 
38  @ingroup GenVector
39 
40  */
41 class AxisAngle {
42 
43 public:
44 
45  typedef double Scalar;
46 
47  /**
48  definition of vector axis
49  */
50  typedef DisplacementVector3D<Cartesian3D<Scalar> > AxisVector;
51 
52 
53  /**
54  Default constructor (axis is z and angle is zero)
55  */
56  AxisAngle() : fAxis(0,0,1), fAngle(0) { }
57 
58  /**
59  Construct from a non-zero vector (x,y,z) and an angle.
60  Precondition: the Vector needs to implement x(), y(), z(), and unit()
61  */
62  template<class AnyVector>
63  AxisAngle(const AnyVector & v, Scalar angle) :
64  fAxis(v.unit()), fAngle(angle) { }
65 
66  /**
67  Construct given a pair of pointers or iterators defining the
68  beginning and end of an array of four Scalars, to be treated as
69  the x, y, and z components of a unit axis vector, and the angle
70  of rotation.
71  Precondition: The first three components are assumed to represent
72  the rotation axis vector and the 4-th the rotation angle.
73  The angle is assumed to be in the range (-pi,pi].
74  The axis vector is automatically normalized to be a unit vector
75  */
76  template<class IT>
77  AxisAngle(IT begin, IT end) { SetComponents(begin,end); }
78 
79  // The compiler-generated copy ctor, copy assignment, and dtor are OK.
80 
81  /**
82  Re-adjust components to eliminate small deviations from the axis
83  being a unit vector and angles out of the canonical range (-pi,pi]
84  */
85  void Rectify();
86 
87  // ======== Construction From other Rotation Forms ==================
88 
89  /**
90  Construct from another supported rotation type (see gv_detail::convert )
91  */
92  template <class OtherRotation>
93  explicit AxisAngle(const OtherRotation & r) {gv_detail::convert(r,*this);}
94 
95 
96  /**
97  Assign from another supported rotation type (see gv_detail::convert )
98  */
99  template <class OtherRotation>
100  AxisAngle & operator=( OtherRotation const & r ) {
101  gv_detail::convert(r,*this);
102  return *this;
103  }
104 
105  // ======== Components ==============
106 
107  /**
108  Set the axis and then the angle given a pair of pointers or iterators
109  defining the beginning and end of an array of four Scalars.
110  Precondition: The first three components are assumed to represent
111  the rotation axis vector and the 4-th the rotation angle.
112  The angle is assumed to be in the range (-pi,pi].
113  The axis vector is automatically normalized to be a unit vector
114  */
115  template<class IT>
116  void SetComponents(IT begin, IT end) {
117  IT a = begin; IT b = ++begin; IT c = ++begin;
118  fAxis.SetCoordinates(*a,*b,*c);
119  fAngle = *(++begin);
120  (void)end;
121  assert (++begin==end);
122  // re-normalize the vector
123  double tot = fAxis.R();
124  if (tot > 0) fAxis /= tot;
125  }
126 
127  /**
128  Get the axis and then the angle into data specified by an iterator begin
129  and another to the end of the desired data (4 past start).
130  */
131  template<class IT>
132  void GetComponents(IT begin, IT end) const {
133  IT a = begin; IT b = ++begin; IT c = ++begin;
134  fAxis.GetCoordinates(*a,*b,*c);
135  *(++begin) = fAngle;
136  (void)end;
137  assert (++begin==end);
138  }
139 
140  /**
141  Get the axis and then the angle into data specified by an iterator begin
142  */
143  template<class IT>
144  void GetComponents(IT begin) const {
145  double ax,ay,az = 0;
146  fAxis.GetCoordinates(ax,ay,az);
147  *begin++ = ax;
148  *begin++ = ay;
149  *begin++ = az;
150  *begin = fAngle;
151  }
152 
153  /**
154  Set components from a non-zero vector (x,y,z) and an angle.
155  Precondition: the Vector needs to implement x(), y(), z(), and unit()
156  */
157  template<class AnyVector>
158  void SetComponents(const AnyVector & v, Scalar angle) {
159  fAxis=v.unit();
160  fAngle=angle;
161  }
162 
163  /**
164  Set components into a non-zero vector (x,y,z) and an angle.
165  The vector is intended to be a cartesian dispalcement vector
166  but any vector class assignable from one will work.
167  */
168  template<class AnyVector>
169  void GetComponents(AnyVector & axis, Scalar & angle) const {
170  axis = fAxis;
171  angle = fAngle;
172  }
173 
174  /**
175  accesss to rotation axis
176  */
177  AxisVector Axis() const { return fAxis; }
178 
179  /**
180  access to rotation angle
181  */
182  Scalar Angle() const { return fAngle; }
183 
184  // =========== operations ==============
185 
186  /**
187  Rotation operation on a cartesian vector
188  */
190  XYZVector operator() (const XYZVector & v) const;
191 
192  /**
193  Rotation operation on a displacement vector in any coordinate system
194  */
195  template <class CoordSystem, class Tag>
198  DisplacementVector3D< Cartesian3D<double> > xyz(v.X(), v.Y(), v.Z());
201  vNew.SetXYZ( rxyz.X(), rxyz.Y(), rxyz.Z() );
202  return vNew;
203  }
204 
205  /**
206  Rotation operation on a position vector in any coordinate system
207  */
208  template <class CoordSystem, class Tag>
213  return PositionVector3D<CoordSystem,Tag> ( rxyz );
214  }
215 
216  /**
217  Rotation operation on a Lorentz vector in any 4D coordinate system
218  */
219  template <class CoordSystem>
221  operator() (const LorentzVector<CoordSystem> & v) const {
223  xyz = operator()(xyz);
224  LorentzVector< PxPyPzE4D<double> > xyzt (xyz.X(), xyz.Y(), xyz.Z(), v.E());
225  return LorentzVector<CoordSystem> ( xyzt );
226  }
227 
228 
229  /**
230  Rotation operation on an arbitrary vector v.
231  Preconditions: v must implement methods x(), y(), and z()
232  and the arbitrary vector type must have a constructor taking (x,y,z)
233  */
234  template <class ForeignVector>
235  ForeignVector
236  operator() (const ForeignVector & v) const {
239  return ForeignVector ( rxyz.X(), rxyz.Y(), rxyz.Z() );
240  }
241 
242  /**
243  Overload operator * for rotation on a vector
244  */
245  template <class AVector>
246  inline
247  AVector operator* (const AVector & v) const
248  {
249  return operator()(v);
250  }
251 
252  /**
253  Invert an AxisAngle rotation in place
254  */
255  void Invert() { fAngle = -fAngle; }
256 
257  /**
258  Return inverse of an AxisAngle rotation
259  */
260  AxisAngle Inverse() const { AxisAngle result(*this); result.Invert(); return result; }
261 
262  // ========= Multi-Rotation Operations ===============
263 
264  /**
265  Multiply (combine) two rotations
266  */
267  AxisAngle operator * (const Rotation3D & r) const;
268  AxisAngle operator * (const AxisAngle & a) const;
269  AxisAngle operator * (const EulerAngles & e) const;
271  AxisAngle operator * (const RotationZYX & r) const;
272  AxisAngle operator * (const RotationX & rx) const;
273  AxisAngle operator * (const RotationY & ry) const;
274  AxisAngle operator * (const RotationZ & rz) const;
275 
276  /**
277  Post-Multiply (on right) by another rotation : T = T*R
278  */
279  template <class R>
280  AxisAngle & operator *= (const R & r) { return *this = (*this)*r; }
281 
282 
283  /**
284  Distance between two rotations
285  */
286  template <class R>
287  Scalar Distance ( const R & r ) const {return gv_detail::dist(*this,r);}
288 
289  /**
290  Equality/inequality operators
291  */
292  bool operator == (const AxisAngle & rhs) const {
293  if( fAxis != rhs.fAxis ) return false;
294  if( fAngle != rhs.fAngle ) return false;
295  return true;
296  }
297  bool operator != (const AxisAngle & rhs) const {
298  return ! operator==(rhs);
299  }
300 
301 private:
302 
303  AxisVector fAxis; // rotation axis (3D vector)
304  Scalar fAngle; // rotation angle
305 
306  void RectifyAngle();
307 
308  static double Pi() { return 3.14159265358979323; }
309 
310 }; // AxisAngle
311 
312 // ============ Class AxisAngle ends here ============
313 
314 /**
315  Distance between two rotations
316  */
317 template <class R>
318 inline
320 Distance ( const AxisAngle& r1, const R & r2) {return gv_detail::dist(r1,r2);}
321 
322 /**
323  Multiplication of an axial rotation by an AxisAngle
324  */
325 AxisAngle operator* (RotationX const & r1, AxisAngle const & r2);
326 AxisAngle operator* (RotationY const & r1, AxisAngle const & r2);
327 AxisAngle operator* (RotationZ const & r1, AxisAngle const & r2);
328 
329 /**
330  Stream Output and Input
331  */
332  // TODO - I/O should be put in the manipulator form
333 
334 std::ostream & operator<< (std::ostream & os, const AxisAngle & a);
335 
336 } // namespace Math
337 } // namespace ROOT
338 
339 
340 #endif /* ROOT_Math_GenVector_AxisAngle */
c
#define c(i)
Definition: RSha256.hxx:119
ROOT::Math::AxisAngle::AxisVector
DisplacementVector3D< Cartesian3D< Scalar > > AxisVector
definition of vector axis
Definition: AxisAngle.h:65
ROOT::Math::AxisAngle::SetComponents
void SetComponents(IT begin, IT end)
Set the axis and then the angle given a pair of pointers or iterators defining the beginning and end ...
Definition: AxisAngle.h:131
ROOT::Math::AxisAngle
AxisAngle class describing rotation represented with direction axis (3D Vector) and an angle of rotat...
Definition: AxisAngle.h:51
e
#define e(i)
Definition: RSha256.hxx:121
ROOT::Math::AxisAngle::XYZVector
DisplacementVector3D< Cartesian3D< double >, DefaultCoordinateSystemTag > XYZVector
Rotation operation on a cartesian vector.
Definition: AxisAngle.h:204
ROOT::Math::AxisAngle::Invert
void Invert()
Invert an AxisAngle rotation in place.
Definition: AxisAngle.h:270
ROOT::Math::AxisAngle::operator!=
bool operator!=(const AxisAngle &rhs) const
Definition: AxisAngle.h:312
ROOT::Math::AxisAngle::Pi
static double Pi()
Definition: AxisAngle.h:323
ROOT::Math::AxisAngle::Rectify
void Rectify()
Re-adjust components to eliminate small deviations from the axis being a unit vector and angles out o...
Definition: AxisAngle.cxx:57
ROOT::Math::RotationZYX
Rotation class with the (3D) rotation represented by angles describing first a rotation of an angle p...
Definition: RotationZYX.h:71
ROOT::Math::PositionVector3D
Class describing a generic position vector (point) in 3 dimensions.
Definition: PositionVector3D.h:63
r
ROOT::R::TRInterface & r
Definition: Object.C:4
ROOT::Math::RotationZ
Rotation class representing a 3D rotation about the Z axis by the angle of rotation.
Definition: RotationZ.h:53
ROOT::Math::Rotation3D
Rotation class with the (3D) rotation represented by a 3x3 orthogonal matrix.
Definition: Rotation3D.h:75
ROOT::Math::AxisAngle::operator()
XYZVector operator()(const XYZVector &v) const
ROOT::Math::operator<<
std::ostream & operator<<(std::ostream &os, const AxisAngle &a)
Stream Output and Input.
Definition: AxisAngle.cxx:101
ROOT::Math::AxisAngle::Inverse
AxisAngle Inverse() const
Return inverse of an AxisAngle rotation.
Definition: AxisAngle.h:275
ROOT::Math::DisplacementVector3D::SetCoordinates
DisplacementVector3D< CoordSystem, Tag > & SetCoordinates(const Scalar src[])
Set internal data based on a C-style array of 3 Scalar numbers.
Definition: DisplacementVector3D.h:198
ROOT::Math::DisplacementVector3D::R
Scalar R() const
Polar R, converting if necessary from internal coordinate system.
Definition: DisplacementVector3D.h:297
ROOT::Math::DisplacementVector3D::Y
Scalar Y() const
Cartesian Y, converting if necessary from internal coordinate system.
Definition: DisplacementVector3D.h:287
v
@ v
Definition: rootcling_impl.cxx:3635
b
#define b(i)
Definition: RSha256.hxx:118
ROOT::Math::AxisAngle::fAngle
Scalar fAngle
Definition: AxisAngle.h:319
q
float * q
Definition: THbookFile.cxx:89
R
#define R(a, b, c, d, e, f, g, h, i)
Definition: RSha256.hxx:128
ROOT::Math::DisplacementVector3D::GetCoordinates
void GetCoordinates(Scalar &a, Scalar &b, Scalar &c) const
get internal data into 3 Scalar numbers
Definition: DisplacementVector3D.h:222
ROOT::Math::gv_detail::dist
double dist(Rotation3D const &r1, Rotation3D const &r2)
Definition: 3DDistances.cxx:63
ROOT::Math::AxisAngle::fAxis
AxisVector fAxis
Definition: AxisAngle.h:318
ROOT::Math::AxisAngle::operator=
AxisAngle & operator=(OtherRotation const &r)
Assign from another supported rotation type (see gv_detail::convert )
Definition: AxisAngle.h:115
a
auto * a
Definition: textangle.C:12
ROOT::Math::EulerAngles
EulerAngles class describing rotation as three angles (Euler Angles).
Definition: EulerAngles.h:53
ROOT::Math::AxisAngle::GetComponents
void GetComponents(IT begin, IT end) const
Get the axis and then the angle into data specified by an iterator begin and another to the end of th...
Definition: AxisAngle.h:147
ROOT::Math::DisplacementVector3D::X
Scalar X() const
Cartesian X, converting if necessary from internal coordinate system.
Definition: DisplacementVector3D.h:282
ROOT::Math::RotationX
Rotation class representing a 3D rotation about the X axis by the angle of rotation.
Definition: RotationX.h:53
PositionVector3D.h
void
typedef void((*Func_t)())
ROOT::Math::DisplacementVector3D::Z
Scalar Z() const
Cartesian Z, converting if necessary from internal coordinate system.
Definition: DisplacementVector3D.h:292
3DConversions.h
ROOT::Math::operator*
AxisAngle operator*(RotationX const &r1, AxisAngle const &r2)
Multiplication of an axial rotation by an AxisAngle.
Definition: AxisAngleXother.cxx:191
Rotation3D.h
ROOT::Math::AxisAngle::Distance
Scalar Distance(const R &r) const
Distance between two rotations.
Definition: AxisAngle.h:302
DisplacementVector3D.h
ROOT::Math::DefaultCoordinateSystemTag
DefaultCoordinateSystemTag Default tag for identifying any coordinate system.
Definition: CoordinateSystemTags.h:48
ROOT::Math::AxisAngle::Scalar
double Scalar
Definition: AxisAngle.h:60
ROOT::Math::AxisAngle::Angle
Scalar Angle() const
access to rotation angle
Definition: AxisAngle.h:197
ROOT::Math::Scalar
Rotation3D::Scalar Scalar
Definition: Rotation3DxAxial.cxx:69
ROOT::Math::AxisAngle::operator==
bool operator==(const AxisAngle &rhs) const
Equality/inequality operators.
Definition: AxisAngle.h:307
ROOT::Math::AxisAngle::operator*=
AxisAngle & operator*=(const R &r)
Post-Multiply (on right) by another rotation : T = T*R.
Definition: AxisAngle.h:295
ROOT::Math::gv_detail::convert
void convert(R1 const &, R2 const)
Definition: 3DConversions.h:56
ROOT::Math::AxisAngle::operator()
DisplacementVector3D< CoordSystem, Tag > operator()(const DisplacementVector3D< CoordSystem, Tag > &v) const
Rotation operation on a displacement vector in any coordinate system.
Definition: AxisAngle.h:212
ROOT::Math::DisplacementVector3D::SetXYZ
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...
Definition: DisplacementVector3D.h:260
ROOT::Math::DisplacementVector3D< Cartesian3D< Scalar > >
LorentzVector.h
ROOT::Math::AxisAngle::AxisAngle
AxisAngle()
Default constructor (axis is z and angle is zero)
Definition: AxisAngle.h:71
ROOT::Math::AxisAngle::RectifyAngle
void RectifyAngle()
Definition: AxisAngle.cxx:41
ROOT::Math::Quaternion
Rotation class with the (3D) rotation represented by a unit quaternion (u, i, j, k).
Definition: Quaternion.h:57
ROOT::Math::Distance
AxisAngle::Scalar Distance(const AxisAngle &r1, const R &r2)
Distance between two rotations.
Definition: AxisAngle.h:330
ROOT
VSD Structures.
Definition: StringConv.hxx:21
Math
ROOT::Math::AxisAngle::Axis
AxisVector Axis() const
accesss to rotation axis
Definition: AxisAngle.h:192
ROOT::Math::LorentzVector
Definition: LorentzVector.h:70
ROOT::Math::AxisAngle::operator*
AVector operator*(const AVector &v) const
Overload operator * for rotation on a vector.
Definition: AxisAngle.h:262
ROOT::Math::RotationY
Rotation class representing a 3D rotation about the Y axis by the angle of rotation.
Definition: RotationY.h:53