Logo ROOT   6.13/01
Reference Guide
Quaternion.cxx
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 // Implementation file for rotation in 3 dimensions, represented by quaternion
12 //
13 // Created by: Mark Fischler Thurs June 9 2005
14 //
15 // Last update: $Id$
16 //
18 
19 #include <cmath>
20 
24 
28 
29 namespace ROOT {
30 
31 namespace Math {
32 
33 // ========== Constructors and Assignment =====================
34 
36 {
37 
38  // The vector should be a unit vector, and the first element should be
39  // non-negative (though negative fU quaternions would work just fine,
40  // being isomorphic to a quaternion with positive fU).
41 
42  if ( fU < 0 ) {
43  fU = - fU; fI = - fI; fJ = - fJ; fK = - fK;
44  }
45 
46  Scalar a = 1.0 / std::sqrt(fU*fU + fI*fI + fJ*fJ + fK*fK);
47  fU *= a;
48  fI *= a;
49  fJ *= a;
50  fK *= a;
51 
52 } // Rectify()
53 
54 
55 // ========== Operations =====================
56 
57 // DisplacementVector3D< Cartesian3D<double> >
58 // Quaternion::operator() (const DisplacementVector3D< Cartesian3D<double> > & v) const
59 // {
60 // // apply to a 3D Vector
61 // }
62 
63 // Quaternion Quaternion::operator * (const Quaternion & q) const {
64 // // combination of rotations
65 // return Quaternion (
66 // fU*q.fU - fI*q.fI - fJ*q.fJ - fK*q.fK
67 // , fU*q.fI + fI*q.fU + fJ*q.fK - fK*q.fJ
68 // , fU*q.fJ - fI*q.fK + fJ*q.fU + fK*q.fI
69 // , fU*q.fK + fI*q.fJ - fJ*q.fI + fK*q.fU );
70 //}
71 
73  // combination of rotations
74  return operator* ( Quaternion(r) );
75 }
76 
78  // combination of rotations
79  return operator* ( Quaternion(a) );
80 }
81 
83  // combination of rotations
84  return operator* ( Quaternion(e) );
85 }
86 
88  // combination of rotations
89  return operator* ( Quaternion(r) );
90 }
91 
93  // distance
94  Scalar chordLength = std::fabs(fU*q.fU + fI*q.fI + fJ*q.fJ + fK*q.fK);
95  if (chordLength > 1) chordLength = 1; // in case roundoff fouls us up
96  return acos(chordLength);
97 }
98 
99 // ========== I/O =====================
100 
101 std::ostream & operator<< (std::ostream & os, const Quaternion & q) {
102  // TODO - this will need changing for machine-readable issues
103  // and even the human readable form may need formatiing improvements
104  os << "\n{" << q.U() << " " << q.I()
105  << " " << q.J() << " " << q.K() << "}\n";
106  return os;
107 }
108 
109 
110 } //namespace Math
111 } //namespace ROOT
Scalar I() const
Definition: Quaternion.h:172
Namespace for new ROOT classes and functions.
Definition: TFoamSampler.h:19
Scalar J() const
Definition: Quaternion.h:173
Rotation class with the (3D) rotation represented by angles describing first a rotation of an angle p...
Definition: RotationZYX.h:61
Rotation class with the (3D) rotation represented by a unit quaternion (u, i, j, k).
Definition: Quaternion.h:47
std::ostream & operator<<(std::ostream &os, const AxisAngle &a)
Stream Output and Input.
Definition: AxisAngle.cxx:91
AxisAngle class describing rotation represented with direction axis (3D Vector) and an angle of rotat...
Definition: AxisAngle.h:41
double sqrt(double)
double acos(double)
Scalar U() const
Access to the four quaternion components: U() is the coefficient of the identity Pauli matrix...
Definition: Quaternion.h:171
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
Rotation class with the (3D) rotation represented by a 3x3 orthogonal matrix.
Definition: Rotation3D.h:65
EulerAngles class describing rotation as three angles (Euler Angles).
Definition: EulerAngles.h:43
you should not use this method at all Int_t Int_t Double_t Double_t Double_t e
Definition: TRolke.cxx:630
Namespace for new Math classes and functions.
void Rectify()
Re-adjust components to eliminate small deviations from |Q| = 1 orthonormality.
Definition: Quaternion.cxx:35
Scalar Distance(const Quaternion &q) const
Distance between two rotations in Quaternion form Note: The rotation group is isomorphic to a 3-spher...
Definition: Quaternion.cxx:92
Scalar K() const
Definition: Quaternion.h:174
Quaternion()
Default constructor (identity rotation)
Definition: Quaternion.h:58
AVector operator*(const AVector &v) const
Overload operator * for rotation on a vector.
Definition: Quaternion.h:246