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
29
31
32namespace ROOT {
33
34namespace ROOT_MATH_ARCH {
35
36// ========== Constructors and Assignment =====================
37
39{
40
41 // The vector should be a unit vector, and the first element should be
42 // non-negative (though negative fU quaternions would work just fine,
43 // being isomorphic to a quaternion with positive fU).
44
45 if (fU < 0) {
46 fU = -fU;
47 fI = -fI;
48 fJ = -fJ;
49 fK = -fK;
50 }
51
52 Scalar a = 1.0 / math_sqrt(fU * fU + fI * fI + fJ * fJ + fK * fK);
53 fU *= a;
54 fI *= a;
55 fJ *= a;
56 fK *= a;
57
58} // Rectify()
59
60// ========== Operations =====================
61
62// DisplacementVector3D< Cartesian3D<double> >
63// Quaternion::operator() (const DisplacementVector3D< Cartesian3D<double> > & v) const
64// {
65// // apply to a 3D Vector
66// }
67
68// Quaternion Quaternion::operator * (const Quaternion & q) const {
69// // combination of rotations
70// return Quaternion (
71// fU*q.fU - fI*q.fI - fJ*q.fJ - fK*q.fK
72// , fU*q.fI + fI*q.fU + fJ*q.fK - fK*q.fJ
73// , fU*q.fJ - fI*q.fK + fJ*q.fU + fK*q.fI
74// , fU*q.fK + fI*q.fJ - fJ*q.fI + fK*q.fU );
75//}
76
78{
79 // combination of rotations
80 return operator*(Quaternion(r));
81}
82
84{
85 // combination of rotations
86 return operator*(Quaternion(a));
87}
88
90{
91 // combination of rotations
92 return operator*(Quaternion(e));
93}
94
96{
97 // combination of rotations
98 return operator*(Quaternion(r));
99}
100
102{
103 // distance
104 Scalar chordLength = math_fabs(fU * q.fU + fI * q.fI + fJ * q.fJ + fK * q.fK);
105 if (chordLength > 1)
106 chordLength = 1; // in case roundoff fouls us up
107 return acos(chordLength);
108}
109
110#if !defined(ROOT_MATH_SYCL) && !defined(ROOT_MATH_CUDA)
111// ========== I/O =====================
112
113std::ostream &operator<<(std::ostream &os, const Quaternion &q)
114{
115 // TODO - this will need changing for machine-readable issues
116 // and even the human readable form may need formatting improvements
117 os << "\n{" << q.U() << " " << q.I() << " " << q.J() << " " << q.K() << "}\n";
118 return os;
119}
120#endif
121
122} // namespace ROOT_MATH_ARCH
123} // namespace ROOT
#define a(i)
Definition RSha256.hxx:99
#define e(i)
Definition RSha256.hxx:103
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
float * q
AxisAngle class describing rotation represented with direction axis (3D Vector) and an angle of rotat...
Definition AxisAngle.h:46
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
AVector operator*(const AVector &v) const
Overload operator * for rotation on a vector.
Definition Quaternion.h:255
void Rectify()
Re-adjust components to eliminate small deviations from |Q| = 1 orthonormality.
Quaternion()
Default constructor (identity rotation)
Definition Quaternion.h:62
Scalar Distance(const Quaternion &q) const
Distance between two rotations in Quaternion form Note: The rotation group is isomorphic to a 3-spher...
Rotation class with the (3D) rotation represented by a 3x3 orthogonal matrix.
Definition Rotation3D.h:71
Rotation class with the (3D) rotation represented by angles describing first a rotation of an angle p...
Definition RotationZYX.h:64
Scalar math_sqrt(Scalar x)
std::ostream & operator<<(std::ostream &os, const AxisAngle &a)
Stream Output and Input.
Definition AxisAngle.cxx:98
Scalar math_fabs(Scalar x)