AxisAngle.cxx

Go to the documentation of this file.
00001 // @(#)root/mathcore:$Id: AxisAngle.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 class AxisAngle, a rotation in 3 dimensions
00012 // represented by its axis and angle of rotation
00013 //
00014 // Created by: Mark Fischler Tues July 5  2005
00015 //
00016 #include "Math/GenVector/AxisAngle.h"
00017 
00018 #include <cmath>
00019 #include <algorithm>
00020 
00021 #include "Math/GenVector/Cartesian3D.h"
00022 #include "Math/GenVector/DisplacementVector3D.h"
00023 #include "Math/GenVector/Rotation3D.h"
00024 
00025 namespace ROOT {
00026 
00027 namespace Math {
00028 
00029 // ========== Constructors and Assignment =====================
00030 
00031 void AxisAngle::RectifyAngle() {
00032    // Note: We could require the angle to be in [0,pi) since we 
00033    //       can represent negative angles by flipping the axis.
00034    //       We choose not to do this.
00035    
00036    if ( fAngle <= Pi() && fAngle > -Pi() ) return;
00037    
00038    if ( fAngle > 0 ) {
00039       int n = static_cast<int>( (fAngle+Pi())/(2*Pi()) );
00040       fAngle -= 2*Pi()*n;
00041    } else {
00042       int n = static_cast<int>( -(fAngle-Pi())/(2*Pi()) );
00043       fAngle += 2*Pi()*n;  
00044    }
00045 } // RectifyAngle()
00046 
00047 void AxisAngle::Rectify()
00048 {
00049    // The two conditions are that the angle is in (-pi, pi] and 
00050    // the axis is a unit vector.
00051    
00052    Scalar r2 = fAxis.Mag2();
00053    if ( r2 == 0 ) {
00054       fAxis.SetCoordinates(0,0,1);
00055       fAngle = 0;
00056       return;
00057    }
00058    fAxis *= (1.0/r2);
00059    RectifyAngle();  
00060 } // Rectify()
00061 
00062 // ======== Transformation to other Rotation Forms ==================
00063 
00064 enum ERotation3DMatrixIndex {
00065    kXX = 0, kXY = 1, kXZ = 2
00066    , kYX = 3, kYY = 4, kYZ = 5
00067    , kZX = 6, kZY = 7, kZZ = 8
00068 };
00069 
00070 
00071 
00072 // ========== Operations =====================
00073 
00074 DisplacementVector3D< Cartesian3D<double> >
00075 AxisAngle::
00076 operator() (const DisplacementVector3D< Cartesian3D<double> > & v) const
00077 {
00078    Scalar c = std::cos(fAngle);
00079    Scalar s = std::sin(fAngle);
00080    Scalar p = fAxis.Dot(v) * ( 1 - c );
00081    return  DisplacementVector3D< Cartesian3D<double> >  
00082       (
00083        c*v.X() + p*fAxis.X() + s * (fAxis.Y()*v.Z() - fAxis.Z()*v.Y())
00084        , c*v.Y() + p*fAxis.Y() + s * (fAxis.Z()*v.X() - fAxis.X()*v.Z())
00085        , c*v.Z() + p*fAxis.Z() + s * (fAxis.X()*v.Y() - fAxis.Y()*v.X())
00086        );
00087 }
00088 
00089 // ========== I/O =====================
00090 
00091 std::ostream & operator<< (std::ostream & os, const AxisAngle & a) {
00092    // TODO - this will need changing for machine-readable issues
00093    //        and even the human readable form may need formatiing improvements
00094    os << "\n" << a.Axis() << "  " << a.Angle() << "\n"; 
00095    return os;
00096 }
00097 
00098 
00099 
00100 } //namespace Math
00101 } //namespace ROOT

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