Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | Static Public Member Functions | Friends
CLHEP::Hep2Vector Class Reference

#include <TwoVector.h>

Public Types

enum  { X =0, Y =1, NUM_COORDINATES =2, SIZE =NUM_COORDINATES }
 
enum  { ZMpvToleranceTicks = 100 }
 

Public Member Functions

 Hep2Vector (double x=0.0, double y=0.0)
 
 Hep2Vector (const Hep2Vector &p)
 
 Hep2Vector (const Hep3Vector &)
 
 ~Hep2Vector ()
 
double x () const
 
double y () const
 
double operator() (int i) const
 
double operator[] (int i) const
 
double & operator() (int i)
 
double & operator[] (int i)
 
void setX (double x)
 
void setY (double y)
 
void set (double x, double y)
 
double phi () const
 
double mag2 () const
 
double mag () const
 
double r () const
 
void setPhi (double phi)
 
void setMag (double r)
 
void setR (double r)
 
void setPolar (double r, double phi)
 
Hep2Vectoroperator= (const Hep2Vector &p)
 
bool operator== (const Hep2Vector &v) const
 
bool operator!= (const Hep2Vector &v) const
 
int compare (const Hep2Vector &v) const
 
bool operator> (const Hep2Vector &v) const
 
bool operator< (const Hep2Vector &v) const
 
bool operator>= (const Hep2Vector &v) const
 
bool operator<= (const Hep2Vector &v) const
 
double howNear (const Hep2Vector &p) const
 
bool isNear (const Hep2Vector &p, double epsilon=tolerance) const
 
double howParallel (const Hep2Vector &p) const
 
bool isParallel (const Hep2Vector &p, double epsilon=tolerance) const
 
double howOrthogonal (const Hep2Vector &p) const
 
bool isOrthogonal (const Hep2Vector &p, double epsilon=tolerance) const
 
Hep2Vectoroperator+= (const Hep2Vector &p)
 
Hep2Vectoroperator-= (const Hep2Vector &p)
 
Hep2Vector operator- () const
 
Hep2Vectoroperator*= (double a)
 
Hep2Vector unit () const
 
Hep2Vector orthogonal () const
 
double dot (const Hep2Vector &p) const
 
double angle (const Hep2Vector &) const
 
void rotate (double)
 
 operator Hep3Vector () const
 

Static Public Member Functions

static double getTolerance ()
 
static double setTolerance (double tol)
 

Friends

std::ostream & operator<< (std::ostream &, const Hep2Vector &)
 
double operator* (const Hep2Vector &a, const Hep2Vector &b)
 
Hep2Vector operator* (const Hep2Vector &p, double a)
 
Hep2Vector operator* (double a, const Hep2Vector &p)
 
Hep2Vector operator/ (const Hep2Vector &p, double a)
 
Hep2Vector operator+ (const Hep2Vector &a, const Hep2Vector &b)
 
Hep2Vector operator- (const Hep2Vector &a, const Hep2Vector &b)
 

Detailed Description

Author

Definition at line 48 of file TwoVector.h.

Member Enumeration Documentation

anonymous enum
Enumerator
NUM_COORDINATES 
SIZE 

Definition at line 52 of file TwoVector.h.

anonymous enum
Enumerator
ZMpvToleranceTicks 

Definition at line 195 of file TwoVector.h.

Constructor & Destructor Documentation

CLHEP::Hep2Vector::Hep2Vector ( double  x = 0.0,
double  y = 0.0 
)
inline
CLHEP::Hep2Vector::Hep2Vector ( const Hep2Vector p)
inline
CLHEP::Hep2Vector::Hep2Vector ( const Hep3Vector )
explicit
CLHEP::Hep2Vector::~Hep2Vector ( )
inline

Member Function Documentation

double CLHEP::Hep2Vector::angle ( const Hep2Vector ) const
inline
int CLHEP::Hep2Vector::compare ( const Hep2Vector v) const

Definition at line 88 of file TwoVector.cc.

Referenced by operator<(), operator<=(), operator>(), and operator>=().

88  {
89  if ( dy > v.dy ) {
90  return 1;
91  } else if ( dy < v.dy ) {
92  return -1;
93  } else if ( dx > v.dx ) {
94  return 1;
95  } else if ( dx < v.dx ) {
96  return -1;
97  } else {
98  return 0;
99  }
100 } /* Compare */
double CLHEP::Hep2Vector::dot ( const Hep2Vector p) const
inline
static double CLHEP::Hep2Vector::getTolerance ( )
inlinestatic
double CLHEP::Hep2Vector::howNear ( const Hep2Vector p) const

Definition at line 121 of file TwoVector.cc.

References dot(), and mag2().

121  {
122  double d = (*this - p).mag2();
123  double pdp = dot(p);
124  if ( (pdp > 0) && (d < pdp) ) {
125  return std::sqrt (d/pdp);
126  } else if ( (pdp == 0) && (d == 0) ) {
127  return 0;
128  } else {
129  return 1;
130  }
131 } /* howNear */
const char * p
Definition: xmltok.h:285
double mag2() const
double dot(const Hep2Vector &p) const
double CLHEP::Hep2Vector::howOrthogonal ( const Hep2Vector p) const

Definition at line 162 of file TwoVector.cc.

References dot(), x(), and y().

162  {
163  // | V1 dot V2 | / | V1 x V2 |
164  // Of course, the "cross product" is fictitious but the math is valid
165  double v1v2 = std::fabs(dot(v));
166  if ( v1v2 == 0 ) {
167  return 0; // Even if one or both are 0, they are considered orthogonal
168  }
169  double abscross = std::fabs ( dx * v.y() - dy - v.x() );
170  if ( v1v2 >= abscross ) {
171  return 1;
172  } else {
173  return v1v2/abscross;
174  }
175 } /* howOrthogonal() */
double dot(const Hep2Vector &p) const
double CLHEP::Hep2Vector::howParallel ( const Hep2Vector p) const

Definition at line 133 of file TwoVector.cc.

References dot(), mag2(), x(), and y().

133  {
134  // | V1 x V2 | / | V1 dot V2 |
135  // Of course, the "cross product" is fictitious but the math is valid
136  double v1v2 = std::fabs(dot(v));
137  if ( v1v2 == 0 ) {
138  // Zero is parallel to no other vector except for zero.
139  return ( (mag2() == 0) && (v.mag2() == 0) ) ? 0 : 1;
140  }
141  double abscross = std::fabs ( dx * v.y() - dy - v.x() );
142  if ( abscross >= v1v2 ) {
143  return 1;
144  } else {
145  return abscross/v1v2;
146  }
147 } /* howParallel() */
double mag2() const
double dot(const Hep2Vector &p) const
bool CLHEP::Hep2Vector::isNear ( const Hep2Vector p,
double  epsilon = tolerance 
) const

Definition at line 116 of file TwoVector.cc.

References dot(), and mag2().

116  {
117  double limit = dot(p)*epsilon*epsilon;
118  return ( (*this - p).mag2() <= limit );
119 } /* isNear() */
const char * p
Definition: xmltok.h:285
double mag2() const
double dot(const Hep2Vector &p) const
bool CLHEP::Hep2Vector::isOrthogonal ( const Hep2Vector p,
double  epsilon = tolerance 
) const

Definition at line 177 of file TwoVector.cc.

References dot(), x(), and y().

178  {
179  // | V1 dot V2 | <= epsilon * | V1 x V2 |
180  // Of course, the "cross product" is fictitious but the math is valid
181  double v1v2 = std::fabs(dot(v));
182  double abscross = std::fabs ( dx * v.y() - dy - v.x() );
183  return ( v1v2 <= epsilon * abscross );
184 } /* isOrthogonal() */
double dot(const Hep2Vector &p) const
bool CLHEP::Hep2Vector::isParallel ( const Hep2Vector p,
double  epsilon = tolerance 
) const

Definition at line 149 of file TwoVector.cc.

References dot(), mag2(), x(), and y().

150  {
151  // | V1 x V2 | <= epsilon * | V1 dot V2 |
152  // Of course, the "cross product" is fictitious but the math is valid
153  double v1v2 = std::fabs(dot(v));
154  if ( v1v2 == 0 ) {
155  // Zero is parallel to no other vector except for zero.
156  return ( (mag2() == 0) && (v.mag2() == 0) );
157  }
158  double abscross = std::fabs ( dx * v.y() - dy - v.x() );
159  return ( abscross <= epsilon * v1v2 );
160 } /* isParallel() */
double mag2() const
double dot(const Hep2Vector &p) const
double CLHEP::Hep2Vector::mag ( ) const
inline
double CLHEP::Hep2Vector::mag2 ( ) const
inline
CLHEP::Hep2Vector::operator Hep3Vector ( ) const

Definition at line 84 of file TwoVector.cc.

84  {
85  return Hep3Vector ( dx, dy, 0.0 );
86 }
bool CLHEP::Hep2Vector::operator!= ( const Hep2Vector v) const
inline
double CLHEP::Hep2Vector::operator() ( int  i) const

Definition at line 27 of file TwoVector.cc.

References x(), and y().

27  {
28  if (i == 0) {
29  return x();
30  }else if (i == 1) {
31  return y();
32  }else{
33 // std::cerr << "Hep2Vector::operator () - "
34 // << "Hep2Vector::operator(): bad index" << std::endl;
35  return 0.0;
36  }
37 }
double y() const
double x() const
double & CLHEP::Hep2Vector::operator() ( int  i)

Definition at line 39 of file TwoVector.cc.

References X, and Y.

39  {
40  static double dummy;
41  switch(i) {
42  case X:
43  return dx;
44  case Y:
45  return dy;
46  default:
47 // std::cerr << "Hep2Vector::operator () - "
48 // << "Hep2Vector::operator() : bad index" << std::endl;
49  return dummy;
50  }
51 }
Hep2Vector& CLHEP::Hep2Vector::operator*= ( double  a)
inline
Hep2Vector& CLHEP::Hep2Vector::operator+= ( const Hep2Vector p)
inline
Hep2Vector CLHEP::Hep2Vector::operator- ( ) const
inline
Hep2Vector& CLHEP::Hep2Vector::operator-= ( const Hep2Vector p)
inline
bool CLHEP::Hep2Vector::operator< ( const Hep2Vector v) const

Definition at line 106 of file TwoVector.cc.

References compare().

106  {
107  return (compare(v) < 0);
108 }
int compare(const Hep2Vector &v) const
Definition: TwoVector.cc:88
bool CLHEP::Hep2Vector::operator<= ( const Hep2Vector v) const

Definition at line 112 of file TwoVector.cc.

References compare().

112  {
113  return (compare(v) <= 0);
114 }
int compare(const Hep2Vector &v) const
Definition: TwoVector.cc:88
Hep2Vector& CLHEP::Hep2Vector::operator= ( const Hep2Vector p)
inline
bool CLHEP::Hep2Vector::operator== ( const Hep2Vector v) const
inline
bool CLHEP::Hep2Vector::operator> ( const Hep2Vector v) const

Definition at line 103 of file TwoVector.cc.

References compare().

103  {
104  return (compare(v) > 0);
105 }
int compare(const Hep2Vector &v) const
Definition: TwoVector.cc:88
bool CLHEP::Hep2Vector::operator>= ( const Hep2Vector v) const

Definition at line 109 of file TwoVector.cc.

References compare().

109  {
110  return (compare(v) >= 0);
111 }
int compare(const Hep2Vector &v) const
Definition: TwoVector.cc:88
double CLHEP::Hep2Vector::operator[] ( int  i) const
inline
double& CLHEP::Hep2Vector::operator[] ( int  i)
inline
Hep2Vector CLHEP::Hep2Vector::orthogonal ( ) const
inline
double CLHEP::Hep2Vector::phi ( ) const
inline
double CLHEP::Hep2Vector::r ( ) const
inline
void CLHEP::Hep2Vector::rotate ( double  aangle)

Definition at line 53 of file TwoVector.cc.

53  {
54  double ss = std::sin(aangle);
55  double cc = std::cos(aangle);
56  double xx = dx;
57  dx = cc*xx - ss*dy;
58  dy = ss*xx + cc*dy;
59 }
void CLHEP::Hep2Vector::set ( double  x,
double  y 
)
inline

Referenced by CLHEP::operator>>().

void CLHEP::Hep2Vector::setMag ( double  r)
inline
void CLHEP::Hep2Vector::setPhi ( double  phi)
inline
void CLHEP::Hep2Vector::setPolar ( double  r,
double  phi 
)
inline
void CLHEP::Hep2Vector::setR ( double  r)
inline
double CLHEP::Hep2Vector::setTolerance ( double  tol)
static

Definition at line 20 of file TwoVector.cc.

20  {
21 // Set the tolerance for Hep2Vectors to be considered near one another
22  double oldTolerance (tolerance);
23  tolerance = tol;
24  return oldTolerance;
25 }
void CLHEP::Hep2Vector::setX ( double  x)
inline
void CLHEP::Hep2Vector::setY ( double  y)
inline
Hep2Vector CLHEP::Hep2Vector::unit ( ) const
inline
double CLHEP::Hep2Vector::x ( ) const
inline
double CLHEP::Hep2Vector::y ( ) const
inline

Friends And Related Function Documentation

double operator* ( const Hep2Vector a,
const Hep2Vector b 
)
friend
Hep2Vector operator* ( const Hep2Vector p,
double  a 
)
friend
Hep2Vector operator* ( double  a,
const Hep2Vector p 
)
friend
Hep2Vector operator+ ( const Hep2Vector a,
const Hep2Vector b 
)
friend
Hep2Vector operator- ( const Hep2Vector a,
const Hep2Vector b 
)
friend
Hep2Vector operator/ ( const Hep2Vector p,
double  a 
)
friend

Definition at line 61 of file TwoVector.cc.

61  {
62 // if (a==0) {
63 // std::cerr << "Hep2Vector operator/ () - "
64 // << "Division of Hep2Vector by zero" << std::endl;
65 // }
66  return Hep2Vector(p.x()/a, p.y()/a);
67 }
const char * p
Definition: xmltok.h:285
Hep2Vector(double x=0.0, double y=0.0)
std::ostream& operator<< ( std::ostream &  os,
const Hep2Vector q 
)
friend

Definition at line 69 of file TwoVector.cc.

69  {
70  os << "(" << q.x() << ", " << q.y() << ")";
71  return os;
72 }

The documentation for this class was generated from the following files: