CLHEP VERSION Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

RotationA.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 // ---------------------------------------------------------------------------
3 //
4 // This file is a part of the CLHEP - a Class Library for High Energy Physics.
5 //
6 // This is the implementation of those methods of the HepRotation class which
7 // were introduced when ZOOM PhysicsVectors was merged in, and which involve
8 // the angle/axis representation of a Rotation.
9 //
10 
11 #ifdef GNUPRAGMA
12 #pragma implementation
13 #endif
14 
15 #include "CLHEP/Vector/defs.h"
16 #include "CLHEP/Vector/Rotation.h"
17 #include "CLHEP/Units/PhysicalConstants.h"
18 
19 #include <iostream>
20 #include <cmath>
21 
22 namespace CLHEP {
23 
24 // ---------- Constructors and Assignment:
25 
26 // axis and angle
27 
28 HepRotation & HepRotation::set( const Hep3Vector & aaxis, double ddelta ) {
29 
30  register double sinDelta = std::sin(ddelta), cosDelta = std::cos(ddelta);
31  register double oneMinusCosDelta = 1.0 - cosDelta;
32 
33  Hep3Vector u = aaxis.unit();
34 
35  register double uX = u.getX();
36  register double uY = u.getY();
37  register double uZ = u.getZ();
38 
39  rxx = oneMinusCosDelta * uX * uX + cosDelta;
40  rxy = oneMinusCosDelta * uX * uY - sinDelta * uZ;
41  rxz = oneMinusCosDelta * uX * uZ + sinDelta * uY;
42 
43  ryx = oneMinusCosDelta * uY * uX + sinDelta * uZ;
44  ryy = oneMinusCosDelta * uY * uY + cosDelta;
45  ryz = oneMinusCosDelta * uY * uZ - sinDelta * uX;
46 
47  rzx = oneMinusCosDelta * uZ * uX - sinDelta * uY;
48  rzy = oneMinusCosDelta * uZ * uY + sinDelta * uX;
49  rzz = oneMinusCosDelta * uZ * uZ + cosDelta;
50 
51  return *this;
52 
53 } // HepRotation::set(axis, delta)
54 
55 HepRotation::HepRotation ( const Hep3Vector & aaxis, double ddelta )
56 {
57  set( aaxis, ddelta );
58 }
60  return set ( ax.axis(), ax.delta() );
61 }
63 {
64  set ( ax.axis(), ax.delta() );
65 }
66 
67 
68 
69 double HepRotation::delta() const {
70 
71  double cosdelta = (rxx + ryy + rzz - 1.0) / 2.0;
72  if (cosdelta > 1.0) {
73  return 0;
74  } else if (cosdelta < -1.0) {
75  return CLHEP::pi;
76  } else {
77  return std::acos( cosdelta ); // Already safe due to the cosdelta > 1 check
78  }
79 
80 } // delta()
81 
83 
84  // Determine 2*std::sin(delta) times the u components (I call this uX, uY, Uz)
85  // Normalization is not needed; it will be done when returning the 3-Vector
86 
87  double Uz = ryx - rxy;
88  double Uy = rxz - rzx;
89  double Ux = rzy - ryz;
90 
91  if ( (Uz==0) && (Uy==0) && (Ux==0) ) {
92  if ( rzz>0 ) {
93  return Hep3Vector(0,0,1);
94  } else if ( ryy>0 ) {
95  return Hep3Vector(0,1,0);
96  } else {
97  return Hep3Vector(1,0,0);
98  }
99  } else {
100  return Hep3Vector( Ux, Uy, Uz ).unit();
101  }
102 
103 } // axis()
104 
106 
107  return HepAxisAngle (axis(), delta());
108 
109 } // axisAngle()
110 
111 
112 void HepRotation::setAxis (const Hep3Vector & aaxis) {
113  set ( aaxis, delta() );
114 }
115 
116 void HepRotation::setDelta (double ddelta) {
117  set ( axis(), ddelta );
118 }
119 
120 } // namespace CLHEP
CLHEP::HepAxisAngle
Definition: Geometry/CLHEP/Vector/AxisAngle.h:37
CLHEP::HepRotation::delta
double delta() const
Definition: RotationA.cc:69
CLHEP::HepAxisAngle::axis
Hep3Vector axis() const
CLHEP::Hep3Vector::unit
Hep3Vector unit() const
CLHEP::Hep3Vector::getY
double getY() const
CLHEP::HepRotation::rxx
double rxx
Definition: Geometry/CLHEP/Vector/Rotation.h:389
CLHEP::HepRotation::rxz
double rxz
Definition: Geometry/CLHEP/Vector/Rotation.h:389
CLHEP::Hep3Vector::getX
double getX() const
CLHEP::HepRotation::setAxis
void setAxis(const Hep3Vector &axis)
Definition: RotationA.cc:112
CLHEP::HepRotation::HepRotation
HepRotation()
CLHEP::HepRotation
Definition: Geometry/CLHEP/Vector/Rotation.h:48
CLHEP::HepRotation::ryz
double ryz
Definition: Geometry/CLHEP/Vector/Rotation.h:390
CLHEP::HepRotation::rxy
double rxy
Definition: Geometry/CLHEP/Vector/Rotation.h:389
CLHEP
Definition: ClhepVersion.h:13
CLHEP::HepRotation::setDelta
void setDelta(double delta)
Definition: RotationA.cc:116
CLHEP::HepRotation::rzy
double rzy
Definition: Geometry/CLHEP/Vector/Rotation.h:391
CLHEP::HepRotation::ryy
double ryy
Definition: Geometry/CLHEP/Vector/Rotation.h:390
CLHEP::HepRotation::axisAngle
HepAxisAngle axisAngle() const
Definition: RotationA.cc:105
Hep3Vector
Issues Concerning the PhysicsVectors CLHEP Vector Merge The merge of ZOOM PhysicsVdectors and the CLHEP Vector package is completed The purpose of this document is to list the major issues that affected the merge of these and where relevant describe the resolutions More detailed documents describe more minor issues General Approach As agreed at the June CLHEP the approach is to combine the features of each ZOOM class with the corresponding CLHEP class expanding the interface to create a single lingua franca of what a Hep3Vector(for example) means. We are not forming SpaceVector as an class derived from Hep3Vector and enhancing it in that way. Another rule imposed by the agreement is to avoid using the Exceptions package(even though that will later go into CLHEP for other uses). A desirable goal is to avoid cluttering the interface and enlarging the code linked in when ordinary CLHEP Vector functionallity is used. To this end
CLHEP::Hep3Vector
Definition: Geometry/CLHEP/Vector/ThreeVector.h:41
CLHEP::HepRotation::axis
Hep3Vector axis() const
Definition: RotationA.cc:82
CLHEP::HepRotation::set
HepRotation & set(const Hep3Vector &axis, double delta)
Definition: RotationA.cc:28
CLHEP::HepRotation::rzz
double rzz
Definition: Geometry/CLHEP/Vector/Rotation.h:391
CLHEP::HepAxisAngle::delta
double delta() const
CLHEP::HepRotation::rzx
double rzx
Definition: Geometry/CLHEP/Vector/Rotation.h:391
CLHEP::HepRotation::ryx
double ryx
Definition: Geometry/CLHEP/Vector/Rotation.h:390
CLHEP::Hep3Vector::getZ
double getZ() const
HepGeom::BasicVector3D::unit
BasicVector3D< T > unit() const
Definition: CLHEP/Geometry/BasicVector3D.h:305