TwoVector.icc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 // ---------------------------------------------------------------------------
00003 //
00004 // This file is a part of the CLHEP - a Class Library for High Energy Physics.
00005 // 
00006 // This is the definitions of the inline member functions of the
00007 // Hep2Vector class.
00008 //
00009 
00010 #include <cmath>
00011 
00012 namespace CLHEP {
00013 
00014 inline double Hep2Vector::x() const {
00015   return dx;
00016 }
00017 
00018 inline double Hep2Vector::y() const {
00019   return dy;
00020 }
00021 
00022 inline Hep2Vector::Hep2Vector(double x1, double y1)
00023 : dx(x1), dy(y1) {}
00024 
00025 inline Hep2Vector::Hep2Vector( const Hep3Vector & p)
00026 : dx(p.x()), dy(p.y()) {}
00027 
00028 inline void Hep2Vector::setX(double x1) {
00029   dx = x1;
00030 }
00031 
00032 inline void Hep2Vector::setY(double y1) {
00033   dy = y1;
00034 }
00035 
00036 inline void Hep2Vector::set(double x1, double y1) {
00037   dx = x1;
00038   dy = y1;
00039 }
00040 
00041 double & Hep2Vector::operator[] (int i)       { return operator()(i); }
00042 double   Hep2Vector::operator[] (int i) const { return operator()(i); }
00043 
00044 inline Hep2Vector::Hep2Vector(const Hep2Vector & p)
00045 : dx(p.x()), dy(p.y()) {}
00046 
00047 inline Hep2Vector::~Hep2Vector() {}
00048 
00049 inline Hep2Vector & Hep2Vector::operator = (const Hep2Vector & p) {
00050   dx = p.x();
00051   dy = p.y();
00052   return *this;
00053 }
00054 
00055 inline bool Hep2Vector::operator == (const Hep2Vector& v) const {
00056   return (v.x()==x() && v.y()==y()) ? true : false;
00057 }
00058 
00059 inline bool Hep2Vector::operator != (const Hep2Vector& v) const {
00060   return (v.x()!=x() || v.y()!=y()) ? true : false;
00061 }
00062 
00063 inline Hep2Vector& Hep2Vector::operator += (const Hep2Vector & p) {
00064   dx += p.x();
00065   dy += p.y();
00066   return *this;
00067 }
00068 
00069 inline Hep2Vector& Hep2Vector::operator -= (const Hep2Vector & p) {
00070   dx -= p.x();
00071   dy -= p.y();
00072   return *this;
00073 }
00074 
00075 inline Hep2Vector Hep2Vector::operator - () const {
00076   return Hep2Vector(-dx, -dy);
00077 }
00078 
00079 inline Hep2Vector& Hep2Vector::operator *= (double a) {
00080   dx *= a;
00081   dy *= a;
00082   return *this;
00083 }
00084 
00085 inline double Hep2Vector::dot(const Hep2Vector & p) const {
00086   return dx*p.x() + dy*p.y();
00087 }
00088 
00089 inline double Hep2Vector::mag2() const {
00090   return dx*dx + dy*dy;
00091 }
00092 
00093 inline double Hep2Vector::mag() const {
00094   return std::sqrt(mag2());
00095 }
00096 
00097 inline double Hep2Vector::r() const {
00098   return std::sqrt(mag2());
00099 }
00100 
00101 inline Hep2Vector Hep2Vector::unit() const {
00102   double tot = mag2();
00103   Hep2Vector p(*this);
00104   return tot > 0.0 ? p *= (1.0/std::sqrt(tot)) : Hep2Vector(1,0);
00105 }
00106 
00107 inline Hep2Vector Hep2Vector::orthogonal() const {
00108   double x1 = std::fabs(dx), y1 = std::fabs(dy);
00109   if (x1 < y1) {
00110     return Hep2Vector(dy,-dx);
00111   }else{
00112     return Hep2Vector(-dy,dx);
00113   }
00114 }
00115 
00116 inline double Hep2Vector::phi() const {
00117   return dx == 0.0 && dy == 0.0 ? 0.0 : std::atan2(dy,dx);
00118 }
00119 
00120 inline double Hep2Vector::angle(const Hep2Vector & q) const {
00121   double ptot2 = mag2()*q.mag2();
00122   return ptot2 <= 0.0 ? 0.0 : std::acos(dot(q)/std::sqrt(ptot2));
00123 }
00124 
00125 inline void Hep2Vector::setMag(double r1){
00126   double ph = phi();
00127   setX( r1 * std::cos(ph) );
00128   setY( r1 * std::sin(ph) );
00129 }
00130 
00131 inline void Hep2Vector::setR(double r1){
00132   setMag(r1);
00133 }
00134 
00135 inline void Hep2Vector::setPhi(double phi1){
00136   double ma = mag();
00137   setX( ma * std::cos(phi1) );
00138   setY( ma * std::sin(phi1) );
00139 }
00140 
00141 inline void Hep2Vector::setPolar(double r1, double phi1){
00142   setX( r1 * std::cos(phi1) );
00143   setY( r1 * std::sin(phi1) );
00144 }
00145 
00146 inline Hep2Vector operator + (const Hep2Vector & a, const Hep2Vector & b) {
00147   return Hep2Vector(a.x() + b.x(), a.y() + b.y());
00148 }
00149 
00150 inline Hep2Vector operator - (const Hep2Vector & a, const Hep2Vector & b) {
00151   return Hep2Vector(a.x() - b.x(), a.y() - b.y());
00152 }
00153 
00154 inline Hep2Vector operator * (const Hep2Vector & p, double a) {
00155   return Hep2Vector(a*p.x(), a*p.y());
00156 }
00157 
00158 inline Hep2Vector operator * (double a, const Hep2Vector & p) {
00159   return Hep2Vector(a*p.x(), a*p.y());
00160 }
00161 
00162 inline double operator * (const Hep2Vector & a, const Hep2Vector & b) {
00163   return a.dot(b);
00164 }
00165 
00166 inline double Hep2Vector::getTolerance () {
00167   return tolerance;
00168 }
00169 
00170 }  // namespace CLHEP
00171 

Generated on Mon May 27 17:50:36 2013 for Geant4 by  doxygen 1.4.7