 ROOT   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
23
27
28 namespace ROOT {
29
30 namespace Math {
31
32 // ========== Constructors and Assignment =====================
33
35 {
36
37  // The vector should be a unit vector, and the first element should be
38  // non-negative (though negative fU quaternions would work just fine,
39  // being isomorphic to a quaternion with positive fU).
40
41  if ( fU < 0 ) {
42  fU = - fU; fI = - fI; fJ = - fJ; fK = - fK;
43  }
45  Scalar a = 1.0 / std::sqrt(fU*fU + fI*fI + fJ*fJ + fK*fK);
46  fU *= a;
47  fI *= a;
48  fJ *= a;
49  fK *= a;
50
51 } // Rectify()
52
53
54 // ========== Operations =====================
55
56 // DisplacementVector3D< Cartesian3D<double> >
57 // Quaternion::operator() (const DisplacementVector3D< Cartesian3D<double> > & v) const
58 // {
59 // // apply to a 3D Vector
60 // }
61
62 // Quaternion Quaternion::operator * (const Quaternion & q) const {
63 // // combination of rotations
64 // return Quaternion (
65 // fU*q.fU - fI*q.fI - fJ*q.fJ - fK*q.fK
66 // , fU*q.fI + fI*q.fU + fJ*q.fK - fK*q.fJ
67 // , fU*q.fJ - fI*q.fK + fJ*q.fU + fK*q.fI
68 // , fU*q.fK + fI*q.fJ - fJ*q.fI + fK*q.fU );
69 //}
70
72  // combination of rotations
73  return operator* ( Quaternion(r) );
74 }
75
76 Quaternion Quaternion::operator * (const AxisAngle & a) const {
77  // combination of rotations
78  return operator* ( Quaternion(a) );
79 }
80
82  // combination of rotations
83  return operator* ( Quaternion(e) );
84 }
85
87  // combination of rotations
88  return operator* ( Quaternion(r) );
89 }
90
92  // distance
93  Scalar chordLength = std::fabs(fU*q.fU + fI*q.fI + fJ*q.fJ + fK*q.fK);
94  if (chordLength > 1) chordLength = 1; // in case roundoff fouls us up
95  return acos(chordLength);
96 }
97
98 // ========== I/O =====================
99
100 std::ostream & operator<< (std::ostream & os, const Quaternion & q) {
101  // TODO - this will need changing for machine-readable issues
102  // and even the human readable form may need formatiing improvements
103  os << "\n{" << q.U() << " " << q.I()
104  << " " << q.J() << " " << q.K() << "}\n";
105  return os;
106 }
107
108
109 } //namespace Math
110 } //namespace ROOT
e
#define e(i)
Definition: RSha256.hxx:121
Rotation3Dfwd.h
ROOT::Math::Quaternion::fJ
Scalar fJ
Definition: Quaternion.h:330
ROOT::Math::Quaternion::Distance
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:101
ROOT::Math::RotationZYX
Rotation class with the (3D) rotation represented by angles describing first a rotation of an angle p...
Definition: RotationZYX.h:71
r
ROOT::R::TRInterface & r
Definition: Object.C:4
ROOT::Math::Rotation3D
Rotation class with the (3D) rotation represented by a 3x3 orthogonal matrix.
Definition: Rotation3D.h:75
ROOT::Math::Quaternion::operator*
AVector operator*(const AVector &v) const
Overload operator * for rotation on a vector.
Definition: Quaternion.h:255
ROOT::Math::operator<<
std::ostream & operator<<(std::ostream &os, const AxisAngle &a)
Stream Output and Input.
Definition: AxisAngle.cxx:101
ROOT::Math::Quaternion::Rectify
void Rectify()
Re-adjust components to eliminate small deviations from |Q| = 1 orthonormality.
Definition: Quaternion.cxx:44
Quaternion.h
ROOT::Math::Quaternion::Quaternion
Quaternion()
Default constructor (identity rotation)
Definition: Quaternion.h:73
q
float * q
Definition: THbookFile.cxx:89
Cartesian3D.h
ROOT::Math::fabs
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
Definition: UnaryOperators.h:131
AxisAnglefwd.h
a
auto * a
Definition: textangle.C:12
ROOT::Math::EulerAngles
EulerAngles class describing rotation as three angles (Euler Angles).
Definition: EulerAngles.h:53
sqrt
double sqrt(double)
acos
double acos(double)
ROOT::Math::Quaternion::fU
Scalar fU
Definition: Quaternion.h:328
DisplacementVector3D.h
ROOT::Math::Quaternion::Scalar
double Scalar
Definition: Quaternion.h:66
ROOT::Math::Quaternion::fK
Scalar fK
Definition: Quaternion.h:331
ROOT::Math::Quaternion::fI
Scalar fI
Definition: Quaternion.h:329
ROOT::Math::Quaternion
Rotation class with the (3D) rotation represented by a unit quaternion (u, i, j, k).
Definition: Quaternion.h:57
EulerAnglesfwd.h
ROOT
VSD Structures.
Definition: StringConv.hxx:21
Math