Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
28namespace ROOT {
29
30namespace 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 }
44
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
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
100std::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
ROOT::R::TRInterface & r
Definition Object.C:4
#define a(i)
Definition RSha256.hxx:99
#define e(i)
Definition RSha256.hxx:103
float * q
double acos(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...
Quaternion()
Default constructor (identity rotation)
Definition Quaternion.h:58
void Rectify()
Re-adjust components to eliminate small deviations from |Q| = 1 orthonormality.
AVector operator*(const AVector &v) const
Overload operator * for rotation on a vector.
Definition Quaternion.h:240
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.
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...