Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
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
17
18#include <iostream>
19#include <cmath>
20
21namespace CLHEP {
22
23// ---------- Constructors and Assignment:
24
25// axis and angle
26
27HepRotation & HepRotation::set( const Hep3Vector & aaxis, double ddelta ) {
28
29 register double sinDelta = std::sin(ddelta), cosDelta = std::cos(ddelta);
30 register double oneMinusCosDelta = 1.0 - cosDelta;
31
32 Hep3Vector u = aaxis.unit();
33
34 register double uX = u.getX();
35 register double uY = u.getY();
36 register double uZ = u.getZ();
37
38 rxx = oneMinusCosDelta * uX * uX + cosDelta;
39 rxy = oneMinusCosDelta * uX * uY - sinDelta * uZ;
40 rxz = oneMinusCosDelta * uX * uZ + sinDelta * uY;
41
42 ryx = oneMinusCosDelta * uY * uX + sinDelta * uZ;
43 ryy = oneMinusCosDelta * uY * uY + cosDelta;
44 ryz = oneMinusCosDelta * uY * uZ - sinDelta * uX;
45
46 rzx = oneMinusCosDelta * uZ * uX - sinDelta * uY;
47 rzy = oneMinusCosDelta * uZ * uY + sinDelta * uX;
48 rzz = oneMinusCosDelta * uZ * uZ + cosDelta;
49
50 return *this;
51
52} // HepRotation::set(axis, delta)
53
54HepRotation::HepRotation ( const Hep3Vector & aaxis, double ddelta )
55{
56 set( aaxis, ddelta );
57}
59 return set ( ax.axis(), ax.delta() );
60}
62{
63 set ( ax.axis(), ax.delta() );
64}
65
66double HepRotation::delta() const {
67
68 double cosdelta = (rxx + ryy + rzz - 1.0) / 2.0;
69 if (cosdelta > 1.0) {
70 return 0;
71 } else if (cosdelta < -1.0) {
72 return CLHEP::pi;
73 } else {
74 return std::acos( cosdelta ); // Already safe due to the cosdelta > 1 check
75 }
76
77} // delta()
78
80
81 // Determine 2*std::sin(delta) times the u components (I call this uX, uY, Uz)
82 // Normalization is not needed; it will be done when returning the 3-Vector
83
84 double Uz = ryx - rxy;
85 double Uy = rxz - rzx;
86 double Ux = rzy - ryz;
87
88 if ( (Uz==0) && (Uy==0) && (Ux==0) ) {
89 if ( rzz>0 ) {
90 return Hep3Vector(0,0,1);
91 } else if ( ryy>0 ) {
92 return Hep3Vector(0,1,0);
93 } else {
94 return Hep3Vector(1,0,0);
95 }
96 } else {
97 return Hep3Vector( Ux, Uy, Uz ).unit();
98 }
99
100} // axis()
101
103
104 return HepAxisAngle (axis(), delta());
105
106} // axisAngle()
107
108
109void HepRotation::setAxis (const Hep3Vector & aaxis) {
110 set ( aaxis, delta() );
111}
112
113void HepRotation::setDelta (double ddelta) {
114 set ( axis(), ddelta );
115}
116
117} // 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:102
Hep3Vector axis() const
Definition: RotationA.cc:79
double delta() const
Definition: RotationA.cc:66
HepRotation & set(const Hep3Vector &axis, double delta)
Definition: RotationA.cc:27
void setDelta(double delta)
Definition: RotationA.cc:113
void setAxis(const Hep3Vector &axis)
Definition: RotationA.cc:109
Definition: DoubConv.h:17