Logo ROOT  
Reference Guide
 
Loading...
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 */
41class AxisAngle {
42
43public:
44
45 typedef double Scalar;
46
47 /**
48 definition of vector axis
49 */
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;
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;
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 */
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>
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;
270 AxisAngle operator * (const Quaternion & q) 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
301private:
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 */
317template <class R>
318inline
319typename AxisAngle::Scalar
320Distance ( const AxisAngle& r1, const R & r2) {return gv_detail::dist(r1,r2);}
321
322/**
323 Multiplication of an axial rotation by an AxisAngle
324 */
325AxisAngle operator* (RotationX const & r1, AxisAngle const & r2);
326AxisAngle operator* (RotationY const & r1, AxisAngle const & r2);
327AxisAngle 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
334std::ostream & operator<< (std::ostream & os, const AxisAngle & a);
335
336} // namespace Math
337} // namespace ROOT
338
339
340#endif /* ROOT_Math_GenVector_AxisAngle */
typedef void(GLAPIENTRYP _GLUfuncptr)(void)
ROOT::R::TRInterface & r
Definition Object.C:4
#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
float * q
AxisAngle class describing rotation represented with direction axis (3D Vector) and an angle of rotat...
Definition AxisAngle.h:41
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:116
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:132
static double Pi()
Definition AxisAngle.h:308
void Rectify()
Re-adjust components to eliminate small deviations from the axis being a unit vector and angles out o...
Definition AxisAngle.cxx:47
XYZVector operator()(const XYZVector &v) const
AVector operator*(const AVector &v) const
Overload operator * for rotation on a vector.
Definition AxisAngle.h:247
bool operator==(const AxisAngle &rhs) const
Equality/inequality operators.
Definition AxisAngle.h:292
void GetComponents(AnyVector &axis, Scalar &angle) const
Set components into a non-zero vector (x,y,z) and an angle.
Definition AxisAngle.h:169
AxisVector Axis() const
accesss to rotation axis
Definition AxisAngle.h:177
Scalar Angle() const
access to rotation angle
Definition AxisAngle.h:182
Scalar Distance(const R &r) const
Distance between two rotations.
Definition AxisAngle.h:287
DisplacementVector3D< Cartesian3D< Scalar > > AxisVector
definition of vector axis
Definition AxisAngle.h:50
void SetComponents(const AnyVector &v, Scalar angle)
Set components from a non-zero vector (x,y,z) and an angle.
Definition AxisAngle.h:158
DisplacementVector3D< Cartesian3D< double >, DefaultCoordinateSystemTag > XYZVector
Rotation operation on a cartesian vector.
Definition AxisAngle.h:189
AxisAngle(const AnyVector &v, Scalar angle)
Construct from a non-zero vector (x,y,z) and an angle.
Definition AxisAngle.h:63
AxisAngle Inverse() const
Return inverse of an AxisAngle rotation.
Definition AxisAngle.h:260
AxisAngle(const OtherRotation &r)
Construct from another supported rotation type (see gv_detail::convert )
Definition AxisAngle.h:93
AxisAngle()
Default constructor (axis is z and angle is zero)
Definition AxisAngle.h:56
void GetComponents(IT begin) const
Get the axis and then the angle into data specified by an iterator begin.
Definition AxisAngle.h:144
bool operator!=(const AxisAngle &rhs) const
Definition AxisAngle.h:297
void Invert()
Invert an AxisAngle rotation in place.
Definition AxisAngle.h:255
AxisAngle & operator=(OtherRotation const &r)
Assign from another supported rotation type (see gv_detail::convert )
Definition AxisAngle.h:100
AxisAngle & operator*=(const R &r)
Post-Multiply (on right) by another rotation : T = T*R.
Definition AxisAngle.h:280
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:77
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 unit() const
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:43
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:47
Rotation class with the (3D) rotation represented by a 3x3 orthogonal matrix.
Definition Rotation3D.h:65
Rotation class representing a 3D rotation about the X axis by the angle of rotation.
Definition RotationX.h:43
Rotation class representing a 3D rotation about the Y axis by the angle of rotation.
Definition RotationY.h:43
Rotation class with the (3D) rotation represented by angles describing first a rotation of an angle p...
Definition RotationZYX.h:61
Rotation class representing a 3D rotation about the Z axis by the angle of rotation.
Definition RotationZ.h:43
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:320
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...