From ece55da410b6ea473602ff963d8edaf360b6961b Mon Sep 17 00:00:00 2001 From: Jakob Odersky Date: Wed, 23 Mar 2011 13:31:54 +0000 Subject: Implemente element courbe. Ajoute `virtual' a toutes les methodes virtuelles heritees. --- src/main/Curved.cc | 13 +------------ src/main/Curved.h | 26 ++++++++++++++++++++++++-- src/main/Element.cc | 1 + src/main/Particle.h | 2 +- src/main/Vector3D.h | 7 +++++-- 5 files changed, 32 insertions(+), 17 deletions(-) (limited to 'src/main') 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 #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 +//#include #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(); -- cgit v1.2.3