summaryrefslogtreecommitdiff
path: root/src/main/Particle.cc
diff options
context:
space:
mode:
authorJakob Odersky <jodersky@gmail.com>2011-04-17 20:05:38 +0000
committerJakob Odersky <jodersky@gmail.com>2011-04-17 20:05:38 +0000
commit964f0f8a7c88c1128c2edbef1fb36a86ed9864cf (patch)
tree38ef5ce1e578e7a40f3b08d30cee8666f0bea2e4 /src/main/Particle.cc
parent064e27d5e7bf451542cc89ee0a05a06447acdc88 (diff)
downloadvhc-964f0f8a7c88c1128c2edbef1fb36a86ed9864cf.tar.gz
vhc-964f0f8a7c88c1128c2edbef1fb36a86ed9864cf.tar.bz2
vhc-964f0f8a7c88c1128c2edbef1fb36a86ed9864cf.zip
Migration de tous les implementations dans les fichier .h vers les fichiers .cc
Diffstat (limited to 'src/main/Particle.cc')
-rw-r--r--src/main/Particle.cc69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/main/Particle.cc b/src/main/Particle.cc
index 2c24134..a3f80cd 100644
--- a/src/main/Particle.cc
+++ b/src/main/Particle.cc
@@ -9,4 +9,73 @@
namespace vhc {
+Particle::Particle(const Vector3D& position, double mass, double charge):
+ position(position),
+ velocity(0, 0, 0),
+ force(0, 0, 0),
+ mass(mass),
+ charge(charge)
+ //element(NULL)
+ {};
+
+
+Particle::Particle(const Vector3D& position, double mass, double charge, double energy, const Vector3D& direction):
+ position(position),
+ velocity(constants::C * sqrt(1 - (mass * mass * constants::C2 * constants::C2) / (energy * energy)) * direction.unit()),
+ gamma(energy / (mass * constants::C2)),
+ force(0, 0, 0),
+ mass(mass),
+ charge(charge)
+// element(NULL)
+ {};
+
+Vector3D Particle::getPosition() const {return position;}
+
+void Particle::setPosition(const Vector3D& pos) {position = pos;}
+
+Vector3D Particle::getForce() const {return force;}
+
+void Particle::setForce(const Vector3D& f) {force = f;}
+
+void Particle::applyForce(const Vector3D& f) {force = force + f;}
+
+void Particle::applyMagneticForce(const Vector3D& b, double dt) {
+ if (b != Vector3D::Null) {
+ Vector3D f = charge * velocity.cross(b);
+ force = force + f.rotate(velocity.cross(f), (dt * f.norm()) / (2 * gamma * mass * velocity.norm()));
+ }
}
+
+double Particle::getMass() const {return mass;}
+
+double Particle::getCharge() const {return charge;}
+
+
+Vector3D Particle::getVelocity() const {return velocity;}
+
+void Particle::setVelocity(const Vector3D& v) {
+ velocity = v;
+ gamma = 1.0 / sqrt(1.0 - v.normSquare() / constants::C2);
+}
+
+double Particle::getEnergy() const {return gamma * mass * constants::C2;}
+
+double Particle::getGamma() const {return gamma;}
+
+std::string Particle::toString() const {
+ std::stringstream s;
+ s << "Particle:" << "\n";
+ s << "\tposition: " << position << "\n";
+ s << "\tvelocity: " << velocity << "\n";
+ s << "\t|v|: " << velocity.norm() << "\n";
+ s << "\tgamma: " << gamma << "\n";
+ s << "\tmass: " << mass << "\n";
+ s << "\tcharge: " << charge << "\n";
+ s << "\tforce: " << force;
+ return s.str();
+}
+
+Particle* Particle::clone() const {return new Particle(*this);}
+
+
+} //vhc