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_MathX_GenVectorX_AxisAngle
18#define ROOT_MathX_GenVectorX_AxisAngle 1
19
25#include <algorithm>
26#include <cassert>
27
29
31
32using namespace ROOT::ROOT_MATH_ARCH;
33
34namespace ROOT {
35namespace ROOT_MATH_ARCH {
36
37//__________________________________________________________________________________________
38/**
39 AxisAngle class describing rotation represented with direction axis (3D Vector) and an
40 angle of rotation around that axis.
41
42 @ingroup GenVectorX
43
44 @see GenVectorX
45*/
46class AxisAngle {
47
48public:
49 typedef double Scalar;
50
51 /**
52 definition of vector axis
53 */
55
56 /**
57 Default constructor (axis is z and angle is zero)
58 */
59 AxisAngle() : fAxis(0, 0, 1), fAngle(0) {}
60
61 /**
62 Construct from a non-zero vector (x,y,z) and an angle.
63 Precondition: the Vector needs to implement x(), y(), z(), and unit()
64 */
65 template <class AnyVector>
67 {
68 }
69
70 /**
71 Construct given a pair of pointers or iterators defining the
72 beginning and end of an array of four Scalars, to be treated as
73 the x, y, and z components of a unit axis vector, and the angle
74 of rotation.
75 Precondition: The first three components are assumed to represent
76 the rotation axis vector and the 4-th the rotation angle.
77 The angle is assumed to be in the range (-pi,pi].
78 The axis vector is automatically normalized to be a unit vector
79 */
80 template <class IT>
81 AxisAngle(IT begin, IT end)
82 {
83 SetComponents(begin, end);
84 }
85
86 // The compiler-generated copy ctor, copy assignment, and dtor are OK.
87
88 /**
89 Re-adjust components to eliminate small deviations from the axis
90 being a unit vector and angles out of the canonical range (-pi,pi]
91 */
92 void Rectify();
93
94 // ======== Construction From other Rotation Forms ==================
95
96 /**
97 Construct from another supported rotation type (see gv_detail::convert )
98 */
99 template <class OtherRotation>
100 explicit AxisAngle(const OtherRotation &r)
101 {
102 gv_detail::convert(r, *this);
103 }
104
105 /**
106 Assign from another supported rotation type (see gv_detail::convert )
107 */
108 template <class OtherRotation>
110 {
111 gv_detail::convert(r, *this);
112 return *this;
113 }
114
115 // ======== Components ==============
116
117 /**
118 Set the axis and then the angle given a pair of pointers or iterators
119 defining the beginning and end of an array of four Scalars.
120 Precondition: The first three components are assumed to represent
121 the rotation axis vector and the 4-th the rotation angle.
122 The angle is assumed to be in the range (-pi,pi].
123 The axis vector is automatically normalized to be a unit vector
124 */
125 template <class IT>
126 void SetComponents(IT begin, IT end)
127 {
128 IT a = begin;
129 IT b = ++begin;
130 IT c = ++begin;
131 fAxis.SetCoordinates(*a, *b, *c);
132 fAngle = *(++begin);
133 (void)end;
134 assert(++begin == end);
135 // re-normalize the vector
136 double tot = fAxis.R();
137 if (tot > 0)
138 fAxis /= tot;
139 }
140
141 /**
142 Get the axis and then the angle into data specified by an iterator begin
143 and another to the end of the desired data (4 past start).
144 */
145 template <class IT>
146 void GetComponents(IT begin, IT end) const
147 {
148 IT a = begin;
149 IT b = ++begin;
150 IT c = ++begin;
151 fAxis.GetCoordinates(*a, *b, *c);
152 *(++begin) = fAngle;
153 (void)end;
154 assert(++begin == end);
155 }
156
157 /**
158 Get the axis and then the angle into data specified by an iterator begin
159 */
160 template <class IT>
161 void GetComponents(IT begin) const
162 {
163 double ax, ay, az = 0;
164 fAxis.GetCoordinates(ax, ay, az);
165 *begin++ = ax;
166 *begin++ = ay;
167 *begin++ = az;
168 *begin = fAngle;
169 }
170
171 /**
172 Set components from a non-zero vector (x,y,z) and an angle.
173 Precondition: the Vector needs to implement x(), y(), z(), and unit()
174 */
175 template <class AnyVector>
177 {
178 fAxis = v.unit();
179 fAngle = angle;
180 }
181
182 /**
183 Set components into a non-zero vector (x,y,z) and an angle.
184 The vector is intended to be a cartesian displacement vector
185 but any vector class assignable from one will work.
186 */
187 template <class AnyVector>
189 {
190 axis = fAxis;
191 angle = fAngle;
192 }
193
194 /**
195 access to rotation axis
196 */
197 AxisVector Axis() const { return fAxis; }
198
199 /**
200 access to rotation angle
201 */
202 Scalar Angle() const { return fAngle; }
203
204 // =========== operations ==============
205
206 /**
207 Rotation operation on a cartesian vector
208 */
210 XYZVector operator()(const XYZVector &v) const;
211
212 /**
213 Rotation operation on a displacement vector in any coordinate system
214 */
215 template <class CoordSystem, class Tag>
224
225 /**
226 Rotation operation on a position vector in any coordinate system
227 */
228 template <class CoordSystem, class Tag>
235
236 /**
237 Rotation operation on a Lorentz vector in any 4D coordinate system
238 */
239 template <class CoordSystem>
241 {
243 xyz = operator()(xyz);
244 LorentzVector<PxPyPzE4D<double>> xyzt(xyz.X(), xyz.Y(), xyz.Z(), v.E());
246 }
247
248 /**
249 Rotation operation on an arbitrary vector v.
250 Preconditions: v must implement methods x(), y(), and z()
251 and the arbitrary vector type must have a constructor taking (x,y,z)
252 */
253 template <class ForeignVector>
260
261 /**
262 Overload operator * for rotation on a vector
263 */
264 template <class AVector>
265 inline AVector operator*(const AVector &v) const
266 {
267 return operator()(v);
268 }
269
270 /**
271 Invert an AxisAngle rotation in place
272 */
273 void Invert() { fAngle = -fAngle; }
274
275 /**
276 Return inverse of an AxisAngle rotation
277 */
279 {
280 AxisAngle result(*this);
281 result.Invert();
282 return result;
283 }
284
285 // ========= Multi-Rotation Operations ===============
286
287 /**
288 Multiply (combine) two rotations
289 */
290 AxisAngle operator*(const Rotation3D &r) const;
291 AxisAngle operator*(const AxisAngle &a) const;
292 AxisAngle operator*(const EulerAngles &e) const;
293 AxisAngle operator*(const Quaternion &q) const;
294 AxisAngle operator*(const RotationZYX &r) const;
295 AxisAngle operator*(const RotationX &rx) const;
296 AxisAngle operator*(const RotationY &ry) const;
297 AxisAngle operator*(const RotationZ &rz) const;
298
299 /**
300 Post-Multiply (on right) by another rotation : T = T*R
301 */
302 template <class R>
304 {
305 return *this = (*this) * r;
306 }
307
308 /**
309 Distance between two rotations
310 */
311 template <class R>
312 Scalar Distance(const R &r) const
313 {
314 return gv_detail::dist(*this, r);
315 }
316
317 /**
318 Equality/inequality operators
319 */
320 bool operator==(const AxisAngle &rhs) const
321 {
322 if (fAxis != rhs.fAxis)
323 return false;
324 if (fAngle != rhs.fAngle)
325 return false;
326 return true;
327 }
328 bool operator!=(const AxisAngle &rhs) const { return !operator==(rhs); }
329
330private:
331 AxisVector fAxis; // rotation axis (3D vector)
332 Scalar fAngle; // rotation angle
333
334 void RectifyAngle();
335
336 static double Pi() { return 3.14159265358979323; }
337
338}; // AxisAngle
339
340// ============ Class AxisAngle ends here ============
341
342/**
343 Distance between two rotations
344 */
345template <class R>
346inline typename AxisAngle::Scalar Distance(const AxisAngle &r1, const R &r2)
347{
348 return gv_detail::dist(r1, r2);
349}
350
351/**
352 Multiplication of an axial rotation by an AxisAngle
353 */
357
358/**
359 Stream Output and Input
360 */
361// TODO - I/O should be put in the manipulator form
362#if !defined(ROOT_MATH_SYCL) && !defined(ROOT_MATH_CUDA)
363
364std::ostream &operator<<(std::ostream &os, const AxisAngle &a);
365
366#endif
367
368} // namespace ROOT_MATH_ARCH
369} // namespace ROOT
370
371#endif /* ROOT_MathX_GenVectorX_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
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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:46
LorentzVector< CoordSystem > operator()(const LorentzVector< CoordSystem > &v) const
Rotation operation on a Lorentz vector in any 4D coordinate system.
Definition AxisAngle.h:240
Scalar Distance(const R &r) const
Distance between two rotations.
Definition AxisAngle.h:312
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:146
DisplacementVector3D< CoordSystem, Tag > operator()(const DisplacementVector3D< CoordSystem, Tag > &v) const
Rotation operation on a displacement vector in any coordinate system.
Definition AxisAngle.h:216
AVector operator*(const AVector &v) const
Overload operator * for rotation on a vector.
Definition AxisAngle.h:265
PositionVector3D< CoordSystem, Tag > operator()(const PositionVector3D< CoordSystem, Tag > &p) const
Rotation operation on a position vector in any coordinate system.
Definition AxisAngle.h:229
DisplacementVector3D< Cartesian3D< Scalar > > AxisVector
definition of vector axis
Definition AxisAngle.h:54
AxisAngle()
Default constructor (axis is z and angle is zero)
Definition AxisAngle.h:59
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:126
void SetComponents(const AnyVector &v, Scalar angle)
Set components from a non-zero vector (x,y,z) and an angle.
Definition AxisAngle.h:176
ForeignVector operator()(const ForeignVector &v) const
Rotation operation on an arbitrary vector v.
Definition AxisAngle.h:254
void Invert()
Invert an AxisAngle rotation in place.
Definition AxisAngle.h:273
XYZVector operator()(const XYZVector &v) const
Definition AxisAngle.cxx:84
AxisAngle & operator=(OtherRotation const &r)
Assign from another supported rotation type (see gv_detail::convert )
Definition AxisAngle.h:109
AxisVector Axis() const
access to rotation axis
Definition AxisAngle.h:197
void GetComponents(IT begin) const
Get the axis and then the angle into data specified by an iterator begin.
Definition AxisAngle.h:161
AxisAngle & operator*=(const R &r)
Post-Multiply (on right) by another rotation : T = T*R.
Definition AxisAngle.h:303
Scalar Angle() const
access to rotation angle
Definition AxisAngle.h:202
bool operator==(const AxisAngle &rhs) const
Equality/inequality operators.
Definition AxisAngle.h:320
AxisAngle(const AnyVector &v, Scalar angle)
Construct from a non-zero vector (x,y,z) and an angle.
Definition AxisAngle.h:66
void GetComponents(AnyVector &axis, Scalar &angle) const
Set components into a non-zero vector (x,y,z) and an angle.
Definition AxisAngle.h:188
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:81
void Rectify()
Re-adjust components to eliminate small deviations from the axis being a unit vector and angles out o...
Definition AxisAngle.cxx:53
DisplacementVector3D< Cartesian3D< double >, DefaultCoordinateSystemTag > XYZVector
Rotation operation on a cartesian vector.
Definition AxisAngle.h:209
AxisAngle(const OtherRotation &r)
Construct from another supported rotation type (see gv_detail::convert )
Definition AxisAngle.h:100
AxisAngle Inverse() const
Return inverse of an AxisAngle rotation.
Definition AxisAngle.h:278
bool operator!=(const AxisAngle &rhs) const
Definition AxisAngle.h:328
DefaultCoordinateSystemTag Default tag for identifying any coordinate system.
EulerAngles class describing rotation as three angles (Euler Angles).
Definition EulerAngles.h:50
Rotation class with the (3D) rotation represented by a unit quaternion (u, i, j, k).
Definition Quaternion.h:52
Rotation class with the (3D) rotation represented by a 3x3 orthogonal matrix.
Definition Rotation3D.h:71
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:64
Rotation class representing a 3D rotation about the Z axis by the angle of rotation.
Definition RotationZ.h:45
double dist(Rotation3D const &r1, Rotation3D const &r2)
void convert(R1 const &, R2 const)
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
AxisAngle operator*(RotationX const &r1, AxisAngle const &r2)
Multiplication of an axial rotation by an AxisAngle.