Logo ROOT   6.19/01
Reference Guide
AxisAngleXother.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 // Header file for multiplications of AxisAngle by a rotation
12 //
13 // Created by: Mark Fischler Tues July 5 2005
14 //
15 
17 
18 #include <cmath>
19 
26 
29 
30 namespace ROOT {
31 
32 namespace Math {
33 
34 
36  // combination with a Rotation3D
37  return operator* ( Quaternion(r) );
38 
39 }
40 
42  // combination with another AxisAngle
43  return operator* ( Quaternion(a) );
44 }
45 
47  // combination with EulerAngles
48  return operator* ( Quaternion(e) );
49 }
50 
52  // combination with RotationZYX
53  return operator* ( Quaternion(r) );
54 }
55 
57  // combination with Quaternion
58  return AxisAngle ( Quaternion(*this) * q );
59 }
60 
61 #ifdef MOVE
62 
64  // combination with quaternion (not used)
65  const Scalar s1 = std::sin(fAngle/2);
66  const Scalar au = std::cos(fAngle/2);
67  const Scalar ai = s1 * fAxis.X();
68  const Scalar aj = s1 * fAxis.Y();
69  const Scalar ak = s1 * fAxis.Z();
70  Scalar aqu = au*q.U() - ai*q.I() - aj*q.J() - ak*q.K();
71  Scalar aqi = au*q.I() + ai*q.U() + aj*q.K() - ak*q.J();
72  Scalar aqj = au*q.J() - ai*q.K() + aj*q.U() + ak*q.I();
73  Scalar aqk = au*q.K() + ai*q.J() - aj*q.I() + ak*q.U();
74  Scalar r = std::sqrt(aqi*aqi + aqj*aqj + aqk*aqk);
75  if (r > 1) r = 1;
76  if (aqu < 0) { aqu = - aqu; aqi = - aqi; aqj = - aqj, aqk = - aqk; }
77  const Scalar angle = 2*asin ( r );
78  DisplacementVector3D< Cartesian3D<double> > axis ( aqi, aqj, aqk );
79  if ( r == 0 ) {
80  axis.SetCoordinates(0,0,1);
81  } else {
82  axis /= r;
83  }
84  return AxisAngle ( axis, angle );
85 }
86 
87 #endif
88 
90  // combination with RotationX
91 
92  const Scalar s1 = std::sin(fAngle/2);
93  const Scalar au = std::cos(fAngle/2);
94  const Scalar ai = s1 * fAxis.X();
95  const Scalar aj = s1 * fAxis.Y();
96  const Scalar ak = s1 * fAxis.Z();
97  Scalar c = rx.CosAngle();
98  if ( c > 1 ) c = 1;
99  if ( c < -1 ) c = -1;
100  Scalar qu = std::sqrt( .5*(1+c) );
101  Scalar qi = std::sqrt( .5*(1-c) );
102  if ( rx.SinAngle() < 0 ) qi = -qi;
103  Scalar aqu = au*qu - ai*qi;
104  Scalar aqi = ai*qu + au*qi;
105  Scalar aqj = aj*qu + ak*qi;
106  Scalar aqk = ak*qu - aj*qi;
107  Scalar r = std::sqrt(aqi*aqi + aqj*aqj + aqk*aqk);
108  if (r > 1) r = 1;
109  if (aqu < 0) { aqu = - aqu; aqi = - aqi; aqj = - aqj, aqk = - aqk; }
110  const Scalar angle = 2*asin ( r );
111  DisplacementVector3D< Cartesian3D<double> > axis ( aqi, aqj, aqk );
112  if ( r == 0 ) {
113  axis.SetCoordinates(0,0,1);
114  } else {
115  axis /= r;
116  }
117  return AxisAngle ( axis, angle );
118 }
119 
121  // combination with RotationY
122 
123  const Scalar s1 = std::sin(fAngle/2);
124  const Scalar au = std::cos(fAngle/2);
125  const Scalar ai = s1 * fAxis.X();
126  const Scalar aj = s1 * fAxis.Y();
127  const Scalar ak = s1 * fAxis.Z();
128  Scalar c = ry.CosAngle();
129  if ( c > 1 ) c = 1;
130  if ( c < -1 ) c = -1;
131  Scalar qu = std::sqrt( .5*(1+c) );
132  Scalar qj = std::sqrt( .5*(1-c) );
133  if ( ry.SinAngle() < 0 ) qj = -qj;
134  Scalar aqu = au*qu - aj*qj;
135  Scalar aqi = ai*qu - ak*qj;
136  Scalar aqj = aj*qu + au*qj;
137  Scalar aqk = ak*qu + ai*qj;
138  Scalar r = std::sqrt(aqi*aqi + aqj*aqj + aqk*aqk);
139  if (r > 1) r = 1;
140  if (aqu < 0) { aqu = - aqu; aqi = - aqi; aqj = - aqj, aqk = - aqk; }
141  const Scalar angle = 2*asin ( r );
142  DisplacementVector3D< Cartesian3D<double> > axis ( aqi, aqj, aqk );
143  if ( r == 0 ) {
144  axis.SetCoordinates(0,0,1);
145  } else {
146  axis /= r;
147  }
148  return AxisAngle ( axis, angle );
149 }
150 
152  // combination with RotationZ
153 
154  const Scalar s1 = std::sin(fAngle/2);
155  const Scalar au = std::cos(fAngle/2);
156  const Scalar ai = s1 * fAxis.X();
157  const Scalar aj = s1 * fAxis.Y();
158  const Scalar ak = s1 * fAxis.Z();
159  Scalar c = rz.CosAngle();
160  if ( c > 1 ) c = 1;
161  if ( c < -1 ) c = -1;
162  Scalar qu = std::sqrt( .5*(1+c) );
163  Scalar qk = std::sqrt( .5*(1-c) );
164  if ( rz.SinAngle() < 0 ) qk = -qk;
165  Scalar aqu = au*qu - ak*qk;
166  Scalar aqi = ai*qu + aj*qk;
167  Scalar aqj = aj*qu - ai*qk;
168  Scalar aqk = ak*qu + au*qk;
169  Scalar r = std::sqrt(aqi*aqi + aqj*aqj + aqk*aqk);
170  if (r > 1) r = 1;
171  if (aqu < 0) { aqu = - aqu; aqi = - aqi; aqj = - aqj, aqk = - aqk; }
172  const Scalar angle = 2*asin ( r );
173  DisplacementVector3D< Cartesian3D<double> > axis ( aqi, aqj, aqk );
174  if ( r == 0 ) {
175  axis.SetCoordinates(0,0,1);
176  } else {
177  axis /= r;
178  }
179  return AxisAngle ( axis, angle );
180 }
181 
182 AxisAngle operator*( RotationX const & r, AxisAngle const & a ) {
183  return AxisAngle(r) * a; // TODO: improve performance
184 }
185 
186 AxisAngle operator*( RotationY const & r, AxisAngle const & a ) {
187  return AxisAngle(r) * a; // TODO: improve performance
188 }
189 
190 AxisAngle operator*( RotationZ const & r, AxisAngle const & a ) {
191  return AxisAngle(r) * a; // TODO: improve performance
192 }
193 
194 
195 } //namespace Math
196 } //namespace ROOT
Scalar SinAngle() const
Sine or Cosine of the rotation angle.
Definition: RotationZ.h:108
DisplacementVector3D< CoordSystem, Tag > & SetCoordinates(const Scalar src[])
Set internal data based on a C-style array of 3 Scalar numbers.
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
AVector operator*(const AVector &v) const
Overload operator * for rotation on a vector.
Definition: AxisAngle.h:253
AxisAngle()
Default constructor (axis is z and angle is zero)
Definition: AxisAngle.h:56
Rotation class representing a 3D rotation about the Z axis by the angle of rotation.
Definition: RotationZ.h:43
Scalar CosAngle() const
Definition: RotationZ.h:109
Scalar SinAngle() const
Sine or Cosine of the rotation angle.
Definition: RotationY.h:108
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
double cos(double)
Scalar CosAngle() const
Definition: RotationY.h:109
AxisAngle class describing rotation represented with direction axis (3D Vector) and an angle of rotat...
Definition: AxisAngle.h:41
Scalar X() const
Cartesian X, converting if necessary from internal coordinate system.
double sqrt(double)
Rotation class representing a 3D rotation about the Y axis by the angle of rotation.
Definition: RotationY.h:43
Scalar Z() const
Cartesian Z, converting if necessary from internal coordinate system.
Scalar Y() const
Cartesian Y, converting if necessary from internal coordinate system.
double sin(double)
Class describing a generic displacement vector in 3 dimensions.
ROOT::R::TRInterface & r
Definition: Object.C:4
auto * a
Definition: textangle.C:12
Rotation class representing a 3D rotation about the X axis by the angle of rotation.
Definition: RotationX.h:43
Rotation class with the (3D) rotation represented by a 3x3 orthogonal matrix.
Definition: Rotation3D.h:65
#define s1(x)
Definition: RSha256.hxx:91
Scalar CosAngle() const
Definition: RotationX.h:109
double asin(double)
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.
#define c(i)
Definition: RSha256.hxx:101
float * q
Definition: THbookFile.cxx:87
Rotation3D::Scalar Scalar
Scalar SinAngle() const
Sine or Cosine of the rotation angle.
Definition: RotationX.h:108
AxisAngle operator*(RotationX const &r1, AxisAngle const &r2)
Multiplication of an axial rotation by an AxisAngle.