Logo ROOT   6.08/07
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 
77 {
79  Scalar s = std::sin(fAngle);
80  Scalar p = fAxis.Dot(v) * ( 1 - c );
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
ERotation3DMatrixIndex
Definition: AxisAngle.cxx:64
DisplacementVector3D< CoordSystem, Tag > & SetCoordinates(const Scalar src[])
Set internal data based on a C-style array of 3 Scalar numbers.
This namespace contains pre-defined functions to be used in conjuction with TExecutor::Map and TExecu...
Definition: StringConv.hxx:21
return c
TArc * a
Definition: textangle.C:12
double cos(double)
std::ostream & operator<<(std::ostream &os, const AxisAngle &a)
Stream Output and Input.
Definition: AxisAngle.cxx:91
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.
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)
AxisVector Axis() const
accesss to rotation axis
Definition: AxisAngle.h:183
void Rectify()
Re-adjust components to eliminate small deviations from the axis being a unit vector and angles out o...
Definition: AxisAngle.cxx:47
Class describing a generic displacement vector in 3 dimensions.
Scalar Angle() const
access to rotation angle
Definition: AxisAngle.h:188
SVector< double, 2 > v
Definition: Dict.h:5
XYZVector operator()(const XYZVector &v) const
Namespace for new Math classes and functions.
Scalar Mag2() const
Magnitute squared ( r^2 in spherical coordinate)
Plane3D::Scalar Scalar
Definition: Plane3D.cxx:29
const Int_t n
Definition: legend1.C:16
static double Pi()
Definition: AxisAngle.h:314
unsigned int r2[N_CITIES]
Definition: simanTSP.cxx:322
Scalar Dot(const DisplacementVector3D< OtherCoords, Tag > &v) const
Return the scalar (dot) product of two displacement vectors.