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