Logo ROOT   6.16/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
29namespace ROOT {
30
31namespace 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
101std::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
ROOT::R::TRInterface & r
Definition: Object.C:4
#define e(i)
Definition: RSha256.hxx:103
float * q
Definition: THbookFile.cxx:87
double acos(double)
double sqrt(double)
AxisAngle class describing rotation represented with direction axis (3D Vector) and an angle of rotat...
Definition: AxisAngle.h:41
EulerAngles class describing rotation as three angles (Euler Angles).
Definition: EulerAngles.h:43
Rotation class with the (3D) rotation represented by a unit quaternion (u, i, j, k).
Definition: Quaternion.h:47
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
Quaternion()
Default constructor (identity rotation)
Definition: Quaternion.h:58
void Rectify()
Re-adjust components to eliminate small deviations from |Q| = 1 orthonormality.
Definition: Quaternion.cxx:35
AVector operator*(const AVector &v) const
Overload operator * for rotation on a vector.
Definition: Quaternion.h:246
Rotation class with the (3D) rotation represented by a 3x3 orthogonal matrix.
Definition: Rotation3D.h:65
Rotation class with the (3D) rotation represented by angles describing first a rotation of an angle p...
Definition: RotationZYX.h:61
Namespace for new Math classes and functions.
std::ostream & operator<<(std::ostream &os, const AxisAngle &a)
Stream Output and Input.
Definition: AxisAngle.cxx:91
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
auto * a
Definition: textangle.C:12