Geant4 11.2.2
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// Alain Boudard, CEA-Saclay, France
28// Joseph Cugnon, University of Liege, Belgium
29// Jean-Christophe David, CEA-Saclay, France
30// Pekka Kaitaniemi, CEA-Saclay, France, and Helsinki Institute of Physics, Finland
31// Sylvie Leray, CEA-Saclay, France
32// Davide Mancusi, CEA-Saclay, France
33//
34#define INCLXX_IN_GEANT4_MODE 1
35
36#include "globals.hh"
37
38/*
39 * ThreeVector.hh
40 *
41 * \date 4 June 2009
42 * \author Pekka Kaitaniemi
43 */
44
45#ifndef G4INCLThreeVector_hh
46#define G4INCLThreeVector_hh 1
47
48#include <string>
49#include <sstream>
50#include <cmath>
51
52namespace G4INCL {
53
55 public:
57 :x(0.0), y(0.0), z(0.0)
58 {}
59
61 :x(ax), y(ay), z(az)
62 {}
63
64 inline G4double getX() const { return x; }
65 inline G4double getY() const { return y; }
66 inline G4double getZ() const { return z; }
67
68 inline G4double perp() const { return std::sqrt(x*x + y*y); }
69 inline G4double perp2() const { return x*x + y*y; }
70 /**
71 * Get the length of the vector.
72 */
73 inline G4double mag() const { return std::sqrt(x*x + y*y + z*z); }
74
75 /**
76 * Get the square of the length.
77 */
78 inline G4double mag2() const { return (x*x + y*y + z*z); }
79
80 /**
81 * Theta angle
82 */
83 inline G4double theta() const {
84 return x == 0.0 && y == 0.0 && z == 0.0 ? 0.0 : std::atan2(perp(),z);
85 }
86
87 /**
88 * Phi angle
89 */
90 inline G4double phi() const {
91 return x == 0.0 && y == 0.0 ? 0.0 : std::atan2(y,x);
92 }
93
94 /**
95 * Dot product.
96 */
97 inline G4double dot(const ThreeVector &v) const {
98 return (x*v.x + y*v.y + z*v.z);
99 }
100
101 /**
102 * Vector product.
103 */
105 return ThreeVector(
106 y*v.z - z*v.y,
107 z*v.x - x*v.z,
108 x*v.y - y*v.x
109 );
110 }
111
112 /// \brief Set the x coordinate
113 inline void setX(G4double ax) { x = ax; }
114
115 /// \brief Set the y coordinate
116 inline void setY(G4double ay) { y = ay; }
117
118 /// \brief Set the z coordinate
119 inline void setZ(G4double az) { z = az; }
120
121 /// \brief Set all the coordinates
122 inline void set(const G4double ax, const G4double ay, const G4double az) { x=ax; y=ay; z=az; }
123
124 inline void operator+= (const ThreeVector &v) {
125 x += v.x;
126 y += v.y;
127 z += v.z;
128 }
129
130 /// \brief Unary minus operator
131 inline ThreeVector operator- () const {
132 return ThreeVector(-x,-y,-z);
133 }
134
135 inline void operator-= (const ThreeVector &v) {
136 x -= v.x;
137 y -= v.y;
138 z -= v.z;
139 }
140
141 template<typename T>
142 inline void operator*= (const T &c) {
143 x *= c;
144 y *= c;
145 z *= c;
146 }
147
148 template<typename T>
149 inline void operator/= (const T &c) {
150 const G4double oneOverC = 1./c;
151 this->operator*=(oneOverC);
152 }
153
154 inline ThreeVector operator- (const ThreeVector &v) const {
155 return ThreeVector(x-v.x, y-v.y, z-v.z);
156 }
157
158 inline ThreeVector operator+ (const ThreeVector &v) const {
159 return ThreeVector(x+v.x, y+v.y, z+v.z);
160 }
161
162 /**
163 * Divides all components of the vector with a constant number.
164 */
165 inline ThreeVector operator/ (const G4double C) const {
166 const G4double oneOverC = 1./C;
167 return ThreeVector(x*oneOverC, y*oneOverC, z*oneOverC);
168 }
169
170 inline ThreeVector operator* (const G4double C) const {
171 return ThreeVector(x*C, y*C, z*C);
172 }
173
174 /** \brief Rotate the vector by a given angle around a given axis
175 *
176 * \param angle the rotation angle
177 * \param axis the rotation axis, which must be a unit vector
178 */
179 inline void rotate(const G4double angle, const ThreeVector &axis) {
180 // Use Rodrigues' formula
181 const G4double cos = std::cos(angle);
182 const G4double sin = std::sin(angle);
183 (*this) = (*this) * cos + axis.vector(*this) * sin + axis * (axis.dot(*this)*(1.-cos));
184 }
185
186 /** \brief Return a vector orthogonal to this
187 *
188 * Simple algorithm from Hughes and Moeller, J. Graphics Tools 4 (1999)
189 * 33.
190 */
192 if(x<=y && x<=z)
193 return ThreeVector(0., -z, y);
194 else if(y<=x && y<=z)
195 return ThreeVector(-z, 0., x);
196 else
197 return ThreeVector(-y, x, 0.);
198 }
199
200 std::string print() const {
201 std::stringstream ss;
202 ss <<"(x = " << x << " y = " << y << " z = " << z <<")";
203 return ss.str();
204 }
205
206 std::string dump() const {
207 std::stringstream ss;
208 ss <<"(vector3 " << x << " " << y << " " << z << ")";
209 return ss.str();
210 }
211
212 private:
213 G4double x, y, z; //> Vector components
214 };
215
216}
217
218#endif
G4double C(G4double temp)
double G4double
Definition G4Types.hh:83
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 perp2() const
std::string print() const
void operator*=(const T &c)
void rotate(const G4double angle, const ThreeVector &axis)
Rotate the vector by a given angle around a given axis.
G4double perp() const
ThreeVector(G4double ax, G4double ay, G4double az)
ThreeVector operator+(const ThreeVector &v) const
G4double dot(const ThreeVector &v) const
void operator/=(const T &c)
G4double mag2() const
void operator-=(const ThreeVector &v)
G4double getX() const
ThreeVector anyOrthogonal() const
Return a vector orthogonal to this.
ThreeVector operator/(const G4double C) const
void set(const G4double ax, const G4double ay, const G4double az)
Set all the coordinates.
ThreeVector vector(const ThreeVector &v) const