Logo ROOT   6.14/05
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 {
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.
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
Class describing a 3D cartesian coordinate system (x, y, z coordinates)
Definition: Cartesian3D.h:44
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
auto * a
Definition: textangle.C:12
XYZVector operator()(const XYZVector &v) const
static constexpr double s
Namespace for new Math classes and functions.
#define c(i)
Definition: RSha256.hxx:101
Scalar Mag2() const
Magnitute squared ( r^2 in spherical coordinate)
Rotation3D::Scalar Scalar
const Int_t n
Definition: legend1.C:16
static double Pi()
Definition: AxisAngle.h:314
Scalar Dot(const DisplacementVector3D< OtherCoords, Tag > &v) const
Return the scalar (dot) product of two displacement vectors.