summaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorJakob Odersky <jodersky@gmail.com>2011-03-23 13:31:54 +0000
committerJakob Odersky <jodersky@gmail.com>2011-03-23 13:31:54 +0000
commitece55da410b6ea473602ff963d8edaf360b6961b (patch)
tree06be62c8a8d3386805b2aa7493459847df0751b7 /src/main
parent4bf517228e71f602f31ed68136479b96f4d40e23 (diff)
downloadvhc-ece55da410b6ea473602ff963d8edaf360b6961b.tar.gz
vhc-ece55da410b6ea473602ff963d8edaf360b6961b.tar.bz2
vhc-ece55da410b6ea473602ff963d8edaf360b6961b.zip
Implemente element courbe. Ajoute `virtual' a toutes les methodes virtuelles heritees.
Diffstat (limited to 'src/main')
-rw-r--r--src/main/Curved.cc13
-rw-r--r--src/main/Curved.h26
-rw-r--r--src/main/Element.cc1
-rw-r--r--src/main/Particle.h2
-rw-r--r--src/main/Vector3D.h7
5 files changed, 32 insertions, 17 deletions
diff --git a/src/main/Curved.cc b/src/main/Curved.cc
index 35b1de2..0523c08 100644
--- a/src/main/Curved.cc
+++ b/src/main/Curved.cc
@@ -5,21 +5,10 @@
* Author: jakob
*/
+#include <math.h>
#include "Curved.h"
namespace vhc {
-Curved::Curved(const Vector3D& entry, const Vector3D& exit, double sectionRadius, double curvatureRadius, Element* next = NULL):
- Element(entry, exit, sectionRadius, next),
- centerOfCurvature(Vector3D::Null) {
-
- Vector3D bisector = getDiagonal().cross(Vector3D::k);
- double halfLength = (getDiagonal() / 2).norm();
- Vector3D midpoint = getEntryPosition() + getDiagonal() / 2;
-
- centerOfCurvature = midpoint + bisector.unit() * copysign(
- sqrt(curvatureRadius * curvatureRadius - halfLength * halfLength),
- curvatureRadius);
-};
}
diff --git a/src/main/Curved.h b/src/main/Curved.h
index e37a017..d2f2c5e 100644
--- a/src/main/Curved.h
+++ b/src/main/Curved.h
@@ -9,7 +9,9 @@
#define CURVED_H_
#include <math.h>
+//#include <cmath.h>
#include "Element.h"
+#include "Particle.h"
#include "Vector3D.h"
namespace vhc {
@@ -19,11 +21,31 @@ class Curved: public Element {
protected:
- Vector3D centerOfCurvature;
+ Vector3D curvatureCenter;
+ double curvature;
public:
- Curved(const Vector3D& entry, const Vector3D& exit, double sectionRadius, double curvatureRadius, Element* next);
+ Curved(const Vector3D& entry, const Vector3D& exit, double sectionRadius, double curvature, Element* next = NULL):
+ Element(entry, exit, sectionRadius, next),
+ curvature(curvature),
+ curvatureCenter(Vector3D::Null) {
+
+ double k = curvature;
+ Vector3D midpoint = (getEntryPosition() + getExitPosition())/ 2;
+ curvatureCenter = midpoint + sqrt(1.0 - (k * k) / 4 * getDiagonal().normSquare()) * (getDiagonal().unit().cross(Vector3D::k));
+ };
+
+ virtual bool isOutside(const Particle& particle) const {
+ Vector3D x(particle.getPosition() - getEntryPosition());
+ return (x - Vector3D(x.getX(), x.getY(), 0).unit() / fabs(curvature)).norm() > sectionRadius;
+ }
+
+ virtual bool isPast(const Particle& particle) const {
+ Vector3D out = (getEntryPosition() - curvatureCenter).cross(getExitPosition() - curvatureCenter).cross(getEntryPosition() - curvatureCenter);
+ return (particle.getPosition() - getExitPosition()).dot(out) > 0;
+ }
+
};
}
diff --git a/src/main/Element.cc b/src/main/Element.cc
index f1e1154..ef1302a 100644
--- a/src/main/Element.cc
+++ b/src/main/Element.cc
@@ -5,6 +5,7 @@
* Author: jakob
*/
+
#include "Element.h"
namespace vhc {
diff --git a/src/main/Particle.h b/src/main/Particle.h
index d14def2..e6ee44f 100644
--- a/src/main/Particle.h
+++ b/src/main/Particle.h
@@ -92,7 +92,7 @@ public:
double getGamma() const {return energy / (mass * constants::c2);}
/** Retourne une représentation en chaîne de cette particule. */
- std::string toString() const {
+ virtual std::string toString() const {
std::stringstream s;
s << "Particle:" << "\n";
s << "\tPosition: " << position << "\n";
diff --git a/src/main/Vector3D.h b/src/main/Vector3D.h
index e2219d1..4325f7e 100644
--- a/src/main/Vector3D.h
+++ b/src/main/Vector3D.h
@@ -96,10 +96,13 @@ public:
Vector3D unit() const {return ~(*this);}
/** Retourne la norme du vecteur. */
- double norm() const {return sqrt(dot(*this));};
+ double norm() const {return sqrt(dot(*this));}
+
+ /** Retourne la norme du vecteur au carre. */
+ double normSquare() const {return dot(*this);}
/** Retourne une représentation en chaîne de caractères de ce vecteur. */
- std::string toString() const {
+ virtual std::string toString() const {
std::stringstream s;
s << "Vector3D(" << x << ", " << y << ", " << z << ")";
return s.str();