AxisAngleXother.cxx

Go to the documentation of this file.
00001 // @(#)root/mathcore:$Id: AxisAngleXother.cxx 22516 2008-03-07 15:14:26Z moneta $
00002 // Authors: W. Brown, M. Fischler, L. Moneta    2005  
00003 
00004  /**********************************************************************
00005   *                                                                    *
00006   * Copyright (c) 2005 , LCG ROOT FNAL MathLib Team                    *
00007   *                                                                    *
00008   *                                                                    *
00009   **********************************************************************/
00010 
00011 // Header file for multiplications of AxisAngle by a rotation
00012 //
00013 // Created by: Mark Fischler Tues July 5  2005
00014 //
00015 
00016 #include "Math/GenVector/AxisAngle.h"
00017 
00018 #include <cmath>
00019 
00020 #include "Math/GenVector/AxisAngle.h"
00021 #include "Math/GenVector/Quaternion.h"
00022 #include "Math/GenVector/Cartesian3D.h"
00023 #include "Math/GenVector/RotationX.h"
00024 #include "Math/GenVector/RotationY.h"
00025 #include "Math/GenVector/RotationZ.h"
00026 
00027 #include "Math/GenVector/Rotation3Dfwd.h"
00028 #include "Math/GenVector/EulerAnglesfwd.h"
00029 
00030 namespace ROOT {
00031 
00032 namespace Math {
00033 
00034 
00035 AxisAngle AxisAngle::operator * (const Rotation3D & r) const {
00036    // combination with a Rotation3D
00037    return operator* ( Quaternion(r) );
00038    
00039 }
00040 
00041 AxisAngle AxisAngle::operator * (const AxisAngle   & a) const {
00042    // combination with another AxisAngle
00043    return operator* ( Quaternion(a) );
00044 }
00045 
00046 AxisAngle AxisAngle::operator * (const EulerAngles & e) const {
00047    // combination with EulerAngles
00048    return operator* ( Quaternion(e) );
00049 }
00050 
00051 AxisAngle AxisAngle::operator * (const RotationZYX & r) const {
00052    // combination with RotationZYX
00053    return operator* ( Quaternion(r) );
00054 }
00055 
00056 AxisAngle AxisAngle::operator * (const Quaternion  & q) const {
00057    // combination with Quaternion
00058    return AxisAngle ( Quaternion(*this) * q );
00059 }
00060 
00061 #ifdef MOVE
00062 
00063 AxisAngle AxisAngle::operator * (const Quaternion  & q) const {
00064    // combination with quaternion (not used)
00065    const Scalar s1 = std::sin(fAngle/2);
00066    const Scalar au = std::cos(fAngle/2);
00067    const Scalar ai = s1 * fAxis.X();
00068    const Scalar aj = s1 * fAxis.Y();
00069    const Scalar ak = s1 * fAxis.Z();
00070    Scalar aqu = au*q.U() - ai*q.I() -  aj*q.J() -  ak*q.K();
00071    Scalar aqi = au*q.I() + ai*q.U() +  aj*q.K() -  ak*q.J();
00072    Scalar aqj = au*q.J() - ai*q.K() +  aj*q.U() +  ak*q.I();
00073    Scalar aqk = au*q.K() + ai*q.J() -  aj*q.I() +  ak*q.U();
00074    Scalar r = std::sqrt(aqi*aqi + aqj*aqj + aqk*aqk);
00075    if (r > 1) r = 1;
00076    if (aqu < 0) { aqu = - aqu; aqi = - aqi; aqj = - aqj, aqk = - aqk; }
00077    const Scalar angle = 2*asin ( r );
00078    DisplacementVector3D< Cartesian3D<double> > axis ( aqi, aqj, aqk );
00079    if ( r == 0 ) {
00080       axis.SetCoordinates(0,0,1);
00081    } else {
00082       axis /= r;
00083    }
00084    return AxisAngle ( axis, angle );
00085 }
00086 
00087 #endif
00088 
00089 AxisAngle AxisAngle::operator * (const RotationX & rx) const {
00090    // combination with RotationX
00091    
00092    const Scalar s1 = std::sin(fAngle/2);
00093    const Scalar au = std::cos(fAngle/2);
00094    const Scalar ai = s1 * fAxis.X();
00095    const Scalar aj = s1 * fAxis.Y();
00096    const Scalar ak = s1 * fAxis.Z();
00097    Scalar c  = rx.CosAngle();
00098    if ( c > 1  ) c =  1;
00099    if ( c < -1 ) c = -1;
00100    Scalar qu = std::sqrt( .5*(1+c) );
00101    Scalar qi = std::sqrt( .5*(1-c) );
00102    if ( rx.SinAngle() < 0 ) qi = -qi;
00103    Scalar aqu = au*qu - ai*qi;
00104    Scalar aqi = ai*qu + au*qi;
00105    Scalar aqj = aj*qu + ak*qi;
00106    Scalar aqk = ak*qu - aj*qi;
00107    Scalar r = std::sqrt(aqi*aqi + aqj*aqj + aqk*aqk);
00108    if (r > 1) r = 1;
00109    if (aqu < 0) { aqu = - aqu; aqi = - aqi; aqj = - aqj, aqk = - aqk; }
00110    const Scalar angle = 2*asin ( r );
00111    DisplacementVector3D< Cartesian3D<double> > axis ( aqi, aqj, aqk );
00112    if ( r == 0 ) {
00113       axis.SetCoordinates(0,0,1);
00114    } else {
00115       axis /= r;
00116    }
00117    return AxisAngle ( axis, angle );
00118 }
00119 
00120 AxisAngle AxisAngle::operator * (const RotationY & ry) const {
00121    // combination with RotationY
00122    
00123    const Scalar s1 = std::sin(fAngle/2);
00124    const Scalar au = std::cos(fAngle/2);
00125    const Scalar ai = s1 * fAxis.X();
00126    const Scalar aj = s1 * fAxis.Y();
00127    const Scalar ak = s1 * fAxis.Z();
00128    Scalar c  = ry.CosAngle();
00129    if ( c > 1  ) c =  1;
00130    if ( c < -1 ) c = -1;
00131    Scalar qu = std::sqrt( .5*(1+c) );
00132    Scalar qj = std::sqrt( .5*(1-c) );
00133    if ( ry.SinAngle() < 0 ) qj = -qj;
00134    Scalar aqu = au*qu - aj*qj;
00135    Scalar aqi = ai*qu - ak*qj;
00136    Scalar aqj = aj*qu + au*qj;
00137    Scalar aqk = ak*qu + ai*qj;
00138    Scalar r = std::sqrt(aqi*aqi + aqj*aqj + aqk*aqk);
00139    if (r > 1) r = 1;
00140    if (aqu < 0) { aqu = - aqu; aqi = - aqi; aqj = - aqj, aqk = - aqk; }
00141    const Scalar angle = 2*asin ( r );
00142    DisplacementVector3D< Cartesian3D<double> > axis ( aqi, aqj, aqk );
00143    if ( r == 0 ) {
00144       axis.SetCoordinates(0,0,1);
00145    } else {
00146       axis /= r;
00147    }
00148    return AxisAngle ( axis, angle );
00149 }
00150 
00151 AxisAngle AxisAngle::operator * (const RotationZ & rz) const {
00152    // combination with RotationZ
00153    
00154    const Scalar s1 = std::sin(fAngle/2);
00155    const Scalar au = std::cos(fAngle/2);
00156    const Scalar ai = s1 * fAxis.X();
00157    const Scalar aj = s1 * fAxis.Y();
00158    const Scalar ak = s1 * fAxis.Z();
00159    Scalar c  = rz.CosAngle();
00160    if ( c > 1  ) c =  1;
00161    if ( c < -1 ) c = -1;
00162    Scalar qu = std::sqrt( .5*(1+c) );
00163    Scalar qk = std::sqrt( .5*(1-c) );
00164    if ( rz.SinAngle() < 0 ) qk = -qk;
00165    Scalar aqu = au*qu - ak*qk;
00166    Scalar aqi = ai*qu + aj*qk;
00167    Scalar aqj = aj*qu - ai*qk;
00168    Scalar aqk = ak*qu + au*qk;
00169    Scalar r = std::sqrt(aqi*aqi + aqj*aqj + aqk*aqk);
00170    if (r > 1) r = 1;
00171    if (aqu < 0) { aqu = - aqu; aqi = - aqi; aqj = - aqj, aqk = - aqk; }
00172    const Scalar angle = 2*asin ( r );
00173    DisplacementVector3D< Cartesian3D<double> > axis ( aqi, aqj, aqk );
00174    if ( r == 0 ) {
00175       axis.SetCoordinates(0,0,1);
00176    } else {
00177       axis /= r;
00178    }
00179    return AxisAngle ( axis, angle );
00180 }
00181 
00182 AxisAngle operator*( RotationX const & r, AxisAngle const & a ) {
00183    return AxisAngle(r) * a;  // TODO: improve performance
00184 }
00185 
00186 AxisAngle operator*( RotationY const & r, AxisAngle const & a ) {
00187    return AxisAngle(r) * a;  // TODO: improve performance
00188 }
00189 
00190 AxisAngle operator*( RotationZ const & r, AxisAngle const & a ) {
00191    return AxisAngle(r) * a;  // TODO: improve performance
00192 }
00193 
00194 
00195 } //namespace Math
00196 } //namespace ROOT

Generated on Tue Jul 5 14:30:52 2011 for ROOT_528-00b_version by  doxygen 1.5.1