Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4INCLThreeVector.hh
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26// INCL++ intra-nuclear cascade model
27// Pekka Kaitaniemi, CEA and Helsinki Institute of Physics
28// Davide Mancusi, CEA
29// Alain Boudard, CEA
30// Sylvie Leray, CEA
31// Joseph Cugnon, University of Liege
32//
33// INCL++ revision: v5.1.8
34//
35#define INCLXX_IN_GEANT4_MODE 1
36
37#include "globals.hh"
38
39/*
40 * ThreeVector.hh
41 *
42 * \date 4 June 2009
43 * \author Pekka Kaitaniemi
44 */
45
46#ifndef G4INCLThreeVector_hh
47#define G4INCLThreeVector_hh 1
48
49#include <string>
50#include <sstream>
51#include <cmath>
52
53namespace G4INCL {
54
56 public:
58 :x(0.0), y(0.0), z(0.0)
59 {}
60
62 :x(ax), y(ay), z(az)
63 {}
64
65 inline G4double getX() const { return x; }
66 inline G4double getY() const { return y; }
67 inline G4double getZ() const { return z; }
68
69 inline G4double perp() const { return std::sqrt(x*x + y*y); }
70 inline G4double perp2() const { return x*x + y*y; }
71 /**
72 * Get the length of the vector.
73 */
74 inline G4double mag() const { return std::sqrt(x*x + y*y + z*z); }
75
76 /**
77 * Get the square of the length.
78 */
79 inline G4double mag2() const { return (x*x + y*y + z*z); }
80
81 /**
82 * Theta angle
83 */
84 inline G4double theta() const {
85 return x == 0.0 && y == 0.0 && z == 0.0 ? 0.0 : std::atan2(perp(),z);
86 }
87
88 /**
89 * Phi angle
90 */
91 inline G4double phi() const {
92 return x == 0.0 && y == 0.0 ? 0.0 : std::atan2(y,x);
93 }
94
95 /**
96 * Dot product.
97 */
98 inline G4double dot(const ThreeVector &v) const {
99 return (x*v.x + y*v.y + z*v.z);
100 }
101
102 /**
103 * Vector product.
104 */
106 return ThreeVector(
107 y*v.z - z*v.y,
108 z*v.x - x*v.z,
109 x*v.y - y*v.x
110 );
111 }
112
113 /// \brief Set the x coordinate
114 inline void setX(G4double ax) { x = ax; }
115
116 /// \brief Set the y coordinate
117 inline void setY(G4double ay) { y = ay; }
118
119 /// \brief Set the z coordinate
120 inline void setZ(G4double az) { z = az; }
121
122 inline void operator+= (const ThreeVector &v) {
123 x += v.x;
124 y += v.y;
125 z += v.z;
126 }
127
128 /// \brief Unary minus operator
129 inline ThreeVector operator- () const {
130 return ThreeVector(-x,-y,-z);
131 }
132
133 inline void operator-= (const ThreeVector &v) {
134 x -= v.x;
135 y -= v.y;
136 z -= v.z;
137 }
138
139 template<typename T>
140 inline void operator*= (const T c) {
141 x *= c;
142 y *= c;
143 z *= c;
144 }
145
146 template<typename T>
147 inline void operator/= (const T c) {
148 x /= c;
149 y /= c;
150 z /= c;
151 }
152
153 inline ThreeVector operator- (const ThreeVector &v) const {
154 return ThreeVector(x-v.x, y-v.y, z-v.z);
155 }
156
157 inline ThreeVector operator+ (const ThreeVector &v) const {
158 return ThreeVector(x+v.x, y+v.y, z+v.z);
159 }
160
161 /**
162 * Divides all components of the vector with a constant number.
163 */
164 inline ThreeVector operator/ (const G4double C) const {
165 return ThreeVector(x/C, y/C, z/C);
166 }
167
168 inline ThreeVector operator* (const G4double C) const {
169 return ThreeVector(x*C, y*C, z*C);
170 }
171
172 /** \brief Rotate the vector by a given angle around a given axis
173 *
174 * \param angle the rotation angle
175 * \param axis the rotation axis, which must be a unit vector
176 */
177 inline void rotate(const G4double angle, const ThreeVector &axis) {
178 // Use Rodrigues' formula
179 const G4double cos = std::cos(angle);
180 const G4double sin = std::sin(angle);
181 (*this) = (*this) * cos + axis.vector(*this) * sin + axis * (axis.dot(*this)*(1.-cos));
182 }
183
184 std::string print() const {
185 std::stringstream ss;
186 ss <<"(x = " << x << " y = " << y << " z = " << z <<")";
187 return ss.str();
188 }
189
190 std::string dump() const {
191 std::stringstream ss;
192 ss <<"(vector3 " << x << " " << y << " " << z << ")";
193 return ss.str();
194 }
195
196 private:
197 G4double x, y, z; //> Vector components
198 };
199
200}
201
202#endif
double G4double
Definition: G4Types.hh:64
void setY(G4double ay)
Set the y coordinate.
G4double theta() const
G4double getY() const
ThreeVector operator*(const G4double C) const
G4double getZ() const
void operator+=(const ThreeVector &v)
std::string dump() const
void setZ(G4double az)
Set the z coordinate.
ThreeVector operator-() const
Unary minus operator.
void setX(G4double ax)
Set the x coordinate.
G4double mag() const
G4double phi() const
void operator*=(const T c)
G4double perp2() const
std::string print() const
void rotate(const G4double angle, const ThreeVector &axis)
Rotate the vector by a given angle around a given axis.
G4double perp() const
void operator/=(const T c)
ThreeVector(G4double ax, G4double ay, G4double az)
ThreeVector operator+(const ThreeVector &v) const
G4double dot(const ThreeVector &v) const
G4double mag2() const
void operator-=(const ThreeVector &v)
G4double getX() const
ThreeVector operator/(const G4double C) const
ThreeVector vector(const ThreeVector &v) const