Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 
35 AxisAngle AxisAngle::operator * (const Rotation3D & r) const {
36  // combination with a Rotation3D
37  return operator* ( Quaternion(r) );
38 
39 }
40 
41 AxisAngle AxisAngle::operator * (const AxisAngle & a) const {
42  // combination with another AxisAngle
43  return operator* ( Quaternion(a) );
44 }
45 
46 AxisAngle AxisAngle::operator * (const EulerAngles & e) const {
47  // combination with EulerAngles
48  return operator* ( Quaternion(e) );
49 }
50 
51 AxisAngle AxisAngle::operator * (const RotationZYX & r) const {
52  // combination with RotationZYX
53  return operator* ( Quaternion(r) );
54 }
55 
56 AxisAngle AxisAngle::operator * (const Quaternion & q) const {
57  // combination with Quaternion
58  return AxisAngle ( Quaternion(*this) * q );
59 }
60 
61 #ifdef MOVE
62 
63 AxisAngle AxisAngle::operator * (const Quaternion & q) const {
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 
89 AxisAngle AxisAngle::operator * (const RotationX & rx) const {
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 
120 AxisAngle AxisAngle::operator * (const RotationY & ry) const {
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 
151 AxisAngle AxisAngle::operator * (const RotationZ & rz) const {
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