Logo ROOT  
Reference Guide
AxisAngle.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 class AxisAngle, a rotation in 3 dimensions
12 // represented by its axis and angle of rotation
13 //
14 // Created by: Mark Fischler Tues July 5 2005
15 //
17 
18 #include <cmath>
19 #include <algorithm>
20 
24 
25 namespace ROOT {
26 
27 namespace Math {
28 
29 // ========== Constructors and Assignment =====================
30 
32  // Note: We could require the angle to be in [0,pi) since we
33  // can represent negative angles by flipping the axis.
34  // We choose not to do this.
35 
36  if ( fAngle <= Pi() && fAngle > -Pi() ) return;
37 
38  if ( fAngle > 0 ) {
39  int n = static_cast<int>( (fAngle+Pi())/(2*Pi()) );
40  fAngle -= 2*Pi()*n;
41  } else {
42  int n = static_cast<int>( -(fAngle-Pi())/(2*Pi()) );
43  fAngle += 2*Pi()*n;
44  }
45 } // RectifyAngle()
46 
48 {
49  // The two conditions are that the angle is in (-pi, pi] and
50  // the axis is a unit vector.
51 
52  Scalar r2 = fAxis.Mag2();
53  if ( r2 == 0 ) {
54  fAxis.SetCoordinates(0,0,1);
55  fAngle = 0;
56  return;
57  }
58  fAxis *= (1.0/r2);
59  RectifyAngle();
60 } // Rectify()
61 
62 // ======== Transformation to other Rotation Forms ==================
63 
65  kXX = 0, kXY = 1, kXZ = 2
66  , kYX = 3, kYY = 4, kYZ = 5
67  , kZX = 6, kZY = 7, kZZ = 8
68 };
69 
70 
71 
72 // ========== Operations =====================
73 
74 DisplacementVector3D< Cartesian3D<double> >
76 operator() (const DisplacementVector3D< Cartesian3D<double> > & v) const
77 {
80  Scalar p = fAxis.Dot(v) * ( 1 - c );
81  return DisplacementVector3D< Cartesian3D<double> >
82  (
83  c*v.X() + p*fAxis.X() + s * (fAxis.Y()*v.Z() - fAxis.Z()*v.Y())
84  , c*v.Y() + p*fAxis.Y() + s * (fAxis.Z()*v.X() - fAxis.X()*v.Z())
85  , c*v.Z() + p*fAxis.Z() + s * (fAxis.X()*v.Y() - fAxis.Y()*v.X())
86  );
87 }
88 
89 // ========== I/O =====================
90 
91 std::ostream & operator<< (std::ostream & os, const AxisAngle & a) {
92  // TODO - this will need changing for machine-readable issues
93  // and even the human readable form may need formatiing improvements
94  os << "\n" << a.Axis() << " " << a.Angle() << "\n";
95  return os;
96 }
97 
98 
99 
100 } //namespace Math
101 } //namespace ROOT
ROOT::Math::DisplacementVector3D::Mag2
Scalar Mag2() const
Magnitute squared ( r^2 in spherical coordinate)
Definition: DisplacementVector3D.h:324
c
#define c(i)
Definition: RSha256.hxx:101
n
const Int_t n
Definition: legend1.C:16
ROOT::Math::AxisAngle
AxisAngle class describing rotation represented with direction axis (3D Vector) and an angle of rotat...
Definition: AxisAngle.h:41
ROOT::Math::kZX
@ kZX
Definition: AxisAngle.cxx:67
ROOT::Math::AxisAngle::Pi
static double Pi()
Definition: AxisAngle.h:308
ROOT::Math::AxisAngle::Rectify
void Rectify()
Re-adjust components to eliminate small deviations from the axis being a unit vector and angles out o...
Definition: AxisAngle.cxx:47
ROOT::Math::kZY
@ kZY
Definition: AxisAngle.cxx:67
ROOT::Math::kYZ
@ kYZ
Definition: AxisAngle.cxx:66
TGeant4Unit::s
static constexpr double s
Definition: TGeant4SystemOfUnits.h:162
ROOT::Math::AxisAngle::operator()
XYZVector operator()(const XYZVector &v) const
sin
double sin(double)
ROOT::Math::operator<<
std::ostream & operator<<(std::ostream &os, const AxisAngle &a)
Stream Output and Input.
Definition: AxisAngle.cxx:91
cos
double cos(double)
ROOT::Math::DisplacementVector3D::SetCoordinates
DisplacementVector3D< CoordSystem, Tag > & SetCoordinates(const Scalar src[])
Set internal data based on a C-style array of 3 Scalar numbers.
Definition: DisplacementVector3D.h:198
ROOT::Math::DisplacementVector3D::Y
Scalar Y() const
Cartesian Y, converting if necessary from internal coordinate system.
Definition: DisplacementVector3D.h:287
ROOT::Math::kXZ
@ kXZ
Definition: AxisAngle.cxx:65
ROOT::Math::kYY
@ kYY
Definition: AxisAngle.cxx:66
v
@ v
Definition: rootcling_impl.cxx:3635
ROOT::Math::AxisAngle::fAngle
Scalar fAngle
Definition: AxisAngle.h:304
ROOT::Math::kYX
@ kYX
Definition: AxisAngle.cxx:66
Cartesian3D.h
ROOT::Math::AxisAngle::fAxis
AxisVector fAxis
Definition: AxisAngle.h:303
a
auto * a
Definition: textangle.C:12
ROOT::Math::DisplacementVector3D::X
Scalar X() const
Cartesian X, converting if necessary from internal coordinate system.
Definition: DisplacementVector3D.h:282
AxisAngle.h
ROOT::Math::DisplacementVector3D::Z
Scalar Z() const
Cartesian Z, converting if necessary from internal coordinate system.
Definition: DisplacementVector3D.h:292
Rotation3D.h
DisplacementVector3D.h
ROOT::Math::AxisAngle::Scalar
double Scalar
Definition: AxisAngle.h:45
ROOT::Math::ERotation3DMatrixIndex
ERotation3DMatrixIndex
Definition: AxisAngle.cxx:64
ROOT::Math::kXX
@ kXX
Definition: AxisAngle.cxx:65
ROOT::Math::kXY
@ kXY
Definition: AxisAngle.cxx:65
ROOT::Math::AxisAngle::RectifyAngle
void RectifyAngle()
Definition: AxisAngle.cxx:31
ROOT::Math::DisplacementVector3D::Dot
Scalar Dot(const DisplacementVector3D< OtherCoords, Tag > &v) const
Return the scalar (dot) product of two displacement vectors.
Definition: DisplacementVector3D.h:404
ROOT::Math::kZZ
@ kZZ
Definition: AxisAngle.cxx:67
ROOT
VSD Structures.
Definition: StringConv.hxx:21
Math
Namespace for new Math classes and functions.