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
22namespace CLHEP {
23
24// ---------- Constructors and Assignment:
25
26// axis and angle
27
28HepRotation & 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
55HepRotation::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
69double 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
112void HepRotation::setAxis (const Hep3Vector & aaxis) {
113 set ( aaxis, delta() );
114}
115
116void HepRotation::setDelta (double ddelta) {
117 set ( axis(), ddelta );
118}
119
120} // namespace CLHEP
Hep3Vector unit() const
double getZ() const
double getX() const
double getY() const
double delta() const
Hep3Vector axis() const
HepAxisAngle axisAngle() const
Definition RotationA.cc:105
Hep3Vector axis() const
Definition RotationA.cc:82
double delta() const
Definition RotationA.cc:69
HepRotation & set(const Hep3Vector &axis, double delta)
Definition RotationA.cc:28
void setDelta(double delta)
Definition RotationA.cc:116
void setAxis(const Hep3Vector &axis)
Definition RotationA.cc:112